+2 votes

So, there is, in unity, the function ScreenToWorldPoint() that transforms a point from screen space into world space.
Is there a similar function in godot?

in Engine by (75 points)

3 Answers

+4 votes
Best answer

This is the closest thing I know in godot.
Look at the camera methods in the documentation, such as:

Vector3 project_position (screen_point: Vector2, z_depth: float) const

Returns the 3D point in worldspace that maps to the given 2D
coordinate in the Viewport rectangle on a plane that is the given
z_depth distance into the scene away from the camera.

Or inverse:

Vector2 unproject_position (world_point: Vector3) const

Returns the 2D coordinate in the Viewport rectangle that maps to the
given 3D point in worldspace.

There is also something in the manual using Raycasting:

https://docs.godotengine.org/en/3.1/tutorials/physics/ray-casting.html#d-ray-casting-from-screen

by (2,258 points)
selected by
+2 votes

get_local_mouse_position() will return the mouse's co-ordinates relative to the node that you're calling it from, while get_global_mouse_position() will return the mouse's position relative to the current canvas layer.

by (449 points)
0 votes

Is this what you are looking for?

get_global_mouse_position()
by (1,888 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 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.