Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Expression to rotate object along the path

Explorer ,
Jul 17, 2023 Jul 17, 2023

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

TOPICS
Expressions , How to
800
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 17, 2023 Jul 17, 2023

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
...
Translate
Community Expert ,
Jul 17, 2023 Jul 17, 2023

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 17, 2023 Jul 17, 2023

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?

Screenshot 2023-07-17 at 22.08.41.png

Screenshot 2023-07-17 at 22.08.54.png

Screenshot 2023-07-17 at 22.09.01.png

   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2023 Jul 17, 2023

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;
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 17, 2023 Jul 17, 2023

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. 

RickGerard_0-1689639974652.gif

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 25, 2023 Jul 25, 2023
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines