From 71610b318dc2ed7127b57205ee538c39798a0374 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 11 Apr 2026 22:15:51 +0200 Subject: [PATCH] Improve water surface height calculation in player locomotion --- src/runtime-three/player-locomotion.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/runtime-three/player-locomotion.ts b/src/runtime-three/player-locomotion.ts index 0658e739..3456b2b7 100644 --- a/src/runtime-three/player-locomotion.ts +++ b/src/runtime-three/player-locomotion.ts @@ -487,13 +487,16 @@ export function stepPlayerLocomotion( verticalVelocity = 0; jumpHoldRemainingMs = 0; } else if (currentSwimmableWater) { + const waterSurfaceHeight = + currentVolumeState.waterSurfaceHeight ?? + options.feetPosition.y + activeShape.eyeHeight; const targetFeetY = - currentVolumeState.waterSurfaceHeight + + waterSurfaceHeight + SWIM_HEAD_CLEARANCE - activeShape.eyeHeight; const currentHeadSubmerged = options.feetPosition.y + activeShape.eyeHeight < - currentVolumeState.waterSurfaceHeight; + waterSurfaceHeight; if (waterVerticalInput !== 0) { verticalVelocity = waterVerticalInput * swimVerticalSpeed; @@ -577,10 +580,13 @@ export function stepPlayerLocomotion( nextVolumeState.inWater && nextVolumeState.waterSurfaceHeight !== null && !nextShallowWater; + const nextWaterSurfaceHeight = + nextVolumeState.waterSurfaceHeight ?? + resolvedMotion.feetPosition.y + activeShape.eyeHeight; const headSubmerged = nextSwimmableWater && resolvedMotion.feetPosition.y + activeShape.eyeHeight < - nextVolumeState.waterSurfaceHeight; + nextWaterSurfaceHeight; const headBump = verticalDisplacement > 0 && resolvedMotion.collidedAxes.y &&