Prakhar
All work

Case study

Car Simulator

A driving game that runs in a browser tab — a garage, real-feeling handling and engine audio, all in React Three Fiber.

Role
Solo — design, 3D and engineering
Timeline
May 2025 — now
Status
Live · physics rewrite in progress
Links
LiveCode
Stack
Next.jsReact Three FiberThree.jsRapierZustandWeb AudioglTF-Transform
The garage: a BMW i8 on a turntable, car stats panel and a row of owned cars
The garage. Pick a car and a track, check its handling, then drive.

The problem

I wanted a racing game I'd actually want to play, without an install. That means two hard things in a browser at once: it has to look like a game, with real car models, a proper garage and a track, and it has to feel like a car — weight, grip, drift — while running at 60 fps next to React.

Most browser driving demos pick one. They're either pretty scenes where the car slides around like a cursor, or physics toys made of boxes.

How it works

  Garage (React UI)  ──pick car + track──▶  Drive scene (R3F <Canvas>)
                                              ├─ Track  (GLB or procedural ring)
                                              ├─ Car    (GLB, auto-scaled)
                                              │    └─ useCarPhysics()  ← input: keyboard / touch / AI
                                              │         └─ telemetry ref ──▶ camera · HUD · engine audio
                                              └─ Multi-camera rig (follow / top / cockpit …)

The whole 3D layer is loaded client-side only (ssr: false) — Three.js can't render on the server, and the garage UI shouldn't wait for it.

Decisions that mattered

Driving the i8 on the race track past barriers
On the race track: follow cam, on-track detection and the HUD.

What broke — and the rewrite

Driving it honestly, the arcade model had real limits. I wrote them down before touching code:

  • Suspension was cosmetic — pitch and roll were springs chasing targets, not wheels touching anything.
  • Velocity was a single number plus a heading, so the car couldn't slide sideways. No real drift, no sideways shove from a crash.
  • Collisions were bounding spheres. Fence rails had spheres 85–184 units wide, so they were excluded — and the car drove straight through the fence.
  • The ground raycast didn't actually run every frame, so hills and off-track detection were quietly wrong.

Tech stack

  • Next.js + React 19 for the app shell and garage UI
  • React Three Fiber + drei for the scene, cameras and GLB loading
  • Rapier (rigid body + raycast vehicle) for physics — the live build still runs the earlier arcade model
  • Zustand for the one piece of global state (the chosen car), persisted career progress
  • Web Audio API for procedural engine, tyre and impact sounds
  • glTF-Transform to optimise downloaded models in the browser

What's next

A career mode is already structured — a ladder of fifteen rivals with story cards before and after each race — but the race loop itself is still a stub. Next up: tyre grip that scales with load (so weight transfer changes handling), a debug overlay to prove the physics rules hold, then time-trial ghosts and AI rivals on the same physics interface.

Next case study

Blogster

A Medium-style blogging platform with the API on the edge — Hono on Cloudflare Workers, Postgres through Prisma Accelerate.

ESC