From 566a684bfacfe67f9da2fb1ac5d35407c8141848 Mon Sep 17 00:00:00 2001 From: neru Date: Mon, 1 Jun 2026 15:35:56 -0300 Subject: [PATCH] fix?: try to fix camera snapping to rnd angles --- src/app/fear/scene-components/player.tsx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/app/fear/scene-components/player.tsx b/src/app/fear/scene-components/player.tsx index be82de2..54d6c7a 100644 --- a/src/app/fear/scene-components/player.tsx +++ b/src/app/fear/scene-components/player.tsx @@ -70,11 +70,23 @@ export default function Player() { camera.position.x += direction.x; camera.position.z += direction.z; + const minX = -fearState.currentWidth / 2 + FEAR_SETTINGS.WALL_BUFFER; + const maxX = fearState.currentWidth / 2 - FEAR_SETTINGS.WALL_BUFFER; + + if (camera.position.x < minX) camera.position.x = minX; + if (camera.position.x > maxX) camera.position.x = maxX; + + let bobX = 0; + let bobY = 0; + const isMoving = controls.Forward || controls.Backward || controls.Left || controls.Right; if (isMoving) { movementCounter.current += delta * 10; - camera.position.y = FEAR_SETTINGS.PLAYER_HEIGHT + Math.sin(movementCounter.current) * 0.08; - camera.position.x += Math.cos(movementCounter.current / 2) * 0.006; + bobY = Math.sin(movementCounter.current) * 0.08; + bobX = Math.cos(movementCounter.current / 2) * 0.006; + + camera.position.y = FEAR_SETTINGS.PLAYER_HEIGHT + bobY; + camera.position.addScaledVector(side, bobX); } else { const breatheTime = state.clock.elapsedTime * 1.5; const breatheY = FEAR_SETTINGS.PLAYER_HEIGHT + Math.sin(breatheTime) * 0.1; @@ -95,12 +107,6 @@ export default function Player() { flashlightRef.current.intensity = FEAR_SETTINGS.FLASHLIGHT_INTENSITY_BASE + Math.sin(state.clock.elapsedTime * 30) * 0.3; } - const minX = -fearState.currentWidth / 2 + FEAR_SETTINGS.WALL_BUFFER; - const maxX = fearState.currentWidth / 2 - FEAR_SETTINGS.WALL_BUFFER; - - if (camera.position.x < minX) camera.position.x = minX; - if (camera.position.x > maxX) camera.position.x = maxX; - const length = FEAR_SETTINGS.HALLWAY_LENGTH; const absoluteZ = -camera.position.z; const rawSegmentIndex = Math.floor(absoluteZ / length); @@ -139,4 +145,4 @@ export default function Player() { /> ); -} +} \ No newline at end of file