- Home /
Rotate overtime to match waypoint
Using the picture below as reference. The 2 grey disks are waypoints on a path, the red disk is what will be moving. What do I need to use so that the disk will move from one disk to the other, and smoothly change its rotation over time to match where it is going to? I need it so that entire movement does not necessarily happen in one frame. The time it takes to move between waypoints can vary .
There is no picture below... But I'm thinking that you might need something like Slerp() for the rotation
Yeah that was kind of dumb, but its there now. I kind of figured I would have to use slerp but how do I make it work over a number of frames?
Answer by robertbu · Feb 02, 2014 at 07:47 PM
First, let me answer the specific question you ask. In the absence of the your code all I can do is outline some pseudo-code.
transform.rotation = Quaternion.Slerp(disk1.rotation, disk2.rotation, precentageBetweenWaypoints);
That is the third parameter is the fraction of the way the disk is between the two waypoints.
Note depending on your goals here, there may be a better solution. You could use your waypoints to generate a spline. Then you can align the disk by using a point a bit forward on the spline from the current position of the object. iTween is a free way to generate the spline. You can use iTween.PointOnPath() or iTween.PutOnPath(). There has also been some spline code posted to UA.