Copy link to clipboard
Copied
So basically what I want to make is expression that rotates object along the path. But instead of directly turning to path, it should round up to closest right angle. For example, I want to move object from the center to top right corner. If horizontal velocity is higher than vertical - object should face to the right. And if vertical velocity is higher - object should turn face up.
Can't figure out myself, would appreciate the help
That's pretty strange. I wouldn't expect velocity to be zero at the keyframes, but apparently it can be. I'm not sure what a general solution would be, but you could try this to fix your particular example:
t = Math.max(time,position.key(1).time + .001);
t = Math.min(t,position.key(position.numKeys).time - .001);
v = position.velocityAtTime(t);
if (length(v) < .001){
v = position.velocityAtTime(t - .001);
}
if (Math.abs(v[0]) > Math.abs(v[1])){
v[0] < 0 ? 180 : 0;
}else{
v[1] < 0 ? -90 : 9
...
Copy link to clipboard
Copied
Assuming the position is keyframed, something like this might work:
t = Math.max(time,position.key(1).time + .001);
t = Math.min(t,position.key(position.numKeys).time - .001);
v = position.velocityAtTime(t);
if (Math.abs(v[0]) > Math.abs(v[1])){
v[0] < 0 ? 180 : 0;
}else{
v[1] < 0 ? -90 : 90;
}
Copy link to clipboard
Copied
Hey Dan! Thanks. I encountered a problem where on time where keyframe is located objects' rotation suddenly returning to the original rotation. I was trying to figure it out myself, but still no progress. Do you know what might be a solution for this?
Copy link to clipboard
Copied
That's pretty strange. I wouldn't expect velocity to be zero at the keyframes, but apparently it can be. I'm not sure what a general solution would be, but you could try this to fix your particular example:
t = Math.max(time,position.key(1).time + .001);
t = Math.min(t,position.key(position.numKeys).time - .001);
v = position.velocityAtTime(t);
if (length(v) < .001){
v = position.velocityAtTime(t - .001);
}
if (Math.abs(v[0]) > Math.abs(v[1])){
v[0] < 0 ? 180 : 0;
}else{
v[1] < 0 ? -90 : 90;
}
Copy link to clipboard
Copied
I like this expression a lot. The arrow points to the direction of motion on the steepest angle and changes after the angle passes 45º. I'm going to take some time this evening to see if I can add a 20-frame rotation animation when the angles change from horizontal or vertical faster using an ease interpolation method. That ought to keep me busy for a couple of hours...
Very cool, Dan the Man Ebberts, I have a lot of ideas on how to use this to improve other animation presets I have created.
Copy link to clipboard
Copied
Hey Dan. This is really amazing expression. Im a bit late with my gratitude, but its better late than nothing at all. Thanks, it works perfectly!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now