summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortpart <tpart120@proton.me>2024-09-28 23:58:52 +0200
committertpart <tpart120@proton.me>2024-09-28 23:58:56 +0200
commit7c24fc6eb28fd036978239a8934d91c90edcfa76 (patch)
tree1d398acd79dba0d407d77f8ed7b099feb119bf8a
parent7bb87fdf2178b672c49d8630ad1f8521034230c9 (diff)
downloadhurrycurry-7c24fc6eb28fd036978239a8934d91c90edcfa76.tar
hurrycurry-7c24fc6eb28fd036978239a8934d91c90edcfa76.tar.bz2
hurrycurry-7c24fc6eb28fd036978239a8934d91c90edcfa76.tar.zst
Add new controller vibration system (Fixes #180)
-rw-r--r--client/player/controllable_player.gd24
1 files changed, 23 insertions, 1 deletions
diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd
index 131bc55d..c291f2a5 100644
--- a/client/player/controllable_player.gd
+++ b/client/player/controllable_player.gd
@@ -34,9 +34,17 @@ var chat_open := false
var enable_input := true
var input_rotation = 0
+var vibration_timer := Timer.new()
+var current_vibration_strength := 0.
+var current_vibration_change := 0.
+
var target: Vector2i = Vector2i(0, 0)
func _ready():
+ vibration_timer = Timer.new()
+ vibration_timer.wait_time = 0.1
+ vibration_timer.timeout.connect(_on_vibration_timeout)
+ add_child(vibration_timer)
var timer = Timer.new()
timer.one_shot = false
timer.wait_time = 1. / 50.
@@ -159,7 +167,21 @@ func update_position(_new_position: Vector2, _new_rotation: float, _new_boosting
func progress(position__: float, speed: float, warn: bool):
super(position__, speed, warn)
- Input.start_joy_vibration(0, 0.5, 0.1, 0.15)
+ if warn:
+ current_vibration_strength = position__
+ current_vibration_change = speed
+ Input.start_joy_vibration(0, 1 * pow(current_vibration_strength, 3), 0, 0.1)
+ vibration_timer.start()
+ if speed == 0:
+ current_vibration_strength = 0.
+ vibration_timer.stop()
+
+func _on_vibration_timeout():
+ current_vibration_strength = clampf(current_vibration_strength + current_vibration_change * 0.1, 0, 1)
+ if current_vibration_strength == 0.:
+ return
+ Input.start_joy_vibration(0, 1 * pow(current_vibration_strength, 3), 0, 0.1)
+ vibration_timer.start()
func put_item(tile: Tile):
super(tile)