Check values in Vector2

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ArondenOuden

I have followed the tutorial from GDquest about swiping.
Now I get an Vector2 corresponding to the direction the swipe is going:

  • Right: (1, 0)
  • Left: (-1, 0)
  • Up (0, 1)
  • Down (0, -1)

Now I want to check which of these values the Vector2 has to move it in that direction.

I tried this, but it didn’t work:

func _on_SwipeDetector_swiped(direction):

if direction == Vector2(-1, 0):
var direction_going = “right”
if direction == Vector2(1, 0):
var direction_going = “left”
if direction == Vector2(0, 1):
var direction_going = “up”
if direction == Vector2(0, -1):
var direction_going = “down”

(b.t.w. I used tabs, but they don’t show up here)

Are you sure that the direction parameter passed in is definitely a Vector2?

Eric Ellingson | 2019-06-23 00:21