The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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?

in Engine by (29 points)
edited by

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.

by (1,124 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.