Hello. I am trying to rotate my object smoothly using Quaternion.Lerp(). But for some reason it’s not rotating smoothly. Instead, it is just snapping to that position. How can i fix this?
This is the code:
float rotateFloat = (((randomReward + 1) * 60) - 30) - transform.rotation.z;
Quaternion targetRotation = Quaternion.Euler(new Vector3(0, 0, rotateFloat));
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, f_difX * Time.deltaTime);
Any kind of help is very much appreciated.
EDIT:
I tried to use Quaternion.RotateTowards() instead, it did rotate smoothly. But i faced another problem which is the direction of the rotation. I did some research and found that Quaternion.RotateTowards() Finds the shortest way to rotate to the targetRotation point, which defies the whole point of spinning the object in a both directions.
If your problem is that the rotation gets performed in an instant (and not smoothly). It's probably because f_difX * Time.deltaTime > 1. So f_difX is probably too big. If you already checked that, then I'm afraid I can't help you.
– msfredb7