- Home /
Having an action that occurs after a Quaternion slerp reaches goal
How do you have an action or trigger that occurs after a Quaternion slerp reaches its target?
Due to rounding errors, would a check like if(itemAngle == targetAngle)
be too strong? What sort of rounding interval should be accounted for?
Is there another way to check when target has been reached?
Answer by aldonaletto · Jan 02, 2012 at 01:22 PM
The equality operator for quaternions accepts nearly equal rotations: Unity verifies if the dot product of the two quaternions is close enough to 1, what should mean they are almost the same. But this "close enough to 1" is fixed by Unity; if you want to control the error margin, do the dot product yourself:
if (Quaternion.Dot(targetRot, transform.rotation) > 0.99){
// rotation is very close to targetRot
}
But you can be more specific yet: use Quaternion.Angle, thus you can specify an error margin in degrees, which's way more intuitive:
if (Quaternion.Angle(targetRot, transform.rotation) <= 2){
// rotation is at 2 degrees or less from targetRot
}
Finally found a solution after two weeks! THAN$$anonymous$$ YOU!
Answer by Kailas · Dec 31, 2011 at 09:09 AM
How are you performing the slerp?
Aren't you supplying the t value (the percentage to slerp between the specified values)?
If so, you could just have a check next to the slerp code:
if(t < 1) { //perform slerp }
else { itemAngle = targetAngle; //call function that does the action you want triggered }
Your answer
Follow this Question
Related Questions
Extrapolating a new rotation from two existing rotations. 2 Answers
Quaternion Rotation Smooth 1 Answer
Quaternion LookRotation/Slerp Axis Lock 3 Answers
Rotating Rigidbodies 2 Answers
Rotate Turret back to match base 1 Answer