Copy link to clipboard
Copied
Hey guys. I'm trying to make an object that is gonna horizontally flip itself when it changes his x axis vector.
It basically works, but the problem here that when object isn't moving anywhere or hit keyframe, velocity goes to 0 and because there is no statements that are going to flip object scale, so it goes to the start scale of [100, 100]. Numbers on screenshot is velocity - when it's negative - scale flips from [100, 100] to [-100, 100]
There is expression that I've been using;
if(transform.position.velocity[0]>0){ [-100, 100] }else{ [100,100] }
What I want to do is the object will remember his last scale number. So if we go from left to right, animation ends - object gonna safe his last scale. What do you think?
Something like this, probably:
if(transform.position.velocity[0]>0){
[-100, 100]
}else if (transform.position.velocity[0]<0){
[100,100]
}else{
t = time - thisComp.frameDuration;
gt = true;
while(t >= inPoint){
if (transform.position.velocityAtTime(t)[0] > 0){
break;
}else if (transform.position.velocityAtTime(t)[0] < 0){
gt = false;
break;
}
t -= thisComp.frameDuration
}
gt ? [-100,100] : [100,100]
}
Copy link to clipboard
Copied
It's all explained here:
http://www.motionscript.com/articles/speed-control.html
You need to integrate the values in a loop and then make determinations about the values based on some threshold.
Mylenium
Copy link to clipboard
Copied
Thank you for you reply, Mylenium! That's a beatiful article, I'll be glad to read it later. But I didn't quite understand how I can use this for my purpose? There is too many for me to understand what and where I can use it right now
Copy link to clipboard
Copied
Something like this, probably:
if(transform.position.velocity[0]>0){
[-100, 100]
}else if (transform.position.velocity[0]<0){
[100,100]
}else{
t = time - thisComp.frameDuration;
gt = true;
while(t >= inPoint){
if (transform.position.velocityAtTime(t)[0] > 0){
break;
}else if (transform.position.velocityAtTime(t)[0] < 0){
gt = false;
break;
}
t -= thisComp.frameDuration
}
gt ? [-100,100] : [100,100]
}
Copy link to clipboard
Copied
It's beautiful!! It works exactly how I wanted! Thank you, Dan.
I don't quite understand what is going on here, but I'll take a closer look 🙂
Copy link to clipboard
Copied
If the horizontal velocity is zero at the current frame, it backs up, frame-by-frame, until it finds the most recent frame where the horizontal velocity was non-zero and uses that value.
Copy link to clipboard
Copied
Thanks a lot for your time Dan! I figured out how it works 🙂
It's actually pretty simple and clever when I started to realise how the whole script works