5 const skin_lean_limit := PI/8
7 @export var movement_speed := 10.0
10 func update(input: InputPacket, delta: float):
11 player.velocity = get_new_velocity_from_input(input, delta, movement_speed)
12 player.move_and_slide()
16 func update_skin(delta: float):
17 # update skin rotation
18 var skin_target_angle := Vector3.BACK.signed_angle_to(
19 player.last_movement_direction,
22 player.skin.global_rotation.y = lerp_angle(
23 player.skin.global_rotation.y,
25 player.rotation_speed * delta
28 # lean into player momentum just a little bit
29 player.skin.rotation.z = lerp_angle(
30 player.skin.rotation.z,
32 player.last_movement_direction.signed_angle_to(
33 player.velocity, Vector3.UP
34 ) * player.velocity.length() * 0.08,
35 -skin_lean_limit, skin_lean_limit
37 player.rotation_speed * delta * 0.25
41 func get_new_velocity_from_input(input: InputPacket, delta: float, speed: float) -> Vector3:
42 var movement_direction := input.camera_movement_direction
43 movement_direction.y = 0
45 # save off last movement direction
46 if movement_direction.length() > 0.2:
47 player.last_movement_direction = movement_direction
49 # if we're not stuck, then it's okay to set the velocity
50 player.floor_normal = player.get_floor_normal()
51 player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal)
52 var new_velocity = player.velocity.move_toward(
53 movement_direction * (speed + player.ground_slope_input * speed),
54 player.acceleration * delta