diff --git a/Player/player_controller.gd b/Player/player_controller.gd index e4a00d5..a41ae07 100644 --- a/Player/player_controller.gd +++ b/Player/player_controller.gd @@ -7,6 +7,8 @@ const BASE_MOVE_SPEED: float = 5 const SPRINT_MOVE_SPEED: float = 8 const BASE_HEIGHT: float = 2.0 const CROUCH_HEIGHT: float = 1.0 +const FRICTION: float = 0.2 +const AIR_FRICTION: float = 0.025 const CROUCH_TRANSITION_SPEED: float = 0.1 enum MovementMode { @@ -62,8 +64,17 @@ func handle_movement(delta: float) -> void: "move_forward", "move_backward") var movement_dir := transform.basis * Vector3(input.x, 0, input.y) - velocity.x = movement_dir.x * move_speed - velocity.z = movement_dir.z * move_speed + if movement_dir.x == 0: + velocity.x = lerpf(velocity.x, 0.0, + FRICTION if is_on_floor() else AIR_FRICTION) + else: + velocity.x = movement_dir.x * move_speed + + if movement_dir.z == 0: + velocity.z = lerpf(velocity.z, 0.0, + FRICTION if is_on_floor() else AIR_FRICTION) + else: + velocity.z = movement_dir.z * move_speed func handle_state_transition() -> void: match current_movement: