How can I get grandparent node relative transform, not global

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Boris Šehovac

I wan’t to get transform of Position3D relative to grandparent, but not global. Currently I am doing this:

func moveNode(node, from, to):
  var temp_transform = node.global_transform
  from.remove_child(node)
  to.add_child(node)
  node.transform = temp_transform

But I need node transform relative to the parent of from and to, not global_transform, since node grandparent is scaled.

In three.js I was doing this in following way:

moveNode(node, from, to) {
  from.updateMatrixWorld();
  to.updateMatrixWorld();
  node.applyMatrix(from.matrixWorld)
  from.remove(piece)
  node.applyMatrix(new THREE.Matrix4().getInverse(to.matrixWorld))
  to.add(piece)
}

But I can’t find equivalent of applyMatrix and getInverse in Godot.

Why not just use both nodes’ global positioning to determine their related positioning? You can just factor in the scaling when comparing them, can’t you?

denxi | 2020-01-25 16:59