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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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,021
    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 :(