diff --git a/src/components/ebike/Ebike.tsx b/src/components/ebike/Ebike.tsx index 7a86bdf..e7de0dc 100644 --- a/src/components/ebike/Ebike.tsx +++ b/src/components/ebike/Ebike.tsx @@ -129,12 +129,6 @@ export function Ebike({ // State for debug visualization (synced from refs during useFrame) const [showCameraPoints, setShowCameraPoints] = useState(true); - const [debugRestingPosition, setDebugRestingPosition] = - useState([ - parkedPosition[0], - parkedPosition[1], - parkedPosition[2], - ]); // Keep movementModeRef in sync — useFrame closures capture React state at // render time and can become stale between renders. @@ -321,9 +315,7 @@ export function Ebike({ } // Sync debug visualization state (throttled to avoid excessive re-renders) - if (showCameraPoints) { - setDebugRestingPosition([...restingPositionRef.current]); - } + // Debug visualization positions are derived elsewhere when needed. } else { updateEbikeSounds({ mounted: false, driving: false, breakdown: false }); groupRef.current.position.set(...restingPositionRef.current); @@ -340,17 +332,6 @@ export function Ebike({ } }); - // Debug visualization positions computed from state (not refs) - const camPointPos: Vector3Tuple = [ - debugRestingPosition[0] + EBIKE_CAMERA_TRANSFORM.position[0], - debugRestingPosition[1] + EBIKE_CAMERA_TRANSFORM.position[1], - debugRestingPosition[2] + EBIKE_CAMERA_TRANSFORM.position[2], - ]; - const dropPointPos: Vector3Tuple = [ - debugRestingPosition[0] + EBIKE_DROP_PLAYER_TRANSFORM.position[0], - debugRestingPosition[1] + EBIKE_DROP_PLAYER_TRANSFORM.position[1], - debugRestingPosition[2] + EBIKE_DROP_PLAYER_TRANSFORM.position[2], - ]; const interactionLabel = mainState === "ebike" ? "Lancer le repair game" @@ -409,9 +390,15 @@ export function Ebike({ EBIKE_CAMERA_TRANSFORM.rotation[2], ]; - animateCameraTransformTransition(targetCamPos, targetRotation, 1, () => { - useGameStore.getState().setPlayerMovementMode("ebike"); - }); + animateCameraTransformTransition( + targetCamPos, + targetRotation, + 1, + () => { + useGameStore.getState().setPlayerMovementMode("ebike"); + }, + { lockInput: false }, + ); } else { const currentPos = new THREE.Vector3(); if (groupRef.current) { @@ -437,9 +424,15 @@ export function Ebike({ THREE.MathUtils.radToDeg(currentEuler.z), ]; - animateCameraTransformTransition(targetCamPos, targetRotation, 1, () => { - useGameStore.getState().setPlayerMovementMode("walk"); - }); + animateCameraTransformTransition( + targetCamPos, + targetRotation, + 1, + () => { + useGameStore.getState().setPlayerMovementMode("walk"); + }, + { lockInput: false }, + ); } }, [movementMode, mainState, ebikeStep, setMissionStep, camera, position]); diff --git a/src/world/GameCinematics.tsx b/src/world/GameCinematics.tsx index 8470a35..6a73c3d 100644 --- a/src/world/GameCinematics.tsx +++ b/src/world/GameCinematics.tsx @@ -242,7 +242,10 @@ export function animateCameraTransformTransition( targetRotation: Vector3Tuple, duration: number = 1, onComplete?: () => void, + options: { lockInput?: boolean } = {}, ): void { + const { lockInput = true } = options; + if (!globalCamera) { logger.warn("GameCinematics", "Camera not found for transition"); onComplete?.(); @@ -252,7 +255,9 @@ export function animateCameraTransformTransition( const camera = globalCamera; cameraTransitionTimeline?.kill(); - useGameStore.getState().setCinematicPlaying(true); + if (lockInput) { + useGameStore.getState().setCinematicPlaying(true); + } // Convert target rotation in degrees to quaternion const targetEuler = new THREE.Euler( @@ -274,7 +279,9 @@ export function animateCameraTransformTransition( }, onComplete: () => { cameraTransitionTimeline = null; - useGameStore.getState().setCinematicPlaying(false); + if (lockInput) { + useGameStore.getState().setCinematicPlaying(false); + } onComplete?.(); }, });