Ember is discontinued. It still works, but it gets no more updates or support. Back to uayi.org
Home · Terrified Gorillas · Glimmerwood · Starfall Hollow · ‹ Prev Next ›
Ember
Download

Making games

Multiplayer and voice chat

Ember's multiplayer works like Unity's Mirror: one player hosts (the server), the others join, and objects are owned by someone. It's built in C++ and driven from Lua, blocks or visual scripts.

net.host(7777)                         -- or net.join("192.168.1.20", 7777)

net.on("player_joined", function(id, name)
    -- the server spawns an avatar that the new player controls
    net.spawn({ name = "Avatar", mesh = "builtin:sphere", position = vec3(0, 2, 0),
                body = { type = "dynamic", shape = "sphere" } }, id)
end)

-- on every player: move what you own
for _, a in ipairs(scene.entities("Avatar")) do
    if a:is_mine() then a:set_velocity(vec3(3, 0, 0)) end
end

a:set_var("health", 80)                -- synced variable: the owner or server writes, everyone reads a:var("health")
net.set("round", 2); net.get("round")  -- shared game state (server)
net.rpc("explode", { at = vec3(1, 2, 3) })       -- server -> everyone
net.command("fire", { dir = vec3(0, 0, -1) })    -- client -> server
net.on("fire", function(from, data) end)         -- handlers for both
net.voice(true, "V")                   -- voice chat, push-to-talk on V ("" = open mic)
net.voice_proximity(30)                -- quieter with distance

Networked objects

Mark scene objects as networked, or spawn them with net.spawn. The owner (the server unless you say otherwise) sends positions about 20 times a second and everyone else smoothly interpolates; dynamic bodies become kinematic on players that don't own them. Players who join late receive everything already spawned. When a player leaves, their objects go with them.

Transports

Transport
ENet (built in) UDP; LAN or a port-forwarded internet host
Photon Realtime relay servers and room names; bring your own SDK and App ID
Epic Online Services peer-to-peer with NAT traversal; join by the host's id; bring your own SDK

Pick one per project in Project Settings > Network, or per call: net.host(7777, 8, "eos").

Voice chat

Microphone capture, Opus at 24 kbit/s in 20 ms frames with error correction, relayed by the server and played per speaker with distance falloff. There's no echo cancellation yet, so headphones work best.

Cheating

The server checks movement: impossible speeds or teleports are rejected and the player is put back; repeat offenders, message floods and malformed packets earn strikes and a kick. See Anti-cheat.

Testing on one computer

ember_player --project MyGame --host 7777
ember_player --project MyGame --join 127.0.0.1:7777
Ember 1.1 documentation. Found a mistake? The source of this page is site/docs/multiplayer.md in the Ember source.