0 votes

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.getglobalmouse_position() returns 0,0.

Godot version 4.0 beta 1
in Engine by (120 points)

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.

Please log in or register to answer this question.

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.