# Comparing two rotations

Wondering if there is a simple way to solve this issue I have with out a lot of logic.
I have a transform change while inside Update() and im wanting to make it not run after it has hit its default location.

This won’t work cause it won’t end exactly at the DefaultLocation with lerp
currentRotation != DefaultLocation

``````Quaternion currentRotation = this.transform.rotation;

if(!target && currentRotation != DefaultLocation){

this.transform.rotation = Quaternion.Lerp(currentRotation,DefaultLocation,Time.deltaTime * 1);
}
``````

It would but you’re not using lerp correctly.

1 Like

thanks for the response GroZZleR

idk that idea doesn’t seem to work or there is something im missing

This statement stays true.

``````this.transform.rotation != DefaultLocation
``````
``````if(!target && this.transform.rotation != DefaultLocation){

currentLerpTime += Time.deltaTime;

if (currentLerpTime > lerpTime) {
currentLerpTime = lerpTime;
}

float perc = currentLerpTime / lerpTime;

this.transform.rotation = Quaternion.Lerp(this.transform.rotation,DefaultLocation, perc);

}
``````

guess I could just check for the x axis find the difference and tell it to stop running it when the difference is small enough.

Comparing floats for equality is going to nearly always end in failure especially when you have a frame dependent calculation (Time.deltaTime) and floating point error to deal with.

Compare something like 1.00000001 and 1.00000002. Clearly they are not equal but the difference is too small for it to matter. Testing for the difference between the two to see if they’re ‘close enough’ like you’ve suggested is a better way to go.

You’re still not lerping correctly – your first parameter is constantly changing as you rotate. You need to store an additional “StartingRotation” which you set before you begin lerping and use that rather than this.transform.rotation. Alternatively, and perhaps much easier in this case, use Quaternion.RotateTowards instead of Quaterion.Lerp.

BPPHarv’s advice is correct but misguided in this situation - a lerp will always hit the end point exactly, so your comparison is valid.

1 Like