Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

finding distance y between two objects?

Discussion in 'Scripting' started by JohnDmu, Apr 23, 2015.

  1. JohnDmu

    JohnDmu

    Joined:
    Apr 8, 2015
    Posts:
    33
    i use something like this to generally find the distance between two objects but how can
    i find only the y distance??

    Code (CSharp):
    1. public float distance;
    2. public Transform target;
    3.  
    4. ......
    5. .
    6. .
    7. .
    8.  
    9.  
    10.  
    11. distance =Vector3.Distance(transform.position,target.position);
     
  2. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    Code (CSharp):
    1. Transform A = something
    2. Transform B = somethingElse
    3.  
    4. Distance = Mathf.abs( A.position.y - B.position.y )
     
  3. JohnDmu

    JohnDmu

    Joined:
    Apr 8, 2015
    Posts:
    33
    you mean Mathf.Abs..
    haha i spent 20 minutes trying to understand what is wrong!
    thank you very much mate!!