Hello,
I recently followed a tutorial to learn how to detect swipes and I realized that there's no defined zone.
I can swipe any where on the view port play test and it'll work, even if I shrink the shape of the scripted node that detects the swipes.
Is there a way to define/make dedicated areas for input touch detection of swipes?
The issue is that I want to make 2 respective zones for swipe detection and not just one.
Here is the code I used if that's any help:
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 and $Arrow.rotation_degrees == 90:
correct_swipe()
elif difference.x <0 and $Arrow.rotation_degrees == 270:
correct_swipe()
else:
if difference.y > 0 and $Arrow.rotation_degrees == 180:
correct_swipe()
elif difference.y < 0 and $Arrow.rotation_degrees == 0:
correct_swipe()
func correct_swipe() -> void:
set_arrow_rotation()
func set_arrow_rotation() -> void:
var random_arrow_rotation : int = $Arrow.rotation_degrees / 90
var new_rotation : int
while true:
new_rotation = randi() % 4
if new_rotation != random_arrow_rotation:
break
$Arrow.rotation_degrees = new_rotation * 90
Open to any helpful tutorials and or resources.
I checked the Godot Online documentation but it wasn't of much help.