0 votes

Just need to know how to do this cause i cant seem to find anything on it in the documentation

in Engine by (483 points)

2 Answers

0 votes
Best answer

If you are creating a 2d game, you can get access to mouse x/y co-ordinates inside any function by using getglobalmouse_pos().

for example:

var mouse_pos = get_global_mouse_pos()
var mx = mouse_pos.x
var my = mouse_pos.y
by (268 points)
selected by

This is the Most Helpful one, thanks ^^

+2 votes

Do you mean position of mouse input event?

func _input(event):
    if event.type == 2 or event.type == 3:
        # Mouse motion or mouse button event
        var mouse_event_pos = event.pos 
by (675 points)

You can also use these constants for clarity:

if event.type == InputEvent.MOUSE_MOTION or event.type == InputEvent.MOUSE_BUTTON:

Not only for clarity, since APIs tend to change over time... :)

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.