Fix RunState
This commit is contained in:
parent
33ea8bbc38
commit
082f834d61
|
|
@ -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://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://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://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"]
|
[sub_resource type="Curve" id="Curve_kxr4l"]
|
||||||
_limits = [0.0, 10.0, 0.0, 1.0]
|
_limits = [0.0, 10.0, 0.0, 1.0]
|
||||||
|
|
@ -82,6 +83,7 @@ script = ExtResource("6_lwgph")
|
||||||
script = ExtResource("7_kxr4l")
|
script = ExtResource("7_kxr4l")
|
||||||
|
|
||||||
[node name="RunState" type="Node" parent="StateMachine" unique_id=1345421775]
|
[node name="RunState" type="Node" parent="StateMachine" unique_id=1345421775]
|
||||||
|
script = ExtResource("8_j4mf1")
|
||||||
|
|
||||||
[node name="InputManagementComponent" type="Node" parent="." unique_id=1981951371]
|
[node name="InputManagementComponent" type="Node" parent="." unique_id=1981951371]
|
||||||
script = ExtResource("2_r5dqo")
|
script = ExtResource("2_r5dqo")
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,6 @@ func input_management() -> void:
|
||||||
if Input.is_action_just_pressed(play_char.aim_cam_action):
|
if Input.is_action_just_pressed(play_char.aim_cam_action):
|
||||||
transitioned.emit(self, "AimState")
|
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:
|
func move(delta : float) -> void:
|
||||||
#manage the character movement
|
#manage the character movement
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ var move_left_action : StringName
|
||||||
var move_right_action : StringName
|
var move_right_action : StringName
|
||||||
var run_action : StringName
|
var run_action : StringName
|
||||||
var jump_action : StringName
|
var jump_action : StringName
|
||||||
|
var dodge_action : StringName
|
||||||
var aim_cam_action : StringName
|
var aim_cam_action : StringName
|
||||||
|
|
||||||
@export_group("Model variables")
|
@export_group("Model variables")
|
||||||
|
|
@ -100,6 +101,7 @@ func _process(delta: float):
|
||||||
modify_model_orientation(delta)
|
modify_model_orientation(delta)
|
||||||
|
|
||||||
func _physics_process(_delta : float):
|
func _physics_process(_delta : float):
|
||||||
|
update_run_toggle()
|
||||||
modify_physics_properties()
|
modify_physics_properties()
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
@ -159,3 +161,9 @@ func squash_and_strech(value : float, timing : float):
|
||||||
#foot_step_audio.play()
|
#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"
|
||||||
|
|
|
||||||
|
|
@ -48,20 +48,13 @@ func applies() -> void:
|
||||||
func input_management() -> 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):
|
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")
|
transitioned.emit(self, "JumpState")
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed(play_char.aim_cam_action):
|
||||||
|
transitioned.emit(self, "AimState")
|
||||||
|
|
||||||
if play_char.continious_run:
|
if play_char.walk_or_run == "WalkState":
|
||||||
#course continue : un nouvel appui sur la touche repasse a la marche
|
transitioned.emit(self, "WalkState")
|
||||||
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")
|
|
||||||
|
|
||||||
func move(delta : float) -> void:
|
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)
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,8 @@ func input_management() -> void:
|
||||||
|
|
||||||
if Input.is_action_just_pressed(play_char.aim_cam_action):
|
if Input.is_action_just_pressed(play_char.aim_cam_action):
|
||||||
transitioned.emit(self, "AimState")
|
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 play_char.walk_or_run == "RunState":
|
||||||
if wants_run:
|
|
||||||
play_char.walk_or_run = "RunState"
|
|
||||||
transitioned.emit(self, "RunState")
|
transitioned.emit(self, "RunState")
|
||||||
|
|
||||||
func move(delta : float) -> void:
|
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)
|
play_char.velocity.z = lerp(play_char.velocity.z, play_char.move_dir.y * play_char.move_speed, play_char.move_accel * delta)
|
||||||
else:
|
else:
|
||||||
transitioned.emit(self, "IdleState")
|
transitioned.emit(self, "IdleState")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue