Created
March 2, 2025 16:04
-
-
Save lamarmarshall/3d9c5676c0c2ed762c958f944053e4b1 to your computer and use it in GitHub Desktop.
godot, swipe detect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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