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
38 func get_new_velocity_from_input(input: InputPacket, delta: float) -> Vector3:
39 # Get the XZ input direction based on player's input relative to the camera
40 var forward := camera.global_basis.z
41 var right := camera.global_basis.x
42 var movement_direction := (
43 forward * input.movement_direction.y + right * input.movement_direction.x
45 movement_direction.y = 0
47 # save off last movement direction
48 if movement_direction.length() > 0.2:
49 player.last_movement_direction = movement_direction
51 # if we're not stuck, then it's okay to set the velocity
52 player.floor_normal = player.get_floor_normal()
53 player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal)
54 var new_velocity = player.velocity.move_toward(
55 movement_direction * (player.walk_speed + player.ground_slope_input * player.walk_speed),
56 player.acceleration * delta