diff --git a/src/game/cameraControl.js b/src/game/cameraControl.js index 22f5265..e896ebc 100644 --- a/src/game/cameraControl.js +++ b/src/game/cameraControl.js @@ -10,12 +10,12 @@ export const cameraInput = { let video; let faceDetector; -let smoothedX = 0.5; -// 🔥 TWEAK THESE FOR FEEL: -const SMOOTHING_FACTOR = 0.6; // Higher = more responsive/less lag (try 0.5 - 0.8) -const LEFT_THRESHOLD = 0.45; // Closer to 0.5 = smaller center zone -const RIGHT_THRESHOLD = 0.55; // Closer to 0.5 = smaller center zone +// 🔥 NARROW CENTER ZONE: +// 0.48 and 0.52 means the center is only 4% of the screen width. +// Adjust these if it's still too hard to trigger movement. +const LEFT_THRESHOLD = 0.48; +const RIGHT_THRESHOLD = 0.52; export async function initCameraControl() { if (cameraInput.active) return video; @@ -26,7 +26,11 @@ export async function initCameraControl() { video.muted = true; const stream = await navigator.mediaDevices.getUserMedia({ - video: { width: 160, height: 120, frameRate: 15 } + video: { + width: 160, + height: 120, + frameRate: { ideal: 20 } // Slightly higher for faster reaction + } }); video.srcObject = stream; @@ -57,23 +61,20 @@ function startDetectionLoop() { if (result.detections.length > 0) { const box = result.detections[0].boundingBox; - const centerX = box.originX + box.width / 2; - const normalizedX = centerX / 160; + // Calculate raw center point (0 to 1) + const rawX = (box.originX + box.width / 2) / 160; + + cameraInput.x = rawX; - // Snappier smoothing - smoothedX += (normalizedX - smoothedX) * SMOOTHING_FACTOR; - cameraInput.x = smoothedX; - - // Updated Logic with smaller center zone - if (smoothedX < LEFT_THRESHOLD) { - updateZones(false, true, 'right'); // Mirrored - } else if (smoothedX > RIGHT_THRESHOLD) { - updateZones(true, false, 'left'); // Mirrored + // INSTANT LOGIC (No smoothing) + if (rawX < LEFT_THRESHOLD) { + updateZones(false, true, 'right'); // Mirrored: Face on left of cam = move right + } else if (rawX > RIGHT_THRESHOLD) { + updateZones(true, false, 'left'); // Mirrored: Face on right of cam = move left } else { updateZones(false, false, 'center'); } } else { - // Snap to center if face is lost updateZones(false, false, 'center'); }