OpenPlayer.One
← All articles

Engineering

Building a Browser Game With Three.js

What it takes to turn a Three.js scene into a playable browser game, from the simulation loop to the first public build.

By OpenPlayer.One · · 4 min read

The first milestone for a Three.js game can fit in one room. A player moves a character around a table, collects a key, opens a door, and can immediately start again. The room can be made of boxes. It already asks for more of the code than a beautiful camera flythrough does. A wall must stop motion, pickup state must survive a stray click, and a restarted game has to begin with the same rules as the first run.

Three.js gives you the rendering pieces for a scene like this. Which systems you add around it depends on the game. Keeping a small playable room in the project while you build those systems gives you a dependable place to check each decision.

Keep the rules separate from the picture

A character mesh is a poor place to keep the entire truth about a character. Decide which part of the game owns position, collision, current action, and held items. Update those values through rules that can run independently of how a frame is drawn. The render layer can then pose the mesh, place the camera, and trigger a visual effect when the simulation reports a pickup.

This split is especially useful when a game starts to stutter. If you tie movement to frames, the same key press can move the player a different distance when a machine gets busy. Time-based movement works for many simple interactions. Use a fixed simulation step when stable physics or collision needs it, and put an upper bound on how many catch-up steps a single frame can run. Otherwise, one long pause can create a backlog that makes the next frame even later.

The first room gives you an honest test. Walk into the same corner at different frame rates, then open another tab for a few seconds and return. The player should remain where they expect, and a held-key state should clear when the game loses focus if the input system can miss a release.

Give loading and restart their own rules

A game typically passes through a few distinct states: loading the required assets, waiting for input, playing, and showing a result. Giving those states clear entry and exit points prevents common problems. In the room example, starting from the result screen should reset the key, restore the door, and make sure there is only one active input listener.

Decide what to do if a required asset fails. An explicit retry action is better than a loading indicator that can remain forever. Serve the game over HTTPS and test the production URL early. The deployed path can differ from the one you used during local development, which is enough to expose a broken asset URL or a misconfigured MIME type.

When you unload a level, remove its objects from the scene and dispose of the geometry, materials, and textures you created for it when they’re no longer shared. The scene graph and GPU resource ownership are separate concerns. Keep track of shared materials so one room does not dispose of a texture the next room still needs.

A small project can make this lifecycle visible with a few modules. Give input responsibility for producing actions such as move or interact. Let the level decide what those actions mean. Keep the renderer responsible for how state looks, while an ordinary HTML layer can handle pause and restart buttons. The boundaries should be recognizable when you trace a single action. If touching a key directly moves the door mesh and updates a menu, the next feature will have to discover all three effects before it can safely change the rules.

Resist adding systems that the slice does not use. One collision shape and one interaction point are enough to learn whether your architecture can carry the rest of the game. When the first asset arrives, use the glTF pipeline to preserve the same scale and pivot conventions from the placeholder test.

Let the first build answer a small question

The initial playtest can be simple. Send one person the public link and ask them to open the door without instructions. Watch when they realize the key matters, whether they try to walk around the table, and where they look after the door moves. Finish the test by asking them to restart. You will learn more about the game’s clarity from that run than from adding a second room first.

Only then start broadening the scope. Replace one placeholder character with a glTF model while preserving the collision and state rules. Add audio after the player’s start gesture. Try a smaller viewport. Given a specific problem, each change has a baseline you can compare against. The starter room is still useful after the game grows. It becomes a fast way to exercise the systems every larger level depends on, especially after a renderer, input, or asset pipeline update.

Sources

Have a playable browser game?

Share it with players through the OpenPlayer.One directory.

Submit your game

Keep reading

Engineering

WebGPU vs. WebGL for Browser Games

When WebGPU earns its place in an indie game, what WebGL 2 fallback actually means, and how to test both paths.

4 min read