X-Git-Url: http://git.purplebirdman.com/frog-ninja.git/blobdiff_plain/16f5fda45ed2a668758450eff052e0903d7ef3ae..47f9406a184d838e4701978a1a6f2dd871326d51:/player/walk.gd diff --git a/player/walk.gd b/player/walk.gd index 5f536b3..e9cf6d9 100644 --- a/player/walk.gd +++ b/player/walk.gd @@ -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