0 votes

i use Input(event) and InputEventMouseMotion, but how do i know if the mouse moves left or right

func _input(event):
if event is InputEventMouseMotion:
    if event.relative:
        a += 1 
        a -= 1

I want that when I move the mouse to the right it adds the variable and when I turn to the left it subtracts, detect the negative and positive side. for now the variables are added and subtracted at the same time since I can't get the mouse side for each one

in Projects by (175 points)

1 Answer

+2 votes

Hi! the relative property of InputEventMouseMotion already gives you the information about the direction you are moving. If the x component of relative is less than 0, you are moving left, if it is greater than 0, you are moving right. Same with y component for up and down. For example:

func _input(event):
    if event is InputEventMouseMotion:
        if event.relative.x > 0:
            print("Moving right")
        if event.relative.x < 0:
            print("Moving left")
by (3,404 points)

But... If I move the mouse from say -78 to -56, I've moved it to the right, yet I'm still <0...

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.
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 webmaster@godotengine.org with your username.