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