From 273933d48b5f91d8cab0fcd36febc1569124577d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnis=20Aldi=C5=86=C5=A1=20=22NeZv=C4=93rs?= Date: Wed, 20 Nov 2024 23:06:11 +0200 Subject: [PATCH] add deadzone for movement and aim inputs --- .../scripts/actor/player/PlayerInput.gd | 2 +- .../top_down/scripts/input/ActionResource.gd | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/addons/top_down/scripts/actor/player/PlayerInput.gd b/addons/top_down/scripts/actor/player/PlayerInput.gd index 4d4bf3c1..0f852f21 100644 --- a/addons/top_down/scripts/actor/player/PlayerInput.gd +++ b/addons/top_down/scripts/actor/player/PlayerInput.gd @@ -49,7 +49,7 @@ func _physics_process(_delta:float)->void: # Walking direction var _axis:Vector2 = Vector2(Input.get_axis(action_resource.left_action, action_resource.right_action), Input.get_axis(action_resource.up_action, action_resource.down_action)) # Analog sticks sucks for diagonals - _axis = Vector2(ceil(abs(_axis.x)) * sign(_axis.x), ceil(abs(_axis.y)) * sign(_axis.y) ) + #_axis = Vector2(ceil(abs(_axis.x)) * sign(_axis.x), ceil(abs(_axis.y)) * sign(_axis.y) ) var _length:float = _axis.length() if _length > 0.01: diff --git a/addons/top_down/scripts/input/ActionResource.gd b/addons/top_down/scripts/input/ActionResource.gd index 8eb7e28d..92101c12 100644 --- a/addons/top_down/scripts/input/ActionResource.gd +++ b/addons/top_down/scripts/input/ActionResource.gd @@ -69,15 +69,16 @@ func _initialize()->void: _init_action(pause_action, [pause_kb, pause_gp].filter(_filter_empty)) - _init_action(right_action, [right_kb, right_gp].filter(_filter_empty)) - _init_action(left_action, [left_kb, left_gp].filter(_filter_empty)) - _init_action(up_action, [up_kb, up_gp].filter(_filter_empty)) - _init_action(down_action, [down_kb, down_gp].filter(_filter_empty)) + _init_action(right_action, [right_kb, right_gp].filter(_filter_empty), 0.2) + _init_action(left_action, [left_kb, left_gp].filter(_filter_empty), 0.2) + _init_action(up_action, [up_kb, up_gp].filter(_filter_empty), 0.2) + _init_action(down_action, [down_kb, down_gp].filter(_filter_empty), 0.2) + + _init_action(aim_right_action, [aim_right_kb, aim_right_gp].filter(_filter_empty), 0.1) + _init_action(aim_left_action, [aim_left_kb, aim_left_gp].filter(_filter_empty), 0.1) + _init_action(aim_up_action, [aim_up_kb, aim_up_gp].filter(_filter_empty), 0.1) + _init_action(aim_down_action, [aim_down_kb, aim_down_gp].filter(_filter_empty), 0.1) - _init_action(aim_right_action, [aim_right_kb, aim_right_gp].filter(_filter_empty)) - _init_action(aim_left_action, [aim_left_kb, aim_left_gp].filter(_filter_empty)) - _init_action(aim_up_action, [aim_up_kb, aim_up_gp].filter(_filter_empty)) - _init_action(aim_down_action, [aim_down_kb, aim_down_gp].filter(_filter_empty)) _init_action(action_1_action, [action_1_kb, action_1_gp].filter(_filter_empty)) _init_action(action_2_action, [action_2_kb, action_2_gp].filter(_filter_empty)) _init_action(next_action, [next_kb, next_gp].filter(_filter_empty)) @@ -85,9 +86,11 @@ func _initialize()->void: updated.emit() -func _init_action(action_name:StringName, event_list:Array)->void: +func _init_action(action_name:StringName, event_list:Array, deadzone:float = 0.5)->void: if !InputMap.has_action(action_name): InputMap.add_action(action_name) + InputMap.action_set_deadzone(action_name, deadzone) + for event:InputEvent in event_list: if InputMap.action_has_event(action_name, event): continue