# Quaternion.Lerp problem - CompareApproximately (aScalar, 0.0F)

Hey!

I’m having a problem with Quaternion.Lerp, which causes two errors.

Here’s the code, it’s supposed to rotate my enemy.

``````// Set rotation target
rotationTarget = Quaternion.Lerp(rotationTarget, Quaternion.LookRotation(attackTarget.position - myTransform.position), rotationSpeed * speedFactor * Time.deltaTime);

// Rotate
myTransform.rotation = Quaternion.Lerp(myTransform.rotation, rotationTarget, rotationSpeed * speedFactor * Time.deltaTime);
``````

It gives me the following errors

At line 2 in above:
CompareApproximately (aScalar, 0.0F)
UnityEngine.Quaternion:Lerp(Quaternion, Quaternion, Single)

At line 5 in above
transform.rotation assign attempt for ‘Fangtooth(Clone)’ is not valid. Input rotation is { NaN, NaN, NaN, NaN }.
UnityEngine.Transform:set_rotation(Quaternion)

Any help is much appreciated, I am pulling my hair out… There’s literally nothing on this problem (Searched Google)

1 Like

Okay I found the problem…

Multiplying with speedFactor made it pop up with the error… So I removed speedFactor
I think it was because speedFactor was 0, making the whole expression 0.

1 Like

In fact, that probably wasn’t the problem. Here: Can someone explain how using Time.deltaTime as 't' in a lerp actually works? - Questions & Answers - Unity Discussions

I’ll sum it up: you probably just had a (0, 0, 0, 0) quaternion in either end.

9 Likes

Its April 2018 and you saved my day, Thank you good sir.

1 Like

Hello from the future! We’re in 2019 now and this was still helpful

4 Likes

2020 and still is.

Later in 2020, and still is.

Please stop necroposting this. Just click like on the post and move on.

1 Like

I’m having this same issue when I have high time scale values, but I’m not passing 0s as parameters.

1 Like

``````if (rotation.x + rotation.y + rotation.z + rotation.w == 0)