5 const skin_lean_limit := PI/8
8 func update(input: InputPacket, delta: float):
9 player.velocity = get_new_velocity_from_input(input, delta, player.walk_speed)
10 player.move_and_slide()
14 func on_enter_state():
15 player.skin.transition_move()
18 func update_skin(delta: float):
19 # update skin rotation
20 var skin_target_angle := Vector3.BACK.signed_angle_to(
21 player.last_movement_direction,
24 player.skin.global_rotation.y = lerp_angle(
25 player.skin.global_rotation.y,
27 player.rotation_speed * delta
30 # lean into player momentum just a little bit
31 player.skin.rotation.z = lerp_angle(
32 player.skin.rotation.z,
34 player.last_movement_direction.signed_angle_to(
35 player.velocity, Vector3.UP
36 ) * player.velocity.length() * 0.08,
37 -skin_lean_limit, skin_lean_limit
39 player.rotation_speed * delta * 0.25
42 player.skin.set_walking_speed(player.velocity.length())
45 func get_new_velocity_from_input(input: InputPacket, delta: float, speed: float) -> Vector3:
46 # Get the XZ input direction based on player's input relative to the camera
47 var forward := camera.global_basis.z
48 var right := camera.global_basis.x
49 var movement_direction := (
50 forward * input.movement_direction.y + right * input.movement_direction.x
52 movement_direction.y = 0
54 # save off last movement direction
55 if movement_direction.length() > 0.2:
56 player.last_movement_direction = movement_direction
58 # if we're not stuck, then it's okay to set the velocity
59 player.floor_normal = player.get_floor_normal()
60 player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal)
61 var new_velocity = player.velocity.move_toward(
62 movement_direction * (speed + player.ground_slope_input * speed),
63 player.acceleration * delta