Templates

Canyon Run

A multiplayer 3D game on Cloudflare Workers that you steer by tilting your phone.

Canyon Run's lobby: the canyon in 3D, and a QR code to scan with your phone.
Owner
Repository
canyon-run
Use Cases
  • Game
  • Realtime
  • Multiplayer
Stack
  • TanStack Start
  • Durable Objects
  • D1
  • Three.js
Credit
Inspired by a post from joshtriedcoding
License
MIT

Fly a rocket with your phone.

Open the game on a computer and scan the QR code: your phone becomes the controller. Tilt it to steer through a canyon that gets faster and narrower the further you fly. Play alone, or with two phones on one screen, and the best distances go on a leaderboard.

Tech stack

TechnologyPurpose
TanStack Start and React 19The screen, the phone controller and the server routes
Three.jsThe canyon, the obstacles and the rocket in 3D
Durable ObjectsOne room per game: WebSockets between the screen and phones
D1The leaderboard
Cloudflare WorkersServes the app and the WebSockets

How it works

  1. The screen opens a room, a Durable Object, and shows its QR code.
  2. The phone scans it and joins the room over a WebSocket. Tap to launch: the way you hold the phone becomes straight ahead.
  3. The phone sends its tilt many times a second. With no motion sensor, you drag on a ring instead.
  4. The room passes each move to the screen, which flies the rocket. The canyon is generated from a seed, so both players fly the same one.
  5. When a rocket crashes, the room checks the distance and saves it to D1. The table is created on the first request: there are no migrations to run.

How to deploy Canyon Run to your Cloudflare account

Conic lets you deploy to Cloudflare like you deploy to Vercel. The difference: everything runs on your own Cloudflare account, so you keep its prices, its limits and its data.

  1. Choose Deploy now and connect your Cloudflare account.
  2. Conic builds Canyon Run straight from its repository, with nothing to fork, and creates the Worker and every resource it needs, such as Durable Objects and D1 databases.
  3. Your app is live on a workers.dev URL. Add your own domain in Domains whenever you want.

When the template gets a new version, your project’s Overview shows New version available. Nothing changes until you choose Update. Every deployment keeps its build logs and runtime logs, and you can roll back to an earlier one in one click. See everything Conic does and its pricing.

Run it locally

git clone https://github.com/P-Essonam/canyon-run.git
cd canyon-run
pnpm install
pnpm dev

Customize it

FileWhat to change
src/game/canyon.tsThe canyon's shape, its speed and the obstacles
src/game/engine.tsThe 3D scene: colors, lights, camera and rocket
src/worker/room.tsThe room: players, start and end of a game
src/worker/scores.tsThe leaderboard
src/lib/i18n.tsThe texts, in English and French
src/shared/site.tsYour domain, for the canonical link and the share card

Your next project could be live on Cloudflare.

Connect your Cloudflare account and a repo. Start on the free plan and upgrade when you need more projects.