Quantcast
Channel: Answers for "How to ROTATE an object without slowing the ends (lerp)"
Viewing all articles
Browse latest Browse all 4

Answer by supernat

$
0
0
Since you are performing the lerp every frame from the current value (transform.rotation), you will be acting on a distance that is shrinking every frame, so you will indeed see the rotation slow as you get closer to the end, because the value you are passing to the sleep for the amount (the speed) will be constant for the most part (yes not really, but it is very close as long as all of your frames are about the same time apart). So let's just assume this rate * time.deltaTime is about 0.5 for simplicity. In the first frame, you slerp to 50% of the full rotation. In the second frame, you slerp 50% of What Remains in the rotation, so you can see as frames continue, you continue to slerp 50%, but the rotation amount becomes smaller and smaller. To fix this, capture the starting rotation at the beginning and use that as the first parameter every frame. Also, simply slerp from 0.0 to 1.0, which is actually the intended use of the lerp and slerp methods, though many people use them in the way you have to ease in and out, which you don't want. So, in frame 1, pass in 0.0, in frame 2, pass in 0.1, in frame 3, 0.2, etc. for the third parameter to lerp. Also, I would do this in the FixedUpdate, though not necessary, but if you do it in Update, it would require the time.deltaTime correction, so you would increase the third parameter by say rate * time.deltaTime every frame, limiting it to 1.0, where rate is around 2 if you wanted the rotation to be about 3% every frame at 60 hz.

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images