]> Untitled Git - frog-ninja.git/blob - player/walk.gd
Separated model movement into discrete states
[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         # Get the XZ input direction based on player's input relative to the camera
12         var forward := camera.global_basis.z
13         var right := camera.global_basis.x
14         var move_direction := (
15                 forward * input.movement_direction.y + right * input.movement_direction.x
16                 ).normalized()
17         move_direction.y = 0
18         
19         # if we're not stuck, then it's okay to set the velocity
20         var floor_normal = player.get_floor_normal()
21         var ground_slope_input = (PI / 2) - player.velocity.angle_to(floor_normal)
22         player.velocity = player.velocity.move_toward(
23                 move_direction * (player.walk_speed + ground_slope_input * player.walk_speed),
24                 player.acceleration * delta
25                 )
26
27         player.move_and_slide()