]> Untitled Git - frog-ninja.git/blobdiff - player/moves/walk.gd
Refactoring
[frog-ninja.git] / player / moves / walk.gd
index 8d92aa7765b92fc34c73660fd6fe50e82c516203..dd707bb0ab9ad6f78b0a7a301354bea6721f25fe 100644 (file)
@@ -2,13 +2,18 @@ extends Move
 class_name Walk
 
 
-const skin_lean_limit := PI/4
+const skin_lean_limit := PI/8
+
+@export var movement_speed := 10.0
 
 
 func update(input: InputPacket, delta: float):
-       player.velocity = get_new_velocity_from_input(input, delta)
+       player.velocity = get_new_velocity_from_input(input, delta, movement_speed)
        player.move_and_slide()
-       
+       update_skin(delta)
+
+
+func update_skin(delta: float):
        # update skin rotation
        var skin_target_angle := Vector3.BACK.signed_angle_to(
                player.last_movement_direction, 
@@ -31,22 +36,14 @@ func update(input: InputPacket, delta: float):
                        ),
                player.rotation_speed * delta * 0.25
                )
-               
-       player.skin.set_walking_speed(player.velocity.length())
 
 
-func on_enter_state():
-       player.skin.transition_move()
-
-
-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 movement_direction := (
-               forward * input.movement_direction.y + right * input.movement_direction.x
-               ).normalized()
-       movement_direction.y = 0
+func get_new_velocity_from_input(input: InputPacket, delta: float, speed: float) -> Vector3:
+       var movement_direction := Vector3(
+               input.player_movement_direction.x,
+               0,
+               input.player_movement_direction.y
+               )
 
        # save off last movement direction 
        if movement_direction.length() > 0.2:
@@ -56,7 +53,7 @@ func get_new_velocity_from_input(input: InputPacket, delta: float) -> Vector3:
        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),
+               movement_direction * (speed + player.ground_slope_input * speed),
                player.acceleration * delta
                )