Skip to content

Commit

Permalink
Merge pull request #117 from Calinou/add-hold-toggle-aiming
Browse files Browse the repository at this point in the history
Add hybrid hold-toggle aiming for better accessibility
  • Loading branch information
aaronfranke authored Apr 4, 2022
2 parents ce786f4 + 492f9db commit 9b2f443
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const CAMERA_CONTROLLER_ROTATION_SPEED = 3.0
const CAMERA_X_ROT_MIN = -89.9
const CAMERA_X_ROT_MAX = 70

# Release aiming if the mouse/gamepad button was held for longer than 0.4 seconds.
# This works well for trackpads and is more accessible by not making long presses a requirement.
# If the aiming button was held for less than 0.4 seconds, keep aiming until the aiming button is pressed again.
const AIM_HOLD_THRESHOLD = 0.4

const DIRECTION_INTERPOLATE_SPEED = 1
const MOTION_INTERPOLATE_SPEED = 10
const ROTATION_INTERPOLATE_SPEED = 10
Expand All @@ -22,6 +27,13 @@ var motion = Vector2()
var velocity = Vector3()

var aiming = false

# If `true`, the aim button was toggled on by a short press (instead of being held down).
var toggled_aim = false

# The duration the aiming button was held for (in seconds).
var aiming_timer = 0.0

var camera_x_rot = 0.0

onready var initial_position = transform.origin
Expand Down Expand Up @@ -89,7 +101,21 @@ func _physics_process(delta):
camera_x.y = 0
camera_x = camera_x.normalized()

var current_aim = Input.is_action_pressed("aim")
var current_aim = false

# Keep aiming if the mouse wasn't held for long enough.
if Input.is_action_just_released("aim") and aiming_timer <= AIM_HOLD_THRESHOLD:
current_aim = true
toggled_aim = true
else:
current_aim = toggled_aim or Input.is_action_pressed("aim")
if Input.is_action_just_pressed("aim"):
toggled_aim = false

if current_aim:
aiming_timer += delta
else:
aiming_timer = 0.0

if aiming != current_aim:
aiming = current_aim
Expand Down

0 comments on commit 9b2f443

Please sign in to comment.