This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+13 votes

How to know the screen position of a node2D?

in Engine by (388 points)

2 Answers

+20 votes
Best answer

get_global_transform_with_canvas() will return a node's transform relative to your viewport. The o property of this will be that transform's origin (position if you will).

by (1,328 points)
selected by

As of 3.1.1, o had been renamed to origin so get_global_transform_with_canvas().origin

Perhaps i'm mistaken, but in my tests, getglobaltransformwithcanvas().origin is giving me the global position, not relative to the viewport... how can i get that position? I need to use it on a shader.

It returns the position to the top-left corner of the window for me in the 2D Platformer demo. You probably wanna open a new question for this.

–8 votes


by (9,800 points)

But doesn't the node.get_global_pos() gives the position on the "world"?

If a camera is centered on a node, the node will always be centered on the screen (same screen position always), but the node global pos will be changed as the node is moved.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.