Why is transform position returning odd results?

Calculating the range to a target and getting some bizarre results with transform.position not matching in editor position and throwing out the range calculations?

in Unity 2018.1.0f1.

Vector3 distance = (target.position - transform.position);

            Debug.Log("Target Pos["+target.position+"] Pos ["+transform.position+"] Distance ["+distance.ToString()+"]" + distance.magnitude);

            if (distance.magnitude < 5f)

Note the object moving is being moved by a Nav Agent component on a navmesh.

Target position will be the target currently, for the navmesh agent. This can be a partial path I think. Transform position will always reflect the transform’s current position.

To make it clearer for you, draw a debug line between the two points and watch the process in scene view. If after this, you feel it really is bugged, I think everyone would love a case number.

2 Likes