+4 votes

Regarding

https://godotengine.org/qa/17247/how-to-know-the-screen-position-of-a-node2d

It seems getglobaltransformwithcanvas() is no longer an option with Godot 3?

I'm attempting to have a CanvasLayer element appear directly above a character. I just need a method to return the position of the character relevant to the screen and camera.

Thanks!

in Engine by (35 points)

y dont u make use of global script use it to get ur viewport rect

How would I then go about tracking a Position2D (for instance) within that space as it moves?

Why isn't it a option anymore, the method still exist in CanvasItem?

1 Answer

+1 vote
Best answer

As coffeeDragon pointed out, get_global_transform_with_canvas() is still an option - my mistake!

I was able to get the UI element to appear above the player's head simply with

var player_pos = get_node("/root/Game/Player").get_global_transform_with_canvas()
var spawn_pos = player_pos.get_origin()
position = spawn_pos

Thanks everyone.

by (35 points)
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 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 webmaster@godotengine.org with your username.