How to move a parent thru its children

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jarlowrey
:warning: Old Version Published before Godot 3 was released.

Typically when you move a parent it’s children move along with it. I want to be able to move a child and have its parents move (up to a point, don’t want to move root or the viewport). Is there a way to do this? Should I switch the child/parent role and then switch back, does that cause any weirdness/data loss?

:bust_in_silhouette: Reply From: Graphitik

Just move the parent, the child will follow,
you can use :

get_parent().set_pos()
get_node("..").set_pos()  #with '..' meaning one level above
get_node("../../").set_pos() to go 2 levels above

Documentation is here : Node — Godot Engine (latest) documentation in English

:bust_in_silhouette: Reply From: jarlowrey

Accidentally posted this question twice (again here - Moving a node as if the child was the parent - Archive - Godot Forum )

This works perfect! Avoids all messy/dumb reparenting stuff and works no matter how many parenting layers are between parent and child

var diff = get_global_pos() - my_child.get_global_pos()
set_global_pos(other_node.get_global_pos() + diff)