Reputation: 11
I want to convert a normal moving camera to a camera and aim
group.
How can I do it? Using API, matrix, etc? Is there a formula?
Thank you very much!
Upvotes: 1
Views: 580
Reputation: 2029
The Maya camera and aim
option on the Create
menu runs a Mel script that has a few of operations in it. As a simplified version of that, you can use the Python Maya command cmds.aimConstraint
to constraint the z
vector to a locator to get a similar result.
Below is a Python script that does something similar to that Mel script. I'm creating a new camera here, but you can constraint your existing camera to a new locator.
import maya.cmds as cmds
# Create a locator at the center of the world
locator = cmds.spaceLocator()
# Create a camera
cam_shape, camera = cmds.camera()
# Point the camera at the locator
cmds.aimConstraint(locator, cam_shape, aimVector=[0, 0, -1])
# move the camera back 3 units
cmds.move(0, 0, 3, camera)
With that, the camera will always point to the locator in a similar fashion that the Camera and Aim
menu option does.
You can now animate (or move) that camera and it will always point to the locator.
Upvotes: 0