]> Untitled Git - frog-ninja.git/blob - player/moves/walk.gd
Added interpolated dashing
[frog-ninja.git] / player / moves / walk.gd
1 extends Move
2 class_name Walk
3
4
5 const skin_lean_limit := PI/4
6
7
8 func update(input: InputPacket, delta: float):
9         player.velocity = get_new_velocity_from_input(input, delta)
10         player.move_and_slide()
11         
12         # update skin rotation
13         var skin_target_angle := Vector3.BACK.signed_angle_to(
14                 player.last_movement_direction, 
15                 Vector3.UP
16                 )
17         player.skin.global_rotation.y = lerp_angle(
18                 player.skin.global_rotation.y,
19                 skin_target_angle,
20                 player.rotation_speed * delta
21         )
22         
23         # lean into player momentum just a little bit
24         player.skin.rotation.z = lerp_angle(
25                 player.skin.rotation.z,
26                 clamp(
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
31                         ),
32                 player.rotation_speed * delta * 0.25
33                 )
34                 
35         player.skin.set_walking_speed(player.velocity.length())
36
37
38 func on_enter_state():
39         player.skin.transition_move()
40
41
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
48                 ).normalized()
49         movement_direction.y = 0
50
51         # save off last movement direction 
52         if movement_direction.length() > 0.2:
53                 player.last_movement_direction = movement_direction
54         
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
61                 )
62         
63         return new_velocity