Hi, in the following code I want to roate an object with Quaternion.RotateTowards() inside the Update-Function. Unfortunately the Rotation doesn’t take place over a period of time but immediately snaps to the target position(goalRot). the target position is a public Quaternion Variable I set in the Inspector. For the movementSpeed I allready applied values between 0.1f and 10f, makes no different.
if (rotateToWeight)
{
Debug.Log("rotation before: " + transform.rotation);
// The step size is equal to speed times frame time.
float step2 = movementSpeed * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, goalRot, step2 );
Debug.Log("rotation: " + transform.rotation);
Debug.Log("goalRot: " + transform.rotation);
Debug.Log("Step: " + step2);
// Check if Rotation finished
if (gameObject.transform.rotation == goalRot)
{
// Stop Rotating
rotateToWeight = false;
Debug.Log("Finished ");
}
}
The console prints the following:
rotation before: (-0.5, -0.5, -0.4, 0.6)
rotation: (-1.0, 0.0, 0.0, 0.0)
goalRot: (-1.0, 0.0, 0.0, 0.0)
Step: 0,09783585
Finished
So, obviousliy the target rotation is allready reached after the first call of the function. No idea why. I would be glad if someone could help