From 082f834d615e0b1380861b3a50a2f727bee4aa51 Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Sun, 27 Sep 2026 10:17:24 +0200 Subject: [PATCH] Fix RunState --- game/player/PlayerCharacter.tscn | 2 ++ game/player/StateMachine/IdleState.gd | 7 ------- game/player/StateMachine/PlayerCharacter.gd | 8 ++++++++ game/player/StateMachine/RunState.gd | 19 ++++++------------- game/player/StateMachine/WalkState.gd | 7 +++---- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/game/player/PlayerCharacter.tscn b/game/player/PlayerCharacter.tscn index d24f1b6..3b5fad4 100644 --- a/game/player/PlayerCharacter.tscn +++ b/game/player/PlayerCharacter.tscn @@ -8,6 +8,7 @@ [ext_resource type="Script" uid="uid://2agliol5dulc" path="res://game/player/StateMachine/WalkState.gd" id="4_lg056"] [ext_resource type="Script" uid="uid://dr5p8ygj25w6x" path="res://game/player/StateMachine/JumpState.gd" id="6_lwgph"] [ext_resource type="Script" uid="uid://dn5idrvu68k83" path="res://game/player/StateMachine/AimState.gd" id="7_kxr4l"] +[ext_resource type="Script" uid="uid://dpcfffs3vt5co" path="res://game/player/StateMachine/RunState.gd" id="8_j4mf1"] [sub_resource type="Curve" id="Curve_kxr4l"] _limits = [0.0, 10.0, 0.0, 1.0] @@ -82,6 +83,7 @@ script = ExtResource("6_lwgph") script = ExtResource("7_kxr4l") [node name="RunState" type="Node" parent="StateMachine" unique_id=1345421775] +script = ExtResource("8_j4mf1") [node name="InputManagementComponent" type="Node" parent="." unique_id=1981951371] script = ExtResource("2_r5dqo") diff --git a/game/player/StateMachine/IdleState.gd b/game/player/StateMachine/IdleState.gd index 42a2bae..e05d1d0 100644 --- a/game/player/StateMachine/IdleState.gd +++ b/game/player/StateMachine/IdleState.gd @@ -51,13 +51,6 @@ func input_management() -> void: if Input.is_action_just_pressed(play_char.aim_cam_action): transitioned.emit(self, "AimState") - if play_char.continious_run: - if Input.is_action_just_pressed(play_char.run_action): - if play_char.walk_or_run == "WalkState": play_char.walk_or_run = "RunState" - elif play_char.walk_or_run == "RunState": play_char.walk_or_run = "WalkState" - else: - play_char.walk_or_run = "RunState" if Input.is_action_pressed(play_char.run_action) else "WalkState" - func move(delta : float) -> void: #manage the character movement diff --git a/game/player/StateMachine/PlayerCharacter.gd b/game/player/StateMachine/PlayerCharacter.gd index 71b72f6..57cc279 100644 --- a/game/player/StateMachine/PlayerCharacter.gd +++ b/game/player/StateMachine/PlayerCharacter.gd @@ -59,6 +59,7 @@ var move_left_action : StringName var move_right_action : StringName var run_action : StringName var jump_action : StringName +var dodge_action : StringName var aim_cam_action : StringName @export_group("Model variables") @@ -100,6 +101,7 @@ func _process(delta: float): modify_model_orientation(delta) func _physics_process(_delta : float): + update_run_toggle() modify_physics_properties() move_and_slide() @@ -159,3 +161,9 @@ func squash_and_strech(value : float, timing : float): #foot_step_audio.play() #) +func update_run_toggle() -> void: + if continious_run: + if Input.is_action_just_pressed(run_action): + walk_or_run = "WalkState" if walk_or_run == "RunState" else "RunState" + else: + walk_or_run = "RunState" if Input.is_action_pressed(run_action) else "WalkState" diff --git a/game/player/StateMachine/RunState.gd b/game/player/StateMachine/RunState.gd index 27acf2b..ec866ab 100644 --- a/game/player/StateMachine/RunState.gd +++ b/game/player/StateMachine/RunState.gd @@ -48,20 +48,13 @@ func applies() -> void: func input_management() -> void: if Input.is_action_pressed(play_char.jump_action) if play_char.auto_jump else Input.is_action_just_pressed(play_char.jump_action): transitioned.emit(self, "JumpState") + + if Input.is_action_just_pressed(play_char.aim_cam_action): + transitioned.emit(self, "AimState") - if play_char.continious_run: - #course continue : un nouvel appui sur la touche repasse a la marche - if Input.is_action_just_pressed(play_char.run_action): - stop_running() - else: - #course maintenue : on court tant que la touche est enfoncee - if !Input.is_action_pressed(play_char.run_action): - stop_running() - -func stop_running() -> void: - play_char.walk_or_run = "WalkState" - transitioned.emit(self, "WalkState") - + if play_char.walk_or_run == "WalkState": + transitioned.emit(self, "WalkState") + func move(delta : float) -> void: play_char.move_dir = Input.get_vector(play_char.move_left_action, play_char.move_right_action, play_char.move_forward_action, play_char.move_backward_action).rotated(-play_char.cam_holder.global_rotation.y) diff --git a/game/player/StateMachine/WalkState.gd b/game/player/StateMachine/WalkState.gd index eaac5f3..ea2a043 100644 --- a/game/player/StateMachine/WalkState.gd +++ b/game/player/StateMachine/WalkState.gd @@ -51,10 +51,8 @@ func input_management() -> void: if Input.is_action_just_pressed(play_char.aim_cam_action): transitioned.emit(self, "AimState") - - var wants_run : bool = Input.is_action_just_pressed(play_char.run_action) if play_char.continious_run else Input.is_action_pressed(play_char.run_action) - if wants_run: - play_char.walk_or_run = "RunState" + + if play_char.walk_or_run == "RunState": transitioned.emit(self, "RunState") func move(delta : float) -> void: @@ -66,3 +64,4 @@ func move(delta : float) -> void: play_char.velocity.z = lerp(play_char.velocity.z, play_char.move_dir.y * play_char.move_speed, play_char.move_accel * delta) else: transitioned.emit(self, "IdleState") +