Topic was automatically imported from the old Question2Answer platform.
Asked By
lalel345
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
print(a)
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
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")
But… If I move the mouse from say -78 to -56, I’ve moved it to the right, yet I’m still <0…
Macryc | 2021-01-03 15:14
godot 3.4.4
func _input(event):
if event is InputEventMouseMotion:
if event.get_relative().x > 0:
print("Moving right")
if event.get_relative().x < 0:
print("Moving left")