Update locomotion logic to handle airborne state and previous locomotion state

This commit is contained in:
2026-04-11 19:34:22 +02:00
parent 23b875ff35
commit baa3c794d0
4 changed files with 106 additions and 3 deletions

View File

@@ -272,6 +272,7 @@ export class FirstPersonNavigationController implements NavigationController {
movementYawRadians: this.yawRadians,
standingShape: this.standingPlayerShape,
verticalVelocity: this.verticalVelocity,
previousLocomotionState: this.locomotionState,
crouched: this.locomotionState.crouched,
wasJumpPressed: this.jumpPressed,
input: inputState,

View File

@@ -69,6 +69,7 @@ export interface StepPlayerLocomotionOptions {
movementYawRadians: number;
standingShape: FirstPersonPlayerShape;
verticalVelocity: number;
previousLocomotionState?: RuntimeLocomotionState;
crouched: boolean;
wasJumpPressed: boolean;
input: PlayerStartActionInputState;
@@ -286,14 +287,25 @@ export function stepPlayerLocomotion(
options.movement.capabilities.sprint &&
sprintPressed &&
!crouched &&
currentlyGrounded &&
!currentVolumeState.inWater;
const requestedPlanarSpeed =
const groundedRequestedPlanarSpeed =
options.movement.moveSpeed *
(crouched
? CROUCH_SPEED_MULTIPLIER
: sprinting
? SPRINT_SPEED_MULTIPLIER
: 1);
const airborneRequestedPlanarSpeed = Math.max(
options.movement.moveSpeed,
options.previousLocomotionState?.requestedPlanarSpeed ?? 0
);
const requestedPlanarSpeed =
activeShape.mode !== "none" &&
!currentVolumeState.inWater &&
!currentlyGrounded
? airborneRequestedPlanarSpeed
: groundedRequestedPlanarSpeed;
const planarMotion = computePlanarMotion(
options.movementYawRadians,
options.input,

View File

@@ -244,6 +244,7 @@ export class ThirdPersonNavigationController implements NavigationController {
movementYawRadians: this.cameraYawRadians,
standingShape: this.standingPlayerShape,
verticalVelocity: this.verticalVelocity,
previousLocomotionState: this.locomotionState,
crouched: this.locomotionState.crouched,
wasJumpPressed: this.jumpPressed,
input: inputState,