- Home /
why is transform.position giving me local location?(c#)
I'm using this code to make a randomly-assembling dungeon out of prefab rooms. But whenever I try to get the current room's door location with "var prevDoor = prevRoom.transform.Find("doorNode").transform.position;", it gives me the position of the node relative to its parent(the room) instead of the global position and i don't know why. doorNode is a gameobject point that is a child to the room prefabs used to locate the door so i can place the next room's door on top of it.
var prevRoom = Instantiate(start, startPosition, Quaternion.identity) as GameObject;
prevRoom.transform.parent = Level.transform;
var prevDoor = prevRoom.transform.Find("doorNode").transform.position;
print(prevDoor);
prevRoom = Instantiate(northSouth, prevDoor, Quaternion.identity) as GameObject;
prevRoom.transform.parent = Level.transform;
prevDoor = prevRoom.transform.Find("doorNode").transform.position;
print(prevDoor);
Ideally, i would want to get the absolute position of the doorNode object from the prefab instance placed in a variable and then use that location to place the next room, then repeat until all the rooms are placed. I'm sure I'm just missing something really obvious and I'm still new to c#. thanks in advance.
Edit: turns out the thing that was causing the problem is pivots vs centerpoints on prefabs, so i changed the view to pivots and then made the prefabs center the same place as the pivot and it worked fine