Dot Product not equals 1
I rotate my character to face at my target using this script:
public class Rotate : MonoBehaviour
{
public Transform target;
public Vector3 distance;
private Quaternion rotateQuaternion;
public float dotRotate;
// Update is called once per frame
void Update()
{
RotateToTarget();
}
private void RotateToTarget()
{
distance = target.position - transform.position;
distance.y = 0;
rotateQuaternion = Quaternion.LookRotation(distance, Vector3.up);
dotRotate = Vector3.Dot(distance.normalized, transform.forward);
Debug.Log(dotRotate);
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotateQuaternion, 120f * Time.deltaTime);
if (dotRotate >= 1f)// Sometime dot's value cannot equal 1
{
Debug.Log("Done Rotating");
}
}
}
this is the final result:
as you can see Dot Product not returning 1, so what's the problem here? please help me, thank you.
capture.png
(221.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Get vector3 from cursor position relative to object in 3D plane 1 Answer
Don't trust "Vector3.Distance"? 1 Answer
prob to define a condition to get out of a search position loop for obstacle avoidance 0 Answers
Bug? Wrong changing position of gameobject 1 Answer
How I can make my camera keep a distance between two objects? 0 Answers