I built a racing sim that runs in a browser tab

2026-11-13来源 dev.toEnglish

im racing usually starts with a big download and a decent PC. I wanted one you could open from a link.

That's LibreCorsa. It runs in the browser and it's open source. There are 2026-style open-wheelers, GT3s, a prototype and a road car, more than a dozen circuits, AI races, ghosts, rain and online races. You can drive it with a keyboard, a gamepad, a touch screen or a steering wheel. If you'd rather watch first, there's a 40-second trailer.

I'm building it on my own. It's a little over 800 commits since mid-October, and a few parts turned out much more interesting than I expected.

500 Hz, whatever your screen does

If the physics depends on frame rate, a 144 Hz monitor gives you more grip than a 60 Hz laptop. In a racing game you notice that within a lap.

So the simulation moves in fixed 2 ms steps (500 Hz), and each step splits into four 0.5 ms substeps for the tyres and suspension. The screen renders at whatever rate it can, and the sim catches up in whole steps. Stripped down, it's the classic loop:

const STEP = 0.002; // 500 Hz let acc = 0; function frame(dt: number) { acc = Math.min(acc + dt, 0.1); // a long hitch doesn't turn into a death spiral while (acc >= STEP) { sim.step(STEP); // four 0.5 ms substeps inside acc -= STEP; } render(sim.state); } 

One detail I didn't see coming: your steering input arrives once per frame, but a frame can run three physics steps or none. So each change is spread across the steps that frame actually runs, the way a real wheel turns, instead of landing all at once on the first one.

Does it hold? I run the same three-second launch at 30, 60, 144 and 240 fps, and the car ends within 0.3 km/h and 0.2 m every time. The test suite runs it at two frame rates and fails if they disagree.

Tyres are most of the work

The tyre is a Pacejka-style slip curve with combined slip, load sensitivity and carcass relaxation. Then it gets complicated. Each tyre tracks inner, middle and outer temperatures, and those move the grip window. Pressure follows the ideal gas law and changes how stiff the carcass is. Tyres wear. In the rain the road carries a water film that builds and drains, the cars dry the racing line first, and wets clear water up to a depth before they aquaplane.

The ground under the tyre mattered more than I thought. With one ground sample per wheel, a kerb's step edge gets hit at a point instead of rolled over. Each tyre now takes five samples across its contact patch (centre, both ends, both edges) and folds them into one height and slope.

There are two vehicle models. The default car has a planar chassis with sprung heave, pitch and roll. The others run a full 6-DOF rigid body with suspension built from hardpoints, so camber, bump steer and anti-dive come out of the geometry instead of numbers I typed in. On those cars the steering torque is the front tyres' moment about the kingpin axes. That's what a wheel actually pushes back with.

Checking it against a real car

When you're the only tester, tuning by feel only goes so far. I have about 24 minutes of MoTeC logs from a real GT3 Evo at Valencia, so the sim's GT3 runs the same manoeuvres: sustained cornering, braking and full-throttle acceleration at each speed, plus the gearing and the understeer gradient.

Right now every point sits within −13 % to +17 % of the logs. Not great, not terrible. The validation page is generated from the sim's own code with one command, and it has a section for where the sim is wrong. CI fails the build if a point leaves its band, and the last physics rework pushed one of them out.

Steering wheels in a browser

Steering, pedals and buttons were the easy part. If your OS sees the wheel as a game controller, the Gamepad API sees it too.

Force feedback is not easy. Chrome and Edge have WebHID, so a page can talk to a wheel base directly, and bases that speak the standard USB HID PID force-feedback reports can be driven with nothing installed. Plenty of popular wheels don't speak it. Logitech's force feedback is proprietary, for one. For those there's a small Windows helper that talks DirectInput and listens on localhost.

Where it stands: the one wheel I've tested, a MOZA R9, connects and steers over WebHID, but I haven't confirmed force feedback on it yet. It's marked experimental. If you have a different wheel, there's a wheel report form on GitHub and I'd love to see it filled in.

Racing people without paying for servers

Multiplayer is peer-to-peer over WebRTC. You host a room and send the link, or a friend types a 6-character code. If you want zero servers, there's a manual offer/answer copy-paste with nothing in between. Two tabs on the same machine can also race each other, which made testing a lot less lonely.

On the live site a small Cloudflare Worker does the rest. It pairs players, hands out relay servers for networks that block a direct link, keeps the leaderboards, and starts an open race every 20 minutes on the week's circuit and car. If nobody shows up, you race the AI.

Half a gigabyte, hosted for free

The game is a static Next.js export on Cloudflare, which is great until a circuit model is bigger than the asset store's 25 MiB per-file limit. Those files sit in an R2 bucket instead. The Worker answers any path that has no static file from R2, at the same URL, so the game never knows.

Car models are meshopt-compressed when the site builds. The default car drops from 16 MB to 6 MB, which matters when the first thing a player sees is a loading screen.

Hosting costs nothing at the moment. I'd like to keep it that way.

Licences, and why the repo is small

The code is MIT. The 3D models and sounds come from a lot of different authors with their own licences, and some are non-commercial. So LibreCorsa has no ads and nothing for sale. There's a Buy Me a Coffee link and that's it.

It's also why the repository carries only one circuit, RISE Motordrome, and the 2026 prototype car. Everything else is served on the site for playing there. A clone still gives you a working game with those two, and there's a guide for porting your own cars locally.

What's rough

VR works through WebXR, but it's a work in progress. Force feedback in the browser is experimental. Circuits converted from community 3D models have less trustworthy surfaces than the hand-built ones. And the handling is tuned by one person, which is exactly why I want other people driving it.

Try it

It's at librecorsa.org, and the code is on GitHub. Tell me how it drives, especially on a gamepad or a wheel I don't have, and how it runs on your machine.

LibreCorsa is an independent fan project. It isn't affiliated with Formula 1, the FIA, or any team or circuit.

原文:https://www.a8q9.cn/en/article/i-built-a-racing-sim-that-runs-in-a-browser-tab-6632d9.html

相关文章