Layer Random Position Every 30 frames

Scripting for After Effects

Layer Random Position Every 30 frames

Postby alarm on 04/8/2017, 9:22 pm

I am trying to have a layer change positions randomly every 30 frames or so. I am having trouble getting the layer to go to a random spot and stay there for 30 frames. My code is:

Code: Select all
if( timeToFrames()%30==0 ){
  x = random()*comp("Comp 1").width;
  y = random()*comp("Comp 1").height;
} else {
  x = transform.position[0];
  y = transform.position[1];
}
[x,y]


This code half works every 30 frames it goes to a random location for one frame and then every other frame it goes back to its original location.

My question is: How come the else statement doesn't hold the layer in its place? It's as if the position of the layer that is being set in the previous frame is ignored? Is there a way to save its location so it holds in the same spot for all 30 frames.
alarm
 
Posts: 2
Joined: 06/6/2010, 11:07 am

Re: Layer Random Position Every 30 frames

Postby hans123 on 04/22/2017, 2:20 am

hans123
 
Posts: 1077
Joined: 12/28/2012, 1:37 am
Location: Paris / France

Re: Layer Random Position Every 30 frames

Postby alarm on 04/24/2017, 12:31 pm

Thanks Hans -- I appreciate the help.
alarm
 
Posts: 2
Joined: 06/6/2010, 11:07 am


Return to After Effects Expressions