Getting a childs global position.

Hi,
I have a model which consists of several meshes eg, walls, doors etc. They are all grouped under one gameobject eg house. I set this gameobject at position(0,0,0). Now the wall at the back of the house is obviously not at position (0,0,0). However I’m not sure how exactly to find this position. I’ve tried transform.position and transform.localPosition but these just print out the position(0,0,0), which is not what I want. Can anyone please help me?

Should work just fine if you’re putting it on the child object(s).
transform.position does give the world coordinates.

If it’s not child objects you’re talking about, and just other parts of one big object, then you could make empty child objects and position them where you want them to be and then use those coord’s.

Put this on a child object and hit “P” to see the debug’s in the console. →

var myTrans : Transform ;
var myParent : Transform ;
 
function Start(){
   myTrans = transform ;
   myParent = transform.root ;
}
 
function Update(){
   if(Input.GetKeyDown(KeyCode.P)){
      Debug.Log("My world position = " + myTrans.position) ;
      Debug.Log("My position relative to my parent = " + myTrans.localPosition) ;
      Debug.Log("My parent's world position = " + myParent.position) ;
   }
}