threejs-first-person-bvh-walk
Skill4 starsChanged 19 days agoMITView on GitHub
Lands a character on a landmark and lets the visitor walk it in first person in three.js — a floating-down arrival, the camera slipping from a three-quarter view into her eyes, WASD + pointer-lock look, Shift run, E use, V over-shoulder, Esc leave, a touch thumb stick, a levitation lift between floors, interiors lit by the nearest lamps — with a three-mesh-bvh capsule controller that never gets stuck (footprint ground, sideways-only capsule push-out, glancing along edges, climb-back for every drop, a breadcrumb unstick) and a headless flood-fill + random-wander soak test that proves it. Use when the user wants first-person or third-person walking inside a GLB building or island, WASD movement with collision, a character controller, pointer lock, or says the player gets stuck on walls, balconies, stairs, rails or seams.
In this repository30 other files it gives its agents.
- threejs-blender-glb-pipelineSkill
- threejs-boat-buoyancy-steeringSkill
- threejs-camera-guided-tourSkill
- threejs-cinematic-loading-screenSkill
- threejs-day-cycle-lightingSkill
- threejs-dreamy-glass-hudSkill
- threejs-fish-school-boidsSkill
- threejs-floating-island-landmarkSkill
- threejs-ghibli-night-modeSkill
- threejs-ghibli-sky-cloudsSkill
- threejs-ghibli-toon-shadingSkill
- threejs-glb-realism-pipelineSkill
- threejs-gpu-butterfliesSkill
- threejs-headless-visual-verificationSkill
- threejs-hud-objective-markersSkill
- threejs-night-lights-lanternsSkill
- threejs-object-interactionSkill
- threejs-open-world-streamingSkill
- threejs-postprocessing-anime-gradeSkill
- threejs-procedural-vegetationSkill
- threejs-shell-fur-renderingSkill
- threejs-skeletonless-character-animationSkill
- threejs-stylized-rock-materialSkill
- threejs-webaudio-generative-soundtrackSkill
- threejs-webgl-performance-profilingSkill
- threejs-webgl-rain-effectSkill
- threejs-webgl-realistic-waterSkill
- threejs-webgl-underwater-effectSkill
- threejs-webgl-wake-simulationSkill
- threejs-webgl-waterfall-effectSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 92
Run it headless, in its own BLENDER_USER_RESOURCES profile so the user's Blender is untouched.
- Very specific: line 93
Use the makehuman_system_assets and dress01 packs.
- Very specific: line 94
Use the game_engine rig.
- Very specific: line 97
Size: after gltf-transform optimize (Draco, WebP at 1024) the character with all four clips is about 0.7 MB.
- Distinctive: line 104
Keep the eye's clearcoat low (≈ .35 at roughness .3).
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
First-person walk on a landmark, with a capsule that never sticks
Click the landmark (or press a key) and {{character}} floats down onto the arrival spot; the
camera watches from a three-quarter view, then slides into her eyes. You walk the whole
thing — terraces, stairs, balconies, furnished rooms — and nothing ever traps you. Proven on
a Laputa-style floating castle (≈120k tris, six rooms, a lift to an observatory), where a
30-visitor soak test went from 110 lock checkpoints to 0.
Stack: three.js r186, three-mesh-bvh 0.9.1 (build/index.module.js, imports bare three
so it resolves through the import map; +esm pulls a second copy of three), a landmark GLB
from a Blender generator (threejs-floating-island-landmark, threejs-blender-glb-pipeline).
When to use
- Walking inside or around a GLB building, castle, island or interior.
- A character controller over arbitrary triangle soup (no navmesh, no physics engine).
- The player sticks at walls, balcony edges, rails, seams between meshes or pits.
Paste-ready prompt
Let me visit
{{landmark}}on foot. Clicking it (or{{key}}) floats{{character}}down onto{{arrival spot}}; the camera watches from a three-quarter view, then slides into her eyes. WASD/arrows walk (arrows left/right turn), mouse looks with pointer lock (drag as a fallback), Shift runs, E uses, V toggles an over-shoulder view with a walk cycle, Esc leaves (the first Esc only releases the mouse). On touch: a thumb stick that appears under the left thumb, the right half looks, E and view buttons.Make the building enterable in the generator: hollow shell, a separate interior material, archways, a
walk.jsonwith spawn, lamps[pos, rgb, intensity, range], things to use and room boxes.Collision: one three-mesh-bvh over every static mesh in the landmark's frame; a capsule pushed out sideways; ground = highest floor under a small footprint; sub-steps ≤ 12 cm; at an edge retry the step turned along it; every drop ≤
{{drop}}must be climbable back (outdoors, hop ≤{{climb}}onto ≥ 1 m of level ground or her own trail); a breadcrumb trail leads her back if she presses on and goes nowhere for 0.5 s. Prove it headless: flood-fill reachability from the spawn and a 30 × 90 s random-wander soak with lock checks.
Implementation
Frame and flow
- The player lives in the landmark's local frame (
walk.pin model metres), so its bob and spin carry her. Camera =isle.localToWorld(eye), quaternion = isle world quaternion × local yaw/pitch (Euler YXZ). - Phases:
descend(from 26 m, eased(1−u)^2.3, a slow turn, arms out) →enter(1.7 s lerp/slerp from the watch pose into the eye, fov to 68, hide her at 72 %) →walk↔float(lift) →endWalkflies back to the orbit. - A capture-phase key/pointer guard (
addEventListener(…, true)+stopImmediatePropagation) silences the rest of the scene's shortcuts while walking.
Numbers that worked (WALK)
eye 1.5, radius .34, step .56, drop 1.25, climb 1.32, speed 2.7, run 5.4, fov 68.
Stair treads must be deeper than the radius, wall probes start above step height.
Controller (references/walk-controller.js)
- BVH: merge every static mesh (skip leaves, water, banners, sprites, moving parts),
transformed by
inv(isle.matrixWorld) · mesh.matrixWorld, positions + index only; buildMeshBVHonce on the first walk. - Floor: one ray from
p.y + stepdown; accept only|n.y| > .6. - Ground: the highest floor under a footprint (centre + 5 toes at .24 m), needing two hits (one stray toe on a ledge is not standing). Seams and hand-width gaps vanish.
- Body: a capsule segment from
y + step + .6rtoy + 1.62 − r;bvh.shapecastwithtri.closestPointToSegment; push sideways only byr − d, 3 passes. Dead-centre on a face → push along the face normal. - Step: try the move; if the capsule ate more than half of it, try a climb; then try the
step turned by
[0, ±.5, ±1, ±1.35]rad, scaled bymax(0, cos), so rails and cliffs are glanced along. Accept only if ground exists, is ≤dropbelow, and a step up has room for the body at the new height (walkFits). - Climb-back: outdoors only (never in rooms or on roofs): a ledge
step < h ≤ climbahead is hopped onto if the landing is solid (8 points at .45 m all within .1 m) or on her own trail, and the body fits there. - Sub-steps ≤ 12 cm so a thin rail can't be stepped through.
- Trail + unstick: a crumb every .35 m (max 60).
stuckTgrows while input > .2 but speed < 25 % of intended; after .5 s walk back toward the nearest crumb that lies roughly in the wanted direction (|dy| ≤ climb). Clear the trail after a lift ride.
Interiors and lift
- On interior materials only, scale sun ×.06, hemisphere ×.1, ambient ×.14,
envMapIntensity.12, and add the four lamps nearest the eye (view space) afterlights_fragment_end; outdoor shaders pay nothing. The same patch on the character with an eased 0…1 factor as she walks in and out. - Lift: a glowing circle under an oculus; E floats her up over ~4 s (smoothstep) onto a glass lens that counts as floor. Hide her and damp the additive beam when the eye is inside it.
A realistic character (optional)
- Source: a primitive toy figure reads as cartoon up close. For a realistic one, generate a CC0 human with
MakeHuman's Blender add-on MPFB:
- Run it headless, in its own
BLENDER_USER_RESOURCESprofile so the user's Blender is untouched. - Use the
makehuman_system_assetsanddress01packs. - Use the
game_enginerig.
- Run it headless, in its own
- Actions: key walk, run, idle and float procedurally as armature-space rotations converted to bone-local
(
R⁻¹·Q·R), and export them as NLA tracks. - Size: after
gltf-transform optimize(Draco, WebP at 1024) the character with all four clips is about 0.7 MB. - Runtime: an
AnimationMixerplays every clip and cross-fades their weights on speed (1 − exp(−7·dt); run above 1.3× walk speed). WalktimeScale = speed/1.35(clamped .6–2.2) and runspeed/4.4(.7–1.4), so the feet don't skate. Keep the toy as the load-failure fallback. - Pitfalls:
- Apply and remove MPFB's shape keys before export. Otherwise the body ships as about 5 MB of morph targets.
- The high-poly eye's cornea shell has alpha 0. Use
alphaTest.5, or the eye renders white. - Keep the eye's clearcoat low (≈ .35 at roughness .3). A mirror-glossy eye reflects the sky.
- The exporter marks every material
BLEND. Set skin, dress and shoes opaque, and hair toalphaTest. - The rest pose is an A-pose with elbows bent about 46°. Leave about 14° of arm clearance, or the hands poke through a flared skirt.
Headless soak test (references/walk-soak-test.mjs)
Expose walkMove, walkGround, walk on a debug handle. Flood-fill: from the spawn,
8 headings × 0.3 s of real walkMove, bucket to 1 m cells, BFS. Hug-and-return: from
every cell walk 1.6 s into whatever is there, then try to walk back. Soak: 30 visitors ×
90 s, random heading changes every 1–4 s, a lock check every 5 s (moved < .3 m while pressing).
Diff reachable sets between versions: a stricter rule once cut off the lower lawns.
Pitfalls
- The four stuck causes: (1) a single centre floor ray fell through seams between meshes and refused the move; (2) the edge refusal cancelled the whole move, so walking into a balcony edge at an angle stopped dead; (3) drop 1.25 but step .56 — every gutter or pit behind a parapet was a trap; (4) mid-fall step-ups landed on rail tops. Ray-fan walls also let the walker slip through arcaded parapets under the handrail.
- Unrestricted climbing lets her hop rail → coping → roof. Limit it to outdoor terraces below the main floor with a 1 m solid landing; then give parapets real gates so lower areas stay reachable.
- glTF materials from Blender are double-sided: a hollowed block can't rely on culling, and anything that ran through the solid now runs through the room — push it out by its full radius.
- New interior geometry built with a jittered helper shifted the generator's global rng and moved every plant: build it on its own rng and diff the placement JSON.
- First-person whiteout: the eye inside her own glow sprite / additive beam.
- Painted windows mean a telescope sees plaster: take its view from ~70 m out along the line.
- Dust motes need
gl_PointSizeclamped to 1–6 px, or they are bokeh balls at 1 m.
Verify
- Soak test: 0 lock checkpoints; reachable cells ≥ the previous version's (diff the sets).
- End-to-end in a headless page: arrive, real
keydownW events, ride the lift, walk the top. - Manual: walk diagonally into every balcony edge and parapet — she slides, never stops dead.
References
references/walk-controller.js— BVH build, floor/ground/collide/fits/solid/climb/step/trail/unstick/move.references/walk-soak-test.mjs— Playwright flood-fill + hug-and-return + random-wander soak.
Related skills
threejs-floating-island-landmark · threejs-blender-glb-pipeline · threejs-object-interaction · threejs-camera-guided-tour · threejs-skeletonless-character-animation · threejs-headless-visual-verification
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

