Instantiate a GameObject at the position of one of its child objects

I’m working on a script to randomly generate a dungeon by connecting random rooms with each other based on their door positions. See picture:

alt text

To the left is an example of a room GameObject - containing a lot of child GameObjects being all the contents of the room. This includes its doors, depicted above. A room can have 1-4 doors, and I wish to instantiate new rooms at the positions of these doors (see picture in the middle).

My issue is that when I instantiate a new room GameObject, its pivot point is located in the center of the room - and thus, I don’t know how to align it with the doors. I can set its height correctly by instantiating it at the location of the original room, then moving it up as much as the room is long. However, I cannot get the horizontal position to work since I don’t know how to match up the door position (see picture to the right).

If I could tell it to be instantiated using the door location as its pivot, everything would work fine, but I don’t know if this is possible or if it’s the best solution. Any suggestions?

Sure, just use four markers

Funnily enough someone just asked about this:

So your Room thing will have four markers, that is, empty game objects, and we’ll call them doorMarkerA, doorMarkerB, doorMarkerC, doorMarkerD.

So you’re about to position a new room. we’ll call it NEWROOM.

Let’s say you want the CENTER of NEWROOM to be at point PLACEITHERE

of course, you just do this

NEWROOM .. get it from your pool
NEWROOM.transform.position = PLACEITHERE

So that’s obvious. Now, if you want DOOR “A” of the NEWROOM to be at the point PLACEITHERE,

Here is what you do:

NEWROOM .. get it from your pool
NEWROOM.transform.position = PLACEITHERE
NEWROOM.transform.position -= doorMarkerA.localPosition

So that’s exactly how you do it. You SUBTRACT the LOCAL POSITION of the relevant marker.

Hope it helps!