How to get a Node's absolute position in the world

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Michael Aganier

If I have a parent Node2D with transform’s translation at (50, 0) and a child Node2D with transform’s translation at (100, 0).

When I type parent.position, I get (50,0).
When I type child.position, I get (100,0).

These are their respective node’s relative position, but not the absolute position in the world. The child’s absolute position is its relative position added to the parent’s relative position: (50,0) + (100,0) = (150, 0)

How do I get the absolute position of a node?

:bust_in_silhouette: Reply From: nathanwfranke

global_position

Another interesting thing I noticed in Godot 4.2, is that when you put Marker2D under just Node, Marker2D’s local and global positions are going to be equal.

In my particular case I had:
Player

  • CollisionPolygon2D
  • Sprite2D
  • Node
    • Marker2D

This marker2D’s local and global positions are going to be the same & constant despite player moving around the map