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

position game object relative to another game object

Discussion in 'Scripting' started by Bioshok2, Oct 4, 2015.

  1. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello ,

    Please how to know, position of a game object relative to another gameobject without using gameobject relationship, father son,

    Thank you very much and good day.

    Best regards .
     
  2. DeuS

    DeuS

    Joined:
    Feb 8, 2013
    Posts:
    24
    With this i receive same value as with relationship:
    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour
    2. {
    3.     public Transform FirstTransform;
    4.     public Transform SecondTransform;
    5.  
    6.     private void Start()
    7.     {
    8.         Debug.Log("First Relative to Second = " + (FirstTransform.position - SecondTransform.position));
    9.         Debug.Log("Second Relative to First = " + (SecondTransform.position - FirstTransform.position));
    10.     }
    11. }
     
    Bioshok2 likes this.
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,004
    Read a bit on Vector math :)
     
    Bioshok2, passerbycmc and Kiwasi like this.
  4. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Thank you very much
     
  5. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    I just forgot the solution :(