# Calculating rotation on a path animation

This topic is 3721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm sure this question has been asked a million times... I have an object, lets say its a ferrari. Now, i set up a path animation for this object to go to the points: (-5000, -5000, -10000), (-5000, 5, 5) (5000, 5, 5) So the ferrari animates to each of those points, but it appears to drift rather than point in the direction of motion. What is the best place for me to get started learning about this type of problem?

##### Share on other sites
This sounds like a job for trig and linear algebra.
You can use atan2 to calculate the angle of rotation between two points.

http://en.wikipedia.org/wiki/Atan2

Also you might consider defining an interpolating spline between the points so the ferrari doesn't just drive straight to one point, turn a sharp angle and drive to the next.

http://en.wikipedia.org/wiki/Spline_(mathematics)

##### Share on other sites
I would do the spline idea but use say the middle of the car as the point that is checking to see if it's on the spline. Also I would go ahead and project the front of the car(say right in between the front wheels) onto the spline also, that way it will always follow it and not appear to drift.

Recap:

Do a spline between those 3 points (wikipedia has a great article on splines).

Have the middle of the car (or possibly the rear 2 wheels) follow the spline.

Next using the distance from the first point to the front of the car find the point on the spline that is that same distance from the middle of the car. Set the front point = to that.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634134
• Total Posts
3015751
×