![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | creativeape |
I have a button I can click which will wait for me to click in the 2D Scene View, it should then report where in the world I clicked.
Currently, I can get the screen position of the mouse, but not relative to the world. Not sure how to do this in the editor.
What I have so far:
func _forward_canvas_gui_input(event):
if will_get_world_coord:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
var scene = get_editor_interface().get_edited_scene_root()
# what to do here?
will_get_world_coord = false
getWorldCoordButton.set_pressed_no_signal(false)
return true
else:
return false
Note that, scene.get_global_mouse_position() returns 0,0.
According to this: post here, get_global_mouse_position()
returns the mouse position in regards to the current canvas layer ( I assume that means the screen) and get_local_mouse_position()
returns the mouse position relative to the node from which it was called.
However, I’m not sure this would help you if you’re calling mouse pos through a gui element, because they tend to be on canvas layer, I’m not sure.
ka0s420 | 2022-10-03 07:46