How this script calculate approach angle?

I’m analyzing a script for improve my skill, but i can’t know what does following line do?

float approachAngle = Vector3.Dot(Vector3.Cross(up, forward), targetDirection);


  • up param => Vector3.up

  • forward param => transform.forward

  • targetDirection param => targetPosition - transform.position

I’m so confused!!

Lets break this code down:

Vector3.Cross (up, forward);

This will give us some vector perpendicular to both the up and forward vectors (so either left or right) with a magnitude proportional to how orthogonal (close to a right angle) the two vectors are.

Vector3.Dot (someLeftRightVector, targetDirection);

This will give us a number between -1 and 1 (assuming the two vectors are normalized, or have a magnitude of at most 1) representing how similar the two directions are with 1 meaning the two vectors are identical, a -1 meaning the two vectors point in opposite directions, and a 0 meaning the two are perpendicular to one another.

So, this code won’t give you an approach angle per se, but it will give you an idea how close to the correct heading the object is. Sort of. It’s difficult to say without seeing the rest of the code or knowing what this should be doing.

OK, finally Kishotta answer and the link below help me to understand what Vector3.Dot and Vector3.Cross do.

Cross Product and Dot Product: Visual explanation

“On of most important application of Math appear in game development”