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