Update movement handling in FirstPersonNavigationController
This commit is contained in:
@@ -13,10 +13,10 @@ import type {
|
||||
RuntimeControllerContext,
|
||||
RuntimeLocomotionState
|
||||
} from "./navigation-controller";
|
||||
import type { RuntimePlayerMovement } from "./runtime-scene-build";
|
||||
|
||||
const LOOK_SENSITIVITY = 0.0022;
|
||||
const GAMEPAD_LOOK_SPEED = 2.4;
|
||||
const MOVE_SPEED = 4.5;
|
||||
const GRAVITY = 22;
|
||||
const MAX_PITCH_RADIANS = Math.PI * 0.48;
|
||||
|
||||
@@ -35,6 +35,20 @@ function toEyePosition(feetPosition: Vec3, eyeHeight: number): Vec3 {
|
||||
};
|
||||
}
|
||||
|
||||
function cloneRuntimePlayerMovement(
|
||||
movement: RuntimePlayerMovement
|
||||
): RuntimePlayerMovement {
|
||||
return {
|
||||
templateKind: movement.templateKind,
|
||||
moveSpeed: movement.moveSpeed,
|
||||
capabilities: {
|
||||
jump: movement.capabilities.jump,
|
||||
sprint: movement.capabilities.sprint,
|
||||
crouch: movement.capabilities.crouch
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function shouldAutoCapturePointerLockOnActivate(): boolean {
|
||||
if (typeof navigator === "undefined") {
|
||||
return true;
|
||||
@@ -189,13 +203,15 @@ export class FirstPersonNavigationController implements NavigationController {
|
||||
return;
|
||||
}
|
||||
|
||||
const playerShape = this.context.getRuntimeScene().playerCollider;
|
||||
const runtimeScene = this.context.getRuntimeScene();
|
||||
const playerShape = runtimeScene.playerCollider;
|
||||
const playerMovement = runtimeScene.playerMovement;
|
||||
const lookInput = resolvePlayerStartLookInput(
|
||||
this.context.getRuntimeScene().playerInputBindings
|
||||
runtimeScene.playerInputBindings
|
||||
);
|
||||
const inputState = resolvePlayerStartMovementActions(
|
||||
this.pressedKeys,
|
||||
this.context.getRuntimeScene().playerInputBindings
|
||||
runtimeScene.playerInputBindings
|
||||
);
|
||||
|
||||
if (lookInput.horizontal !== 0 || lookInput.vertical !== 0) {
|
||||
@@ -218,7 +234,7 @@ export class FirstPersonNavigationController implements NavigationController {
|
||||
if (inputLength > 0) {
|
||||
const normalizedInputX = inputX / inputLength;
|
||||
const normalizedInputZ = inputZ / inputLength;
|
||||
const moveDistance = MOVE_SPEED * dt;
|
||||
const moveDistance = playerMovement.moveSpeed * dt;
|
||||
|
||||
this.forwardVector.set(
|
||||
Math.sin(this.yawRadians),
|
||||
@@ -358,6 +374,9 @@ export class FirstPersonNavigationController implements NavigationController {
|
||||
eyePosition,
|
||||
grounded: this.grounded,
|
||||
locomotionState: this.locomotionState,
|
||||
movement: cloneRuntimePlayerMovement(
|
||||
this.context.getRuntimeScene().playerMovement
|
||||
),
|
||||
inWaterVolume: this.inWaterVolume,
|
||||
cameraSubmerged: cameraVolumeState.inWater,
|
||||
inFogVolume: this.inFogVolume,
|
||||
|
||||
Reference in New Issue
Block a user