Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Why is transform position returning odd results?

Discussion in '2018.1 Beta' started by Arowx, Apr 30, 2018.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    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.

    Code (CSharp):
    1. Vector3 distance = (target.position - transform.position);
    2.  
    3.             Debug.Log("Target Pos["+target.position+"] Pos ["+transform.position+"] Distance ["+distance.ToString()+"]" + distance.magnitude);
    4.  
    5.             if (distance.magnitude < 5f)
    Note the object moving is being moved by a Nav Agent component on a navmesh.
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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.
     
    Peter77 and LeonhardP like this.