# Unity - Mathf.Lerp() didn't work as expected?

I want to rotate an object 360 degrees so this is what I did: xRotation = Mathf.Lerp(0, 360, Time.fixedDeltaTime * lerpTime)

and then I used Quaternion.Lerp() to rotate the Object so:

targetRotation = Quaternion.Euler(initialRotation.x + xRotation, initialRotation.y, initialRotation.z);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.fixedDeltaTime * lerpTime);


But it didn't work as expected, the xRotation didn't go from 0 to 360, it just changed from 0 to 9 (instantly), and that's it, it never changed.

This is my full code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class QuaternionExpirement : MonoBehaviour
{

[SerializeField] [Range(5, 10)] float lerpTime;
Vector3 initialRotation;
float xRotation;

private void Awake()
{
initialRotation = Vector3.zero;
mousePress = false;
xRotation = 0;
}

private void Update()
{
mousePress = Input.GetMouseButtonDown(0);
}

private void FixedUpdate()
{
if (mousePress)
{
initialRotation = transform.eulerAngles;
}

{
xRotation = Mathf.Lerp(0, 360, Time.fixedDeltaTime * lerpTime);
Quaternion targetRotation = Quaternion.Euler(initialRotation.x + xRotation, initialRotation.y, initialRotation.z);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.fixedDeltaTime * lerpTime);

if (xRotation >= 360)
{
}
}
}

}


It seems you have not really understood what the functions you use actually do. The Time.fixedDeltaTime, as per the documentation, returns the time between each physics update in seconds. This is a fixed value (e.g. for 50 physics updates per second this will be 0.02). Now, lerpTime is also a fixed value in your case from my understanding. This means that in every FixedUpdate() call, the Mathf.Lerp function will return the same value (360 * 0.02 * lerpTime), in your case 9, which means that Time.fixedDeltaTime * lerpTime = 0.025.
In order to fix the problem the Time.fixedDeltaTime * lerpTime must not be a constant value but must be updated each frame in order to start from 0.025 and eventually reach 1 after 40 frames.
float previousInterpolation = 0f; // member variable