Ready. Set. Shake.
Turn your smartphone into a motion controller.
Race against friends or bots, right in your browser.
How to play · Features · Browser support · Connection help · Development
Motion Race is an open-source, accelerometer-powered party game. Put the race on a computer or another big screen, connect smartphones as controllers, and race by moving your phone. The more intense your controlled movement, the faster your racer advances.
No accounts, installation or dedicated game server. Just open the website and play.
| Host a game | Join a game | Try solo |
|---|---|---|
| Open the game on a big screen. | Open the game on your phone. | Open the game on any supported device. |
| Select room capacity, finish score and time limit, then create a room. | Scan the QR code, enter the eight-digit room code or paste the invitation link. | Choose one to three bot opponents. |
| Invite up to 16 racers and press Start race. | Grant motion access if prompted. Move your phone when the countdown ends. | Use motion on mobile, or Boost / Space on desktop. |
The host is a separate spectator screen, not an additional racer. A multiplayer round can start with one to 16 connected players, depending on the selected room capacity (4, 8, 12 or 16; default 8).
Keep a firm grip on your phone. Gentle, controlled movement is enough; avoid violent shaking or swinging the device.
| Motion-powered racing | Continuous accelerometer input with time-based scoring, common gravity compensation and capped speed. |
| Live multiplayer | Synchronized race tracks, countdown, scores, timer, winner announcements and rematches. |
| Easy invitations | QR codes, shareable URLs and eight-digit room codes such as 5824 1937. Separators are optional. |
| Flexible rounds | Choose room capacity (4, 8, 12 or 16). Finish targets of 60, 100 or 150 points; time limits of 30, 45 or 60 seconds. |
| Racing legends | Leave your nickname blank to receive a racing character or driver name, with automatic names kept distinct within a room. |
| Reconnect & resume | Automatic retries, manual recovery, and a 60-second identity reservation for previously confirmed players; unconfirmed abandoned joins release their lobby slot and replacing an unfinished handshake cannot extend its deadline. |
| Responsive interface | Live Race above the controller on narrow screens, centered result banners, dark and light themes, accessible expandable diagnostics. |
| Feedback | Sound, visual start/finish cues, vibration where the browser supports it, and best-effort screen wake lock. |
| Solo mode | Race against bots without connecting to a multiplayer service. |
| Platform | Controls | Feedback |
|---|---|---|
| Android — Chrome and compatible browsers | DeviceMotion sensor | Sound, visual cues, vibration when available |
| iOS / iPadOS — Safari | DeviceMotion sensor; permission may be required | Sound and visual cues; native switch haptics on supported versions |
| Desktop — Chrome, Edge, Firefox, Safari | Boost button or Space | Sound and visual cues |
These are target browsers, not an exhaustive compatibility certification. Device sensors and browser policies vary.
- Motion permission: sensor readings are detected automatically. If none arrive, the game displays a highlighted Enable motion or retry action. Use HTTPS on mobile.
- Vibration: iOS Safari does not provide the standard Vibration API. The native switch test checks direct system haptics only; it cannot trigger automatic race vibration. On Android, the vibration test reports whether the browser accepted the request, not whether the hardware physically vibrated.
- Scoring: acceleration is integrated over elapsed time at a fixed 200 ms scoring cadence, up to four points per tick. The same algorithm is used on both mobile platforms; physical sensor sensitivity can still differ.
- Diagnostics: expand Motion diagnostics to inspect the local sensor source, frequency, intensity and peak acceleration.
Multiplayer supports two transport modes. Select the mode when creating a room; invitations automatically identify the appropriate transport.
| Mode | How it connects |
|---|---|
| Compatibility room (default) | Encrypted game messages over MQTT and secure WebSockets using the public EMQX test broker. Useful when direct WebRTC connections fail. |
| WebRTC | PeerJS signaling and WebRTC data channels, with STUN and optional TURN relay configuration. Uncheck Compatibility room to use this mode. |
Rooms with more than eight racers use compact tracks and a slower state update cadence (400 ms during races) to reduce traffic. On narrow screens the controller's own track appears first. The relay coalesces queued same-phase snapshots, retaining the newest state without combining registration or resynchronization messages. Pending broker writes are bounded separately from the encryption queue, leaving capacity for control messages; stalled writes trigger transport recovery after a timeout. Large rooms have simulated regression coverage but real-network capacity is not guaranteed.
The eight-digit code is resolved through a live MQTT request/reply lookup, even for WebRTC rooms. Long invitation links and QR codes bypass that lookup. No permanent room directory is stored by the application.
Can't connect or reconnect?
- Keep the host tab open and visible, and refresh all devices to the same application version. Clients using the old four-player protocol cannot join newer rooms.
- Try a fresh Compatibility room. If the short code is unavailable, use the invitation link or QR code instead.
- In WebRTC mode, try Automatic or Direct on both devices, or configure a working custom TURN server. Relay-only mode requires custom TURN credentials.
- Expand Connection diagnostics on the host and controller to inspect signaling, ICE, candidate types, channel status or relay registration.
- If automatic attempts are exhausted or signaling terminates while offline, use Retry connection on the controller or Restore room connection on the host. A valid reservation preserves the player's identity and existing score, including across a rematch while reconnection is pending (scores reset for a new round); the race clock continues during interruptions.
Public signaling, TURN, CDN and MQTT services have no availability guarantee. Network filters, browser suspension or a closed host tab may prevent recovery. Host migration is not supported.
Privacy and security
Motion data is processed locally. The game sends bounded score events rather than raw accelerometer readings. There are no accounts or application analytics.
The host is authoritative for scores, rounds and player registration. Clients reject malformed snapshots and score or roster rollback within a round. Compatibility room game payloads use AES-GCM with a key derived from the full invitation ID; the MQTT topic is derived separately. The broker still sees connection metadata and may disrupt delivery. Short codes have 100 million possibilities and are not private credentials; anyone who obtains a valid invitation may join an open lobby. Observed code collisions require a link or QR instead.
This is a casual demo, not a production matchmaking service or a cheat-proof competition. Do not share sensitive information through it.
The application is plain HTML, CSS and JavaScript ES modules. No bundler, framework, database or custom backend is needed. PeerJS, MQTT.js and the QR generator are loaded on demand from jsDelivr.
Clone the repository and serve the project root:
git clone https://github.com/lgg/accelerometer-mobile-race-game.git
cd accelerometer-mobile-race-game
python3 -m http.server 8000Open localhost:8000. Python is only needed for this example static server; any static HTTP server works.
Localhost is a secure context on the same device. For motion testing on a separate smartphone, use HTTPS rather than a plain HTTP LAN address.
| Path | Purpose |
|---|---|
index.html, style.css |
Responsive user interface and themes |
src/app.mjs |
Game screens, controller lifecycle and invitations |
src/engine.mjs |
Host-authoritative race rules and bots |
src/motion.mjs |
Sensor processing, scoring and vibration support |
src/protocol.mjs |
Invitation parsing and snapshot validation |
src/network.mjs |
WebRTC lifecycle, ICE configuration and diagnostics |
src/relay.mjs |
Encrypted MQTT transport and temporary room-code lookup |
test/ |
Automated unit and simulated integration tests |
assets/ |
Application artwork |
Requires Node.js 20+; no npm dependencies need to be installed.
npm run check
npm testThe tests cover race rules, sensor processing, invitations, protocol validation, reconnects, relay encryption, message ordering, simulated browser interactions, and concurrent 16-player rooms. They do not replace physical-device testing or live network checks.
Manual smoke-test checklist
- Open the site on desktop, Android and iPhone; verify both themes and narrow-screen layout.
- Create a Compatibility room and a WebRTC room. Join through QR, link and short code; test each room capacity, late-join rejection and reconnects in a full room.
- Complete rounds in multiplayer and solo modes, including a tie, timeout and rematch. Check result banners, default names and desktop controls.
- Verify mobile permission prompts, automatic sensor activation, stationary readings, comparable motion scoring and feedback on real devices.
- Interrupt connectivity, switch networks, background and resume the browser. Confirm reconnection, preserved scores within the reservation period, and explicit leave / room restoration.
- Test blocked services, invalid invitations and unavailable vibration. Check that errors and diagnostics are understandable.
Fork the repository, open Settings → Pages, choose Deploy from a branch, select master (or your default branch) and / (root), then save. Enable HTTPS. All application paths are relative; .nojekyll enables direct static serving.
DeviceMotion · PeerJS · MQTT.js · qrcode-generator · Web Crypto · Vibration API
MIT © lgg. Contributions, bug reports and suggestions are welcome through GitHub Issues.
Play Motion Race