Posted by Duncan Brinsmead, 3 May 2007 5:27 am
Here is a script that allows you to easily have one object follow the position of another, but with damping and a lag. I find it is very useful when you wish to have a camera follow an object automatically without following too closely or in too jerky a fashion. Note how in the example avi the camera follows the general motion of the sphere but not so closely as to bounce up and down with the sphere.
To use, first save the following MEL file in your maya scripts folder then run Maya.
dynamicFollow.mel (scroll to the bottom to download related materials)
You can now select first a leader and then a follower object( the order of selection matters ). The lead object may be a single vertex selection if desired. Make the second object your camera if you wish to have it follow the lead object. Type "dynamicFollow" into the command line and it will set up an expression and create a parent for the follower object. When you playback it will animate the position of this parent node but still allow you to edit the relative position of the follower object. With a camera one can still track and tumble the view even while it is following the object position. There is usage info in the attribute editor notes for the generated "follower" node, as well as the extra attributes "damp" and "drag". The expression creates a simple dynamic spring that pulls the follower towards the leader. Note that you must bake out the translation on the follower to keyframes if you wish to render out of sequence. The expression treats frame 1 as a start frame by default (resetting the position on rewind), but you can edit the expression if you want it start at a different frame.
If you typically wish to use this for cameras and would rather it just used the current camera you can also add the following to your scripts folder.
cameraFollow.mel (scroll to the bottom to download related materials)
Then you simply need to select the object or vertex and type: "cameraFollow".
If you don't like typing, then simply select the text "dynamicFollow" or "cameraFollow" and leftmouse drag onto the shelf to create a button.
I find this script is particularily useful when iterating over dynamic simulations. For example in a dynamic parachute animation the speed at which the character falls is dependant on when the parachute opens, which changes when I adjust the simulation. This script lets me simply have the camera follow the parachute smoothly with a little lag so that I can best see what is happening. Otherwise the camera would need to be too far away to capture the entire fall.
Note that if you group the lead object and rotate at the parent level then follower will only work correctly when the lead is a vertex. In this case it is better to make the parent or group tranform the lead object if possible.
Feel free to modify and share these scripts as desired.
Please only report comments that are spam or abusive.