forked from team-sg/hero-mark-2
walking acceleration when player is grounded
This commit is contained in:
parent
b4b7577479
commit
4c0513e84a
2 changed files with 16 additions and 2 deletions
|
@ -10,6 +10,8 @@ const DeathSplatter = preload("res://objects/player/player_death_particles.tscn"
|
||||||
# EXPORTS #
|
# EXPORTS #
|
||||||
## horizontal movement speed
|
## horizontal movement speed
|
||||||
export var walk_speed: float = 50.0
|
export var walk_speed: float = 50.0
|
||||||
|
## frames until walk speed peak (at 60fps reference)
|
||||||
|
export var walk_acceleration_frames: float = 1.0
|
||||||
## speed to push pushable objects at
|
## speed to push pushable objects at
|
||||||
export var push_speed: float = 25.0
|
export var push_speed: float = 25.0
|
||||||
## climbing speed
|
## climbing speed
|
||||||
|
@ -232,6 +234,17 @@ func _process_horizontal_movement(delta: float) -> void:
|
||||||
if input_dir != 0.0:
|
if input_dir != 0.0:
|
||||||
graphics.scale.x = input_dir
|
graphics.scale.x = input_dir
|
||||||
|
|
||||||
|
## player movement with acceleration
|
||||||
|
func _process_horizontal_movement_grounded(delta: float) -> void:
|
||||||
|
var input_dir = sign(Input.get_axis("ui_left", "ui_right")) # sign() to normalize
|
||||||
|
if input_dir == 0.0 or input_dir != sign(velocity.x):
|
||||||
|
velocity.x = 0.0
|
||||||
|
var acceleration = lerp(0.0, walk_speed, 1.0 / walk_acceleration_frames) * 60.0
|
||||||
|
velocity.x += input_dir * acceleration * delta
|
||||||
|
velocity.x = clamp(velocity.x, -walk_speed, walk_speed)
|
||||||
|
if input_dir != 0.0:
|
||||||
|
graphics.scale.x = input_dir
|
||||||
|
|
||||||
## walk/idle state
|
## walk/idle state
|
||||||
func _process_can_walk(delta: float) -> void:
|
func _process_can_walk(delta: float) -> void:
|
||||||
if sign(Input.get_axis("ui_left", "ui_right")) != 0.0:
|
if sign(Input.get_axis("ui_left", "ui_right")) != 0.0:
|
||||||
|
|
|
@ -762,6 +762,7 @@ collision_layer = 128
|
||||||
collision_mask = 7
|
collision_mask = 7
|
||||||
moving_platform_apply_velocity_on_leave = 1
|
moving_platform_apply_velocity_on_leave = 1
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
walk_acceleration_frames = 8.0
|
||||||
gravity = 700.0
|
gravity = 700.0
|
||||||
jump_force = 140.0
|
jump_force = 140.0
|
||||||
double_jump_force = 124.0
|
double_jump_force = 124.0
|
||||||
|
@ -1158,7 +1159,7 @@ script = ExtResource( 8 )
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded" to="." method="_on_Grounded_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded" to="." method="_on_Grounded_state_entered"]
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded" to="." method="_process_grounded"]
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded" to="." method="_process_grounded"]
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_can_walk"]
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_can_walk"]
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_horizontal_movement"]
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_horizontal_movement_grounded"]
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Still" to="." method="_on_Still_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Still" to="." method="_on_Still_state_entered"]
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Walking" to="." method="_on_Walking_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Walking" to="." method="_on_Walking_state_entered"]
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Blinking" to="." method="_on_Blinking_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/CanWalk/Blinking" to="." method="_on_Blinking_state_entered"]
|
||||||
|
@ -1168,8 +1169,8 @@ script = ExtResource( 8 )
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/Pushing" to="." method="_process_pushing"]
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/Pushing" to="." method="_process_pushing"]
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Airborne" to="." method="_on_Airborne_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Airborne" to="." method="_on_Airborne_state_entered"]
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne" to="." method="_process_gravity"]
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne" to="." method="_process_gravity"]
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_jump"]
|
|
||||||
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_horizontal_movement"]
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_horizontal_movement"]
|
||||||
|
[connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_jump"]
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Airborne/Jump/NormalJump" to="." method="_on_NormalJump_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Airborne/Jump/NormalJump" to="." method="_on_NormalJump_state_entered"]
|
||||||
[connection signal="state_exited" from="StateChart/Root/Movement/Airborne/Jump/NormalJump" to="." method="_on_NormalJump_state_exited"]
|
[connection signal="state_exited" from="StateChart/Root/Movement/Airborne/Jump/NormalJump" to="." method="_on_NormalJump_state_exited"]
|
||||||
[connection signal="state_entered" from="StateChart/Root/Movement/Airborne/Jump/LadderJump" to="." method="_on_LadderJump_state_entered"]
|
[connection signal="state_entered" from="StateChart/Root/Movement/Airborne/Jump/LadderJump" to="." method="_on_LadderJump_state_entered"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue