View Full Version : creating jerky movement in expressions

Darren Garrison
04 April 2009, 11:15 PM
This is probably something simple to do with expressions, but I'm not very proficient with it. I want an object to move across an axis over time, but, every x number of frames, reverse direction for y number of frames before going in the original direction again. I know the easy part-- moving forward-- this is the expression: pSphere1.translateY=frame/10;

but how do I add the periodic backwards jerk?

05 May 2009, 06:59 PM
you simply need to put a condition into your expression that checks how many frames have passed since your last "jerk". if not enough time has passed, continue moving forward, else move backwards.

here is some psuedo code, its not perfect but you should be able to get the idea of a conditional statement from it. since this is an expression you may need to store the lastFrame variable in a node or global var, not too sure.

$curFrame = `currentTime -q`;
if ( ($curFrame - $lastFrame) < 10 ) {

//jerk animation
$lastFrame = $curFrame;

} else {
//forward animation


Darren Garrison
05 May 2009, 05:24 AM
Thanks for the reply you gave on this. I did a little more reading, and found that I was overthinking my problem in thinking I'd need code. All I had to do was keyframe one cycle of the motion, then go in the graph editor and choose curves/post infinity/cycle with offset.

CGTalk Moderation
05 May 2009, 05:24 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.