How to find out when I have reached the end of a rotation
Okay so I have multiple game objects that I rotate toward. I am trying to see if playerAgentBase.transform.rotation == lookRotation The problem I am having is that sometimes the playerAgentBase rotation has negative values while lookRotation has positive values. So the if statement never returns as true. I am not sure why this is happening. Sometimes this works and other times it don't. When it don't work it rotates toward the wrong object. Is there a better way to check when my rotation has reached its destination? Any help would be appreciated. Thanks.
private void Start()
{
rotate = true;
}
public void RotateTowards()
{
float strength = 1.5f;
float str = 0f;
if (playerAgentBase != null)
{
Vector3 direction = (transform.position - playerAgentBase.transform.position);
direction.y = 0;
str = Mathf.Min(strength * Time.deltaTime, 1);
Quaternion lookRotation = Quaternion.LookRotation(direction);
playerAgentBase.transform.rotation = Quaternion.Slerp(playerAgentBase.transform.rotation, lookRotation, 10f);
//Here is where my problem is
if (playerAgentBase.transform.rotation == lookRotation) //<-------------------
{
rotate = false;
InteractA();
}
}
}
public void Update()
{
if (rotate)
{
RotateTowards();
}
}
Your answer
Follow this Question
Related Questions
Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers
How can I fix rotation of Z axis to 0? 0 Answers
Scaling animation that takes rotation into account 0 Answers
rotate an object with HTC Vive controller 0 Answers
How to Rotate Y axis of an Object toward virtual joystick direction 0 Answers