Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
Created March 2, 2025 16:04
Show Gist options
  • Save lamarmarshall/3d9c5676c0c2ed762c958f944053e4b1 to your computer and use it in GitHub Desktop.
Save lamarmarshall/3d9c5676c0c2ed762c958f944053e4b1 to your computer and use it in GitHub Desktop.
godot, swipe detect
extends Control
var pressed_position: Vector2
var release_position: Vector2
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed("click"):
pressed_position = event.position
if Input.is_action_just_released("click"):
release_position = event.position
calculate_swipe()
func calculate_swipe() -> void:
var difference: Vector2 = release_position - pressed_position
if abs(difference.x) > abs(difference.y):
if difference.x > 0:
print("Right")
else:
print("Left")
else:
if difference.y > 0:
print("Down")
else:
print("UP")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment