I am using some altered rotation code I’ve found on the forums, but am having some issues registering that the slerping has been completed.
Sometimes the conditional statement at the end will run and turn off the function from running, but most times, it will never execute the conditional statement as true, and the function will run indefinitely, but the gameobject stops rotating as if it has finished (and it seems like it has).
What is wrong with my logic behind knowing when the slerp is complete?
if (IsRotating == true)
{
// Find the vector pointing from our position to the target
_lookDirection = (_destinationPosition - _transform.position).normalized;
// Create the rotation we need to be in to look at the target
_lookRotation = Quaternion.LookRotation(_lookDirection);
// Rotate us over time according to speed until we are in the required rotation
_transform.rotation = Quaternion.Slerp(_transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);
Debug.Log("_lookRotation is " + _lookRotation);
if (_transform.rotation == _lookRotation)
IsRotating = false;
}
thats because it will never complete.
i’m sure you heard a varation on this joke. sexist (maybe) but explains the point
2 guys walk into a bar see a beautiful woman sitting down and a sign at the entrance saying
“that is my daughter. if you can get to her you can date her. the only rule is you can only travel half the distance to her at any one time”
first man turns around and starts to walk out.
2nd man walks toward the girl
first guy says “dude its impossible, you’ll never get to her”
2nd guys says “yeah but i can get close enough to touch her”
CS 101 never check for absolute values with floats. always check epsilons.
I think I see what your point is, and I was thinking it might be the case, however I’ve not worked with epsilons. Can you give some example code of how you would convert the floats to epsilons so they can be compared?
Does this have a lot of overhead processing cost?
After reading into it , I see that people are saying you do something like:
if ((Math.Abs(_transform.rotation.y - _lookRotation.y) < 0.001))
IsRotating = false;
This seems to give me better results, but it still has a couple areas that never register as true.
Can someone please supply supply with a code sample a reliable and efficient way to check if a Slerp is complete? Even unity stops actually slerping at a certain point, so there must be a way to tell.