Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
macattack
Topic Author
Posts: 5
Joined: Wed Aug 05, 2009 3:57 pm

oscillation by frame

Wed Aug 12, 2009 2:40 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?

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: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Re: oscillation by frame

Wed Aug 12, 2009 8:01 pm

Try this:

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



Dan

Who is online

Users browsing this forum: No registered users and 1 guest