Why isn't my object lerping ? C#

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.

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.

Try spherical interpolation perhaps?

I’ve tried your code and it sorta works. But I don’t think it’s the behaviour you want.

When you use “transform.rotation.z” in the first line, you don’t actually refer to the 3rd parameter of your rotation. To do so, you need to do: transform.rotation.eulerAngles.z

If you don’t insert that .eulerAngles, you’ll be refering the quaterion parameters.