How to slowly reach a certain number

first of all, i have to say that i know for/while loops are used to achieve this kind of things and it’s quite a very basic thing in programming. but it didn’t work in update method and i still haven’t figured how to use loops in update methods

anyway, i want to rotate something in my game when the character is moving, and slowly put it back to 0f, 0f, 0f when player stops moving.
i wrote a code which i can’t copy paste it here since it’s a bit long to be in a question body, that rotates my object perfectly but, the problem is when the character stops moving, the rotation jumps back to 0 and it looks bad.
i used Mathf.sin for rotating the object it’s quite perfect.

any suggestion/idea is welcomed.


Hey there,

i think there are 2 options to solve your problems:
Either use Quaternion.RotateTowards(yourcurrentRotation, destinationRotation, maxAnglePerUpdate) for a steady movement of a given maximum degree per Update() call. (You do !not! need a loop for this if this is unclear)
Otherwise use Quaternion.Slerp(yourcurrentRotation, destinationRotation, interpolationSpeedBetweenZeroAndOne) for an interpolation like movement (so getting slower towards the end). Here you also need just one call per Update().

Hope this helps. If not let me know what points are not clear. (Best provide a small code snippet of wat you are doing right now to turn your car back)