]> Untitled Git - frog-ninja.git/blobdiff - player/walk.gd
Fixed up moves
[frog-ninja.git] / player / walk.gd
index 5f536b356b7d2c4a39260913c5ea11ac4a7f9873..e9cf6d9d82397e8f5e657d7926bc92c2e04a2b88 100644 (file)
@@ -8,20 +8,29 @@ func should_enter(input) -> String:
 
 
 func update(input: InputPacket, delta: float):
+       player.velocity = get_new_velocity_from_input(input, delta)
+       player.move_and_slide()
+
+
+func get_new_velocity_from_input(input: InputPacket, delta: float) -> Vector3:
        # Get the XZ input direction based on player's input relative to the camera
        var forward := camera.global_basis.z
        var right := camera.global_basis.x
-       var move_direction := (
+       var movement_direction := (
                forward * input.movement_direction.y + right * input.movement_direction.x
                ).normalized()
-       move_direction.y = 0
+       movement_direction.y = 0
+
+       # save off last movement direction 
+       if movement_direction.length() > 0.2:
+               player.last_movement_direction = movement_direction
        
        # if we're not stuck, then it's okay to set the velocity
-       var floor_normal = player.get_floor_normal()
-       var ground_slope_input = (PI / 2) - player.velocity.angle_to(floor_normal)
-       player.velocity = player.velocity.move_toward(
-               move_direction * (player.walk_speed + ground_slope_input * player.walk_speed),
+       player.floor_normal = player.get_floor_normal()
+       player.ground_slope_input = (PI / 2) - player.velocity.angle_to(player.floor_normal)
+       var new_velocity = player.velocity.move_toward(
+               movement_direction * (player.walk_speed + player.ground_slope_input * player.walk_speed),
                player.acceleration * delta
                )
-
-       player.move_and_slide()
+       
+       return new_velocity