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 #
|
||||
## horizontal movement speed
|
||||
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
|
||||
export var push_speed: float = 25.0
|
||||
## climbing speed
|
||||
|
@ -232,6 +234,17 @@ func _process_horizontal_movement(delta: float) -> void:
|
|||
if input_dir != 0.0:
|
||||
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
|
||||
func _process_can_walk(delta: float) -> void:
|
||||
if sign(Input.get_axis("ui_left", "ui_right")) != 0.0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue