Problem rotating a cube with quaternions using lerp

I’m trying to rotate a cube 90 degrees. My script was working until I started to simplify it :frowning: I’ve starred myself blind as to why it’s not working anymore. The cube just rotates a tiny bit and then starts jittering in its rotating movement.

    const float ROTATION_SPEED = 4.0f;

	Quaternion _sourceRotation;
	Quaternion _targetRotation;

	void Start () {
		_sourceRotation = this.transform.rotation;
		_targetRotation = this.transform.rotation;
	void Update () {

		float angle = Quaternion.Angle(this.transform.rotation, _targetRotation);
		if (angle < 0.1f) {	
			_sourceRotation = _targetRotation;
			_targetRotation = this.transform.rotation * Quaternion.Euler(90, 0, 0); //a random rotation will be chosen here, but hardcoded right now for simplicity

		this.transform.rotation = Quaternion.Lerp(_sourceRotation, _targetRotation, Time.deltaTime * ROTATION_SPEED);

If I change _sourceRotation to a Transform instead of a Quaternion and store the cubes transform instead or its rotation in _sourceRotation, and in the Quaternion.Lerp use _source.rotation it does the rotation as it should, but I don’t understand why… feeling frustrated

That’s because Lerp doesn’t work the way you are using it. It interpolates from the first rotation to the second rotation while t == 0 is the first and t == 1 the second rotation value. Assume Time.deltaTime stays constant at 0.05 then t will always be 0.05*4 = 0.2. That’s 20% the first and 80% the second rotation, that’s where the jitter comes from, slightly different deltaTime every frame.

Create another float, use it as t, and add the Time.deltaTime * ROTATION_SPEED to it.
Whenever you reach your target, reset it to 0.