]> Untitled Git - frog-ninja.git/blob - player/walk.gd
Fixed up moves
[frog-ninja.git] / player / walk.gd
1 extends Move
2 class_name Walk
3
4
5 func should_enter(input) -> String:
6         input.actions.sort_custom(moves_priority_sort)
7         return input.actions[0]
8
9
10 func update(input: InputPacket, delta: float):
11         player.velocity = get_new_velocity_from_input(input, delta)
12         player.move_and_slide()
13
14
15 func get_new_velocity_from_input(input: InputPacket, delta: float) -> Vector3:
16         # Get the XZ input direction based on player's input relative to the camera
17         var forward := camera.global_basis.z
18         var right := camera.global_basis.x
19         var movement_direction := (
20                 forward * input.movement_direction.y + right * input.movement_direction.x
21                 ).normalized()
22         movement_direction.y = 0
23
24         # save off last movement direction 
25         if movement_direction.length() > 0.2:
26                 player.last_movement_direction = movement_direction
27         
28         # if we're not stuck, then it's okay to set the velocity
29         player.floor_normal = player.get_floor_normal()
30         player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal)
31         var new_velocity = player.velocity.move_toward(
32                 movement_direction * (player.walk_speed + player.ground_slope_input * player.walk_speed),
33                 player.acceleration * delta
34                 )
35         
36         return new_velocity