0 votes

Hi,

Trying to check mouse pos relative to the moving camera in the _input(e) loop, I'm getting all zeros for the global_ and relative_ member variables of InputEventMouseMotion

func _input(event):
    if event.type == InputEvent.MOUSE_MOTION:
        print("Global mouse: " + str(event.global_x) + ":" + str(event.global_pos.x))
        print("Relative mouse: " + str(event.relative_x) + ":" + str(event.relative_pos.x))
        print("Simple mouse: " + str(event.x) + ":" + str(event.pos.x))

The code above output:
Global mouse: 0:0
Relative mouse: 0:0
Simple mouse: 601:601

Am i doing something wrong or should I rely on get_global_mouse_pos() only?
Maybe there's another way to cast node pos into screen (viewport) space instead?

asked Jun 22, 2016 in Engine by Ilya (29 points)
edited Jun 22, 2016 by Ilya

1 Answer

0 votes

I can't confirm that the relative mouse position was always 0. It's 0 quite often since it's measured in pixels, so there will be moments where the position didn't change for a whole pixel between two frames.

The global position however is 0,0 for me as well, but since every Control has the get_global_mouse_pos()-method that member might be deprecated.

answered Jun 22, 2016 by Warlaan (1,116 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.