This expression will take the attribute of an object at a certain “offset” time, and apply it to another objects attribute. For instance it will take it off a cubes translateZ attribute, and assign it to a spheres translateZ attribute.
-Create a new scene.
-Create a polyCube.
-Create a polySphere.
-Translate the sphere about 10 units in Y.
-Open the Expressions editor, then Select Filter/By Expression Name.
-Type in the following:
int $offset = 10;
int $currentTime = `currentTime -q`;
$offsetTime = $currentTime - $offset;
$cube1Zpos = `getAttr -t $offsetTime pCube1.tz`;
pSphere1.translateZ = $cube1Zpos;
-Hit Create.
and here is the explaination !
//Time offset expression
//offset length (in frames)
int $offset = 10;
//Get current time
int $currentTime = `currentTime -q`;
//Substract the offset to the current time
//so if current time is 10,
//and offset is 2, offsetTime will be 8
$offsetTime = $currentTime - $offset;
//Get the value of pCube1.translateZ
//at frame $offsetTime (8 in our example)
$cube1Zpos = `getAttr -t $offsetTime pCube1.tz`;
//Assign it to pSphere1.translateZ
pSphere1.translateZ = $cube1Zpos;
This could be taken much further, you could for example setup joints and IK so it looks like power tubes are going from the mothership to the children, you could also add a custom attribute called “motion” and multiply the “noise” section of the expression by it, so that if you decide to turn you noisy motion off you would just have to set the custom attribute to 0. You could keyframe that attribute so you could control the random “floating” motion of the ship throughout the scene so it stops looking as if it were floating if it lands for example.
This type of setup could also be applied to a cranefly, or any other type of futuristic flying object etc. Experiment with setting all sorts of different relationships etc until you are comfortable with this expression.
this is very handy little snippet from
Oliver Shyal Beardsley
thanks alot for .......it
hope you enjoy it...........
nParticleShape1.position = MASH.positions
cmds.connectAttr( 'MASH.positions', 'nParticleMashShape.position')