Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(city): third-person follow camera as the default exploration mode

[._.]/ Adam Eivyd4e050842a1f
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index c4573aa2c4..4d7b3942bd 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -51,7 +51,7 @@ import { cityDayMix } from './cityConstants';
import { CityPaletteProvider } from './CityPaletteContext';
import ErrorBoundary from '../ErrorBoundary';
-export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, healthMetrics, voiceState, aiActivity, productivityData, activityCalendar, goals, character, chronotype, memoryGraph, inboxDepth, jiraTickets, introspection, playback = false, photoMode, photoPresetId, photoDof, onPhotoCaptureReady, settings, playSfx, keysRef, dimmedAppIds, background, palette }) {
+export default function CityScene({ apps, agentMap, onBuildingClick, onToggleCameraView, cosStatus, reviewCounts, instances, backupStatus, cosTasks, healthMetrics, voiceState, aiActivity, productivityData, activityCalendar, goals, character, chronotype, memoryGraph, inboxDepth, jiraTickets, introspection, playback = false, photoMode, photoPresetId, photoDof, onPhotoCaptureReady, settings, playSfx, keysRef, dimmedAppIds, background, palette }) {
const [positions, setPositions] = useState(null);
const [proximityApp, setProximityApp] = useState(null);
const [transitioning, setTransitioning] = useState(false);
@@ -267,8 +267,11 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
positions={positions}
onBuildingProximity={handleBuildingProximity}
onBuildingClick={onBuildingClick}
+ onToggleCameraView={onToggleCameraView}
apps={apps}
active={explorationMode}
+ transitioning={transitioning}
+ cameraView={settings?.cameraView ?? 'third'}
/>
)}
{!explorationMode && !transitioning && !photoMode && (
diff --git a/client/src/components/city/CitySettingsPanel.jsx b/client/src/components/city/CitySettingsPanel.jsx
index 9cd1c9f565..1cbe2341f4 100644
--- a/client/src/components/city/CitySettingsPanel.jsx
+++ b/client/src/components/city/CitySettingsPanel.jsx
@@ -251,13 +251,37 @@ export default function CitySettingsPanel() {
{/* Exploration */}
<div>
- <SectionHeader title="EXPLORATION" subtitle="Street-level 3rd-person mode" />
+ <SectionHeader title="EXPLORATION" subtitle="Street-level character mode" />
<SettingToggle
label="DROP IN MODE"
value={settings.explorationMode}
onChange={(v) => updateSetting('explorationMode', v)}
description="Toggle street-level exploration (Tab)"
/>
+ <div className="mt-2">
+ <div className="grid grid-cols-2 gap-1.5">
+ {[
+ { key: 'third', label: 'CHARACTER' },
+ { key: 'first', label: 'FIRST PERSON' },
+ ].map(({ key, label }) => {
+ const active = (settings.cameraView ?? 'third') === key;
+ return (
+ <button
+ key={key}
+ onClick={() => updateSetting('cameraView', key)}
+ className={`font-pixel text-[9px] py-2 rounded border transition-all tracking-wide ${
+ active
+ ? 'bg-cyan-500/20 border-cyan-500/50 text-cyan-400 shadow-[0_0_8px_rgba(6,182,212,0.2)]'
+ : 'bg-gray-800/40 border-gray-700/40 text-gray-500 hover:border-gray-600 hover:text-gray-400'
+ }`}
+ >
+ {label}
+ </button>
+ );
+ })}
+ </div>
+ <div className="font-pixel text-[8px] text-gray-600 tracking-wide mt-1.5">CAMERA WHILE EXPLORING (V SWAPS IN-WORLD)</div>
+ </div>
</div>
<div className="border-t border-cyan-500/10" />
diff --git a/client/src/components/city/PlayerController.jsx b/client/src/components/city/PlayerController.jsx
index dd0ed1ba22..39a8592acf 100644
--- a/client/src/components/city/PlayerController.jsx
+++ b/client/src/components/city/PlayerController.jsx
@@ -1,6 +1,12 @@
import { useRef, useEffect, useCallback } from 'react';
import { useThree, useFrame } from '@react-three/fiber';
import * as THREE from 'three';
+import PlayerAvatar from './PlayerAvatar';
+import {
+ THIRD_PERSON, thirdPersonCamera, resolveBoomT,
+ dampFactor, dampAngle, moveFacing, avatarState, bankAngle,
+} from '../../utils/cityPlayerRig';
+import { isWalkable } from '../../utils/cityPlan';
const WALK_SPEED = 10;
const SPRINT_SPEED = 20;
@@ -11,40 +17,75 @@ const WORLD_BOUND = 180;
const EYE_HEIGHT = 1.6;
const MAX_CAMERA_HEIGHT = 160;
const BUILDING_FLYOVER_HEIGHT = 12; // above this the player clears rooftops, so skip collision
+const AIRBORNE_HEIGHT = EYE_HEIGHT + 0.6; // above this the avatar reads as flying (hover state)
const MOUSE_SENSITIVITY = 0.002;
const PITCH_LIMIT = Math.PI / 2 - 0.02;
+// Frame-loop scratch vectors (module scope — no per-frame allocation on the camera path).
+const _camTarget = new THREE.Vector3();
+const _lookTarget = new THREE.Vector3();
+
+// Exploration-mode player rig. One mutable rig object is the single source of truth for
+// the player's pose; both camera modes (and the third-person avatar) read from it:
+// - 'first' (V to toggle): the classic invisible first-person camera.
+// - 'third' (default): a damped follow camera behind a visible cyber-runner, with
+// building-aware boom shortening (cityPlayerRig.js owns all the math).
+// All original behavior is preserved: WASD/arrows, shift sprint, E/Q vertical, F interact,
+// pointer-lock mouselook, per-building cylinder collision below flyover height, world
+// bounds, spawn persistence. New: ground movement can't walk into the bay (the harbor
+// piers stay walkable — see isWalkable in cityPlan.js).
export default function PlayerController({
keysRef,
positions,
onBuildingProximity,
onBuildingClick,
+ onToggleCameraView,
apps,
active,
+ transitioning = false,
+ cameraView = 'third',
}) {
const { camera, gl } = useThree();
- const playerPos = useRef(new THREE.Vector3(0, 0, 0));
- const yawRef = useRef(0); // Facing toward city center (-Z direction)
- const pitchRef = useRef(0);
+ const rigRef = useRef({
+ position: new THREE.Vector3(0, EYE_HEIGHT, 0),
+ yaw: 0, // camera heading; forward is (-sin yaw, 0, -cos yaw)
+ pitch: 0,
+ moving: false,
+ sprinting: false,
+ airborne: false,
+ facing: 0, // the character's body heading (damped toward movement direction)
+ bank: 0, // lean into turns
+ state: 'idle',
+ });
const lastSpawnRef = useRef(null);
const pointerLockedRef = useRef(false);
const proximityAppRef = useRef(null);
+ // Damped third-person aim point — lags the true lookAt so the aim stays smooth.
+ const lookRef = useRef(new THREE.Vector3());
+ const lookInitRef = useRef(false);
+
+ // Re-snap the aim whenever the camera mode flips (V) so the lerp never starts
+ // from a stale aim point left by the previous third-person stint.
+ useEffect(() => { lookInitRef.current = false; }, [cameraView]);
// Initialize spawn position
useEffect(() => {
if (!active) return;
+ const rig = rigRef.current;
if (lastSpawnRef.current) {
- playerPos.current.copy(lastSpawnRef.current);
+ rig.position.copy(lastSpawnRef.current);
} else {
// Spawn behind front row, facing downtown
let maxZ = 0;
positions?.forEach((pos) => {
if (pos.z > maxZ) maxZ = pos.z;
});
- playerPos.current.set(0, EYE_HEIGHT, maxZ + 8);
- yawRef.current = 0; // Forward = (0, 0, -1), facing toward city center
- pitchRef.current = 0;
+ rig.position.set(0, EYE_HEIGHT, maxZ + 8);
+ rig.yaw = 0; // Forward = (0, 0, -1), facing toward city center
+ rig.pitch = 0;
+ rig.facing = 0;
}
+ lookInitRef.current = false;
}, [active, positions]);
// Pointer lock management
@@ -59,9 +100,10 @@ export default function PlayerController({
const handleMouseMove = useCallback((e) => {
if (!pointerLockedRef.current || !active) return;
- yawRef.current -= e.movementX * MOUSE_SENSITIVITY;
- pitchRef.current -= e.movementY * MOUSE_SENSITIVITY;
- pitchRef.current = Math.max(-PITCH_LIMIT, Math.min(PITCH_LIMIT, pitchRef.current));
+ const rig = rigRef.current;
+ rig.yaw -= e.movementX * MOUSE_SENSITIVITY;
+ rig.pitch -= e.movementY * MOUSE_SENSITIVITY;
+ rig.pitch = Math.max(-PITCH_LIMIT, Math.min(PITCH_LIMIT, rig.pitch));
}, [active]);
useEffect(() => {
@@ -71,7 +113,7 @@ export default function PlayerController({
document.exitPointerLock?.();
}
// Save last position for re-entry
- lastSpawnRef.current = playerPos.current.clone();
+ lastSpawnRef.current = rigRef.current.position.clone();
return;
}
@@ -90,20 +132,25 @@ export default function PlayerController({
};
}, [active, gl.domElement, handleClick, handlePointerLockChange, handleMouseMove]);
- // F key for building interaction. E is vertical up in free-look controls.
+ // F interacts with the nearby building; V swaps first/third person. (E is vertical-up
+ // in the free-look controls, so neither shadows movement.)
useEffect(() => {
if (!active) return;
const handleKeyDown = (e) => {
- if (e.key.toLowerCase() === 'f' && proximityAppRef.current) {
+ const key = e.key.toLowerCase();
+ if (key === 'f' && proximityAppRef.current) {
onBuildingClick?.(proximityAppRef.current);
+ } else if (key === 'v') {
+ onToggleCameraView?.();
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
- }, [active, onBuildingClick]);
+ }, [active, onBuildingClick, onToggleCameraView]);
useFrame((_, delta) => {
if (!active) return;
+ const rig = rigRef.current;
const keys = keysRef.current;
const isSprinting = keys.has('shift');
@@ -111,14 +158,16 @@ export default function PlayerController({
const verticalSpeed = (isSprinting ? SPRINT_SPEED : VERTICAL_SPEED) * delta;
// Movement direction relative to camera yaw
- const forward = new THREE.Vector3(-Math.sin(yawRef.current), 0, -Math.cos(yawRef.current));
+ const forward = new THREE.Vector3(-Math.sin(rig.yaw), 0, -Math.cos(rig.yaw));
const right = new THREE.Vector3(-forward.z, 0, forward.x);
- const moveDir = new THREE.Vector3(0, 0, 0);
- if (keys.has('w') || keys.has('arrowup')) moveDir.add(forward);
- if (keys.has('s') || keys.has('arrowdown')) moveDir.sub(forward);
- if (keys.has('a') || keys.has('arrowleft')) moveDir.sub(right);
- if (keys.has('d') || keys.has('arrowright')) moveDir.add(right);
+ const forwardInput = (keys.has('w') || keys.has('arrowup') ? 1 : 0)
+ - (keys.has('s') || keys.has('arrowdown') ? 1 : 0);
+ const strafeInput = (keys.has('d') || keys.has('arrowright') ? 1 : 0)
+ - (keys.has('a') || keys.has('arrowleft') ? 1 : 0);
+ const moveDir = new THREE.Vector3(0, 0, 0)
+ .addScaledVector(forward, forwardInput)
+ .addScaledVector(right, strafeInput);
const hasHorizontal = moveDir.lengthSq() > 0;
const verticalDir = (keys.has('e') ? 1 : 0) - (keys.has('q') ? 1 : 0);
@@ -126,7 +175,7 @@ export default function PlayerController({
if (moving) {
if (hasHorizontal) moveDir.normalize().multiplyScalar(speed);
- const nextPos = playerPos.current.clone().add(moveDir);
+ const nextPos = rig.position.clone().add(moveDir);
nextPos.y += verticalDir * verticalSpeed;
// Collision detection with buildings — skipped above rooftop height so the
@@ -144,8 +193,8 @@ export default function PlayerController({
const dot = moveDir.x * nx + moveDir.z * nz;
if (dot < 0) {
// Moving toward building - project movement onto tangent
- nextPos.x = playerPos.current.x + (moveDir.x - dot * nx) * 0.8;
- nextPos.z = playerPos.current.z + (moveDir.z - dot * nz) * 0.8;
+ nextPos.x = rig.position.x + (moveDir.x - dot * nx) * 0.8;
+ nextPos.z = rig.position.z + (moveDir.z - dot * nz) * 0.8;
// Re-check distance after slide
const dx2 = nextPos.x - pos.x;
const dz2 = nextPos.z - pos.z;
@@ -155,6 +204,9 @@ export default function PlayerController({
}
}
});
+ // The bay is not walkable (the harbor piers are) — a grounded player stops
+ // at the shoreline instead of strolling onto open water.
+ if (!isWalkable(nextPos.x, nextPos.z)) blocked = true;
}
if (!blocked) {
@@ -162,17 +214,32 @@ export default function PlayerController({
nextPos.x = Math.max(-WORLD_BOUND, Math.min(WORLD_BOUND, nextPos.x));
nextPos.y = Math.max(EYE_HEIGHT, Math.min(MAX_CAMERA_HEIGHT, nextPos.y));
nextPos.z = Math.max(-WORLD_BOUND, Math.min(WORLD_BOUND, nextPos.z));
- playerPos.current.copy(nextPos);
+ rig.position.copy(nextPos);
}
}
+ // Pose classification for the avatar + facing/banking toward movement.
+ rig.moving = moving;
+ rig.sprinting = isSprinting && moving;
+ rig.airborne = rig.position.y > AIRBORNE_HEIGHT;
+ rig.state = avatarState(rig);
+ if (hasHorizontal) {
+ const target = moveFacing(rig.yaw, { forward: forwardInput, strafe: strafeInput });
+ const prevFacing = rig.facing;
+ rig.facing = dampAngle(rig.facing, target, dampFactor(10, delta));
+ const yawRate = delta > 0 ? (rig.facing - prevFacing) / delta : 0;
+ rig.bank += (bankAngle(yawRate) - rig.bank) * dampFactor(6, delta);
+ } else {
+ rig.bank += (0 - rig.bank) * dampFactor(6, delta);
+ }
+
// Building proximity detection
let nearestApp = null;
let nearestDist = PROXIMITY_DISTANCE;
positions?.forEach((pos, appId) => {
- const dx = playerPos.current.x - pos.x;
- const dy = playerPos.current.y - ((pos.height ?? 4) * 0.5);
- const dz = playerPos.current.z - pos.z;
+ const dx = rig.position.x - pos.x;
+ const dy = rig.position.y - ((pos.height ?? 4) * 0.5);
+ const dz = rig.position.z - pos.z;
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (dist < nearestDist) {
nearestDist = dist;
@@ -186,17 +253,46 @@ export default function PlayerController({
onBuildingProximity?.(nearestApp);
}
- camera.position.copy(playerPos.current);
- const lookDir = new THREE.Vector3(
- -Math.sin(yawRef.current) * Math.cos(pitchRef.current),
- Math.sin(pitchRef.current),
- -Math.cos(yawRef.current) * Math.cos(pitchRef.current),
- );
- const lookTarget = playerPos.current.clone().add(lookDir);
- camera.lookAt(lookTarget);
+ // Camera application. While CameraTransition flies the camera (exploration toggle),
+ // it is the sole camera writer — explicit gate instead of relying on mount order.
+ if (transitioning) return;
+
+ if (cameraView === 'first') {
+ camera.position.copy(rig.position);
+ const lookDir = new THREE.Vector3(
+ -Math.sin(rig.yaw) * Math.cos(rig.pitch),
+ Math.sin(rig.pitch),
+ -Math.cos(rig.yaw) * Math.cos(rig.pitch),
+ );
+ camera.lookAt(rig.position.clone().add(lookDir));
+ return;
+ }
+
+ // Third person: boom behind the camera yaw, shortened when it would clip a building,
+ // damped so the camera glides while the aim stays tight.
+ const desired = thirdPersonCamera({ pos: rig.position, yaw: rig.yaw, pitch: rig.pitch });
+ const anchor = { x: rig.position.x, y: rig.position.y + THIRD_PERSON.lookHeight, z: rig.position.z };
+ const t = resolveBoomT({ anchor, camera: desired.camera, buildings: positions?.values() });
+ const camX = anchor.x + (desired.camera.x - anchor.x) * t;
+ const camY = Math.max(THIRD_PERSON.minCamY, anchor.y + (desired.camera.y - anchor.y) * t);
+ const camZ = anchor.z + (desired.camera.z - anchor.z) * t;
+
+ if (!lookInitRef.current) {
+ // First third-person frame (mode entry): aim snaps so the camera doesn't swing
+ // through the scene; position still eases in from wherever the camera was.
+ lookRef.current.set(desired.lookAt.x, desired.lookAt.y, desired.lookAt.z);
+ lookInitRef.current = true;
+ }
+ const posFactor = dampFactor(THIRD_PERSON.camDampRate, delta);
+ const lookFactor = dampFactor(THIRD_PERSON.lookDampRate, delta);
+ camera.position.lerp(_camTarget.set(camX, camY, camZ), posFactor);
+ lookRef.current.lerp(_lookTarget.set(desired.lookAt.x, desired.lookAt.y, desired.lookAt.z), lookFactor);
+ camera.lookAt(lookRef.current);
});
if (!active) return null;
- return null;
+ // The visible character exists only in third person — first person stays the
+ // classic invisible camera (and can't self-clip).
+ return cameraView === 'third' ? <PlayerAvatar rigRef={rigRef} eyeHeight={EYE_HEIGHT} /> : null;
}
diff --git a/client/src/hooks/useCitySettings.js b/client/src/hooks/useCitySettings.js
index c3bc32185d..65cf438185 100644
--- a/client/src/hooks/useCitySettings.js
+++ b/client/src/hooks/useCitySettings.js
@@ -44,6 +44,7 @@ const DEFAULT_SETTINGS = {
qualityPreset: 'high',
timeOfDay: 'auto', // 'auto' follows the active theme's day/night mode; 'day'/'night' force it
explorationMode: false,
+ cameraView: 'third', // exploration camera: 'third' follows the cyber-runner; 'first' is classic FPS (V toggles)
...QUALITY_PRESETS.high,
};
diff --git a/client/src/pages/CyberCity.jsx b/client/src/pages/CyberCity.jsx
index c71cfc32a2..fdc40e42c2 100644
--- a/client/src/pages/CyberCity.jsx
+++ b/client/src/pages/CyberCity.jsx
@@ -100,6 +100,11 @@ function CyberCityInner() {
updateSetting('explorationMode', !settings?.explorationMode);
}, [updateSetting, settings?.explorationMode]);
+ // V (in exploration mode) swaps the follow-camera character view and first person.
+ const handleToggleCameraView = useCallback(() => {
+ updateSetting('cameraView', settings?.cameraView === 'first' ? 'third' : 'first');
+ }, [updateSetting, settings?.cameraView]);
+
const keysRef = useKeyboardControls(handleToggleExploration);
// Photo mode (roadmap 3.3): a cinematic capture mode with framing presets and a postcard
@@ -348,6 +353,7 @@ function CyberCityInner() {
apps={v('apps', apps)}
agentMap={v('agentMap', agentMap)}
onBuildingClick={handleBuildingClick}
+ onToggleCameraView={handleToggleCameraView}
cosStatus={v('cosStatus', cosStatus)}
reviewCounts={reviewCounts}
instances={instances}