Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | nullsalad |
I’m trying to get the position of a Node2D as follows:
public override void _Ready()
{
Node2D pt = (Node2D)GetNode("../GetMe");
Vector2 coord = pt.get_global_position();
}
This fails to build with the error "Node2D does not contain a definition for ‘get_global_position()’. It looks like the docs in the editor list this as a getter function but I don’t see it listed on the online docs. I do see a member variable called global_position
however. But when I try to do Vector2 coord = pt.get_global_position;
I get the same error.
My object hierarchy looks like:
TileMap:
–KinematicBody2D (holds the script)
–Node2D “GetMe” (the object I’m trying to reference)
---- Sprite
So my questions are as follows:
- How do I get the position of a Node2D? What am I doing wrong here?
- Why does GetNode return a Node, when the object that I’m referencing is a Node2D?