How can I match the positions of two children nodes by moving the parent?

Godot Version

4.2

Question

imagine a scene structure:

— Parent Node 1
— — Marker 1
— Parent Node 2
— — Marker 2

if you had to match the global positions of marker 1 and marker 2 (with them having an offset on their local position) by moving the parent nodes, how would you do it? and if that seemed easy, how would you work out when a global rotation is applied on the y axis?

in another words, im making rooms that should connect to each other via a doorframe, to achieve this i’ve decided the easiest way would be to match the positions of a “DoorwayIn” and a “DoorwayOut” room nodes. DoorwayIn and DoorwayOut are doorframe meshes, ive managed to deal with this problem by subtracting the previous room’s global DoorwayOut position from new room’s DoorwayIn local position (see image below for reference)

The only problem im facing right now is I got rooms that can change the “way” the room are creating to the left/right or even turn around 180 degrees on a higher Y level (like a staircase that goes up and back the same way you came from), heres some more screenshots:


video demo of current state:
https://mega.nz/file/dZsizQ4D#WRZsEKjCV9a-nOg3miCyfgIT0C5iiV8SHeGlgwYZkLI

Im not sure about the rotation but the matching position should be fairly simple:

func getNewParentPosition() -> Vector3:
    var distance = other_child.global_position - my_child.global_position
    var myNewPosition = distance - my_child.position
    return myNewPosition

EDIT:
Do you rotate the parent or the child?

I’ve put the rooms geometry in a new parent node3d which acts as a “pivot” point, the doorframe is always at 0,0,0 coordinates, rotating this node around would rotate it with doorframeIn being the pivot point, this fixed it for me, thanks for replying though.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.