Page 1 of 1

oscillation by frame

Posted: August 12th, 2009, 2:40 pm
by macattack
I'm trying to write a script that causes a solid to oscillate between two positions with each frame.

What I've come up with works most frames, but skips beats. Entering the script below in a 30 fps comp, the object is static from 0:00:04:02 - 0:00:04:04. What's wrong with my math?

Code: Select all

var xDisp = 0
var yDisp = 20
var fps = 30
var x = Math.floor(fps*time)	 
if(x%2==1) transform.position+[xDisp, yDisp] else transform.position-[xDisp, yDisp ]  

Re: oscillation by frame

Posted: August 12th, 2009, 8:01 pm
by Dan Ebberts
Try this:

Code: Select all

var xDisp = 0
var yDisp = 20
var x = timeToFrames();
if(x%2==1) transform.position+[xDisp, yDisp] else transform.position-[xDisp, yDisp ]

Dan