5 const skin_lean_limit := PI/8
7 @export var movement_speed: float
10 func update(input: InputPacket, delta: float):
11 super.update(input, delta)
12 player.velocity = get_new_velocity_from_input(input, delta, movement_speed)
13 player.move_and_slide()
17 func update_skin(delta: float):
18 # update skin rotation
19 var skin_target_angle := Vector3.BACK.signed_angle_to(
20 player.last_movement_vector,
23 player.model.global_rotation.y = lerp_angle(
24 player.model.global_rotation.y,
26 PlayerVariables.rotation_speed * delta
29 # lean into player momentum just a little bit
30 player.model.rotation.z = lerp_angle(
31 player.model.rotation.z,
33 player.last_movement_vector.signed_angle_to(
34 player.velocity, Vector3.UP
35 ) * player.velocity.length() * 0.08,
36 -skin_lean_limit, skin_lean_limit
38 PlayerVariables.rotation_speed * delta * 0.25
42 func get_new_velocity_from_input(input: InputPacket, delta: float, speed: float) -> Vector3:
43 var movement_vector := Vector3(
44 input.player_movement_direction.x,
46 input.player_movement_direction.y
49 # save off last movement direction
50 if movement_vector.length() > 0.2:
51 player.last_movement_vector = movement_vector
53 # if we're not stuck, then it's okay to set the velocity
54 player.floor_normal = player.get_floor_normal()
55 player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal)
56 var new_velocity = player.velocity.move_toward(
57 movement_vector * (speed + player.ground_slope_input * speed),
58 PlayerVariables.acceleration * delta