From b1bafdb4ceacf5d06d866394e4c7e033b2eae534 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 11 Apr 2026 18:00:48 +0200 Subject: [PATCH] Update third-person navigation controller to use player movement speed and clone runtime player movement --- .../third-person-navigation-controller.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/runtime-three/third-person-navigation-controller.ts b/src/runtime-three/third-person-navigation-controller.ts index 10378cbe..1389ceb9 100644 --- a/src/runtime-three/third-person-navigation-controller.ts +++ b/src/runtime-three/third-person-navigation-controller.ts @@ -13,10 +13,10 @@ import type { RuntimeControllerContext, RuntimeLocomotionState } from "./navigation-controller"; +import type { RuntimePlayerMovement } from "./runtime-scene-build"; const LOOK_SENSITIVITY = 0.008; const GAMEPAD_LOOK_SPEED = 2.8; -const MOVE_SPEED = 4.5; const GRAVITY = 22; const DEFAULT_CAMERA_DISTANCE = 4.5; const MIN_CAMERA_DISTANCE = 1.5; @@ -49,6 +49,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 + } + }; +} + export class ThirdPersonNavigationController implements NavigationController { readonly id = "thirdPerson" as const; @@ -161,13 +175,15 @@ export class ThirdPersonNavigationController 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) { @@ -191,7 +207,7 @@ export class ThirdPersonNavigationController 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.cameraYawRadians), @@ -345,6 +361,9 @@ export class ThirdPersonNavigationController implements NavigationController { eyePosition, grounded: this.grounded, locomotionState: this.locomotionState, + movement: cloneRuntimePlayerMovement( + this.context.getRuntimeScene().playerMovement + ), inWaterVolume: this.inWaterVolume, cameraSubmerged: cameraVolumeState.inWater, inFogVolume: this.inFogVolume,