Skip to content

About

A multiplayer game starter built with React Three Fibre (R3F), Node.js, Socket.io & Vite

Topics

Resources

Stars

13 stars

Watchers

2 watching

Forks

Repository files navigation

🍄 Mushroom Kingdom 🍄

A multiplayer game starter built with React Three Fiber (R3F), Node.js, WebSockets, and Vite.

Mobile controls using nippleJS and WASD movement controls on desktop.

React Three Fiber Multiplayer Game

Installation

  • Use Node.js 20.19 or newer.
  • Install dependencies:
npm install

Usage

Run the full development app, including the Express/WebSocket server and Vite middleware:

npm run dev

Open http://localhost:8080.

Build production assets:

npm run build

Run the production server after a build:

npm start

Build and run production locally:

npm run preview

Voice chat

Peer-to-peer WebRTC. The server relays signalling and serves the ICE server list from /ice-servers.

A deployment needs a TURN relay. Without one, voice works between some pairs of players and not others, with no error on either side. Create a TURN Server app at dash.cloudflare.com -> Realtime -> TURN and set TURN_TOKEN_ID and TURN_API_TOKEN.

/ice-servers is public, so it never serves the key itself - it exchanges it for a credential that expires after two hours. If Cloudflare cannot be reached, voice degrades to STUN rather than taking the game down.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Suggestions for improving the server and WebSocket flow would be much appreciated.

License

MIT

3D Assets

Nature Pack

World time

The server supplies world time on join and on each 25-second heartbeat. Clients compensate for half the round-trip delay and advance using a monotonic browser clock, so local clock settings do not change the time of day. Reconnecting resynchronizes automatically.

shared/dayNightCycle.js defines a repeating 10-minute cycle: five minutes from sunrise to sunset and five from sunset to sunrise. Dawn, dusk and blue twilight blend across each horizon crossing (roughly 45 seconds), within those ten minutes. A fixed UTC epoch keeps the cycle running through empty rooms and server restarts. The sun and moon peak at 25° and travel across the negative-Z side of the sky; their directions also drive the key light, moving shadows and grass highlights. Night retains the cool forest palette.

Run node --test shared/dayNightCycle.test.js to check timing, paths and server messages.

About

A multiplayer game starter built with React Three Fibre (R3F), Node.js, Socket.io & Vite

Topics

Resources

Stars

13 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages