oscillation by frame

Moderators: Disciple, zlovatt

Post Reply
macattack
Posts: 5
Joined: August 5th, 2009, 3:57 pm

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 ]  
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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
Post Reply