Copy link to clipboard
Copied
I've got a composition of an animated bug. I have a script that gives it random movement left and right with pauses (so it'll crawl randomly left or right, stop, then crawl again at random intervals).
I'm looking for a way to flip the composition to face the direction it is moving and STAY that way while paused.
I'm currently using this hackey way to flip the X scale depending on the direction it's moving, but it always goes back to facing one way when it stops, when it should be facing the way it was facing when it stopped.
var movement = transform.position.velocity;
if (movement[0] < 0) {
transform.scale
} else {
[transform.scale[0]*-1,transform.scale[1]]
}
I hope that makes sense?
Any help would be awesome, thanks!
Try this:
var movement = transform.position.velocity;
if (Math.abs(movement[0]) < .01){
t = time - thisComp.frameDuration;
while (t >= 0){
if (Math.abs(position.velocityAtTime(t)[0]) < .01){
t -= thisComp.frameDuration;
continue;
}
if (position.velocityAtTime(t)[0] < 0){
transform.scale;
}else{
[-scale[0],scale[1]];
}
break;
}
} else if (movement[0] < 0) {
transform.scale;
} else {
[-scale[0],scale[1]];
}
Copy link to clipboard
Copied
You need to run it in a loop and check every frame.
Mylenium
Copy link to clipboard
Copied
Try this:
var movement = transform.position.velocity;
if (Math.abs(movement[0]) < .01){
t = time - thisComp.frameDuration;
while (t >= 0){
if (Math.abs(position.velocityAtTime(t)[0]) < .01){
t -= thisComp.frameDuration;
continue;
}
if (position.velocityAtTime(t)[0] < 0){
transform.scale;
}else{
[-scale[0],scale[1]];
}
break;
}
} else if (movement[0] < 0) {
transform.scale;
} else {
[-scale[0],scale[1]];
}
Copy link to clipboard
Copied
Perfect! That works great, exactly what I needed. Thank you (again!) Dan Ebberts
Copy link to clipboard
Copied
That's great. It turns out that expression will break under certain conditions, so this one is probably better:
var movement = transform.position.velocity;
val = value;
if (Math.abs(movement[0]) < .01){
t = time - thisComp.frameDuration;
while (t >= 0){
if (Math.abs(position.velocityAtTime(t)[0]) < .01){
t -= thisComp.frameDuration;
continue;
}
if (position.velocityAtTime(t)[0] > 0){
val = [-scale[0],scale[1]];
}
break;
}
} else if (movement[0] > 0) {
val = [-scale[0],scale[1]];
}
val