Sample: Gear Arena (pushing inside a spinning gear)
A match inside a spinning gear: push concave pieces around. It exists for both Unity and Godot, and the two can play each other.
- Moving concave shapes, collided exactly: an internal gear (a concave ring with two gaps) spins; inside it, two rods push 120 concave pieces (L, T, U, cross). The gear is a kinematic concave shape driven as a function of the tick ("moving concave shapes" in 3. Concepts), so it adds no state to roll back.
- Zero input delay: the default input delay is 0 ticks. The remote input is predicted; a wrong guess is rolled back and re-simulated.
- Cross-engine play: the rule is written once in C#; the same files are in Unity (
GearArena/in the imported samples) and Godot (Runtime/ Shared samples/). Unity on a PC and Godot on Android agree on every confirmed tick's hash.gear_ arena/ shared - A desync shows its cause and heals itself: "Nudge 1 ULP" shifts the state by one ULP; the desync debugger shows the tick, body and field on both devices and the session resyncs.
How to play: a piece that falls out through a gap and crosses the line below scores for the player on the other side (falls on P1's side, left = a point for P2). After 30 seconds (1800 ticks) the player who pushed out more wins.
Run it
| Unity | Godot | |
|---|---|---|
| Open | Import the samples (Package Manager > In Project > DetPhys > Samples), open Scenes/ and pick "Gear arena" (or play Scenes/) | Open engines/, F5, then "Gear arena" in the menu (res://; C#, so the .NET build of Godot) |
| Two players on one device | "Two players on this device" in the menu | The same |
| Two devices | One side "Host (waits)", the other "Guest (connects)" with the host's IP. Port 47700 | The same (connects to Unity or Godot) |
| Two devices (room code) | "Make a room" / "Enter the room" (relay, EOS). See Play in a room | The same |
| Windows player | Add Scenes/ (or the sample picker and all four samples) to the build and build a Windows player | The Windows / Android export presets |
Controls: P1 = WASD to move, Q E to turn the rod (gamepad: left stick, LB RB). P2 on the same device = arrows, N M. Touch: drag on the left to move, the buttons at the bottom right turn. Make the PC the side that connects: then Windows Firewall needs no permission. Either side may be the host (the reference when states differ).
Top left of the screen:
| Item | Meaning |
|---|---|
| Injected delay (slider 0..150 ms) | Delays the packets this side sends (jitter = 1/5 of the delay). The confirmed results stay the same; only the rollback gets deeper |
| Input delay | The current input delay [ticks] (default 0) |
| Lamp | Green = the confirmed ticks' hashes match the peer's, red = a desync was found and the session is resyncing, grey = nothing compared yet |
| Rollback | Ticks re-simulated by the last advance and the maximum within one second (meter) |
| Opponent | The peer's engine and platform (e.g. Godot 4.), sent by the link wrapper in a separate datagram (never part of the simulation) |
| Nudge 1 ULP | Shifts this side's state (the last created dynamic body = P2's rod, x) by one ULP → the desync debugger's report at the bottom → automatic resync |
| Show convex pieces | Draws the gear and the pieces as the convex polygons given to Box2D (shows that nothing is approximated) |
| Path (rooms only, below the panel) | How this side reaches the peer (DIRECT / RELAYED) and the room code; with a relay, also the round trip time to the relay (Play in a room) |
Launch options (automatic matches and tests; Unity -detphys "...", Godot -- detphys=game=gear;..., Godot on Android --esa command_): peer=0|1, listen=<port>, connect=<ip>:<port>, mode=local, auto=1 (automatic input), ticks=<n>, delay=<min>:<max>, loss=<‰>, dup=<‰>, inputdelay=<n>, nudge=<t>/<t> (shift the guest after tick t), convex=1, objects=<n> (e.g. 100..150; the same on both), gap=<segments>, spin=<mrad/s>, lang=en|ja, quit=1. With automatic input and the default settings both engines compare against the reference hashes and print [DetPhysGear] SUMMARY OK|FAIL.
Play in a room
Instead of the LAN UDP (typing the peer's IP), the two devices can also connect with a room code. Then the peer does not have to be on the same Wi-Fi (a home line and a mobile network, for example). There are two ways, "relay" and "EOS", and the menu has a "Make a room" and an "Enter the room" button for each. The match is the same as on a LAN, between Unity and Godot and between a PC and Android too.
| Relay | EOS | |
|---|---|---|
| How it connects | Through your own relay (detphys_relay); both devices use the same relay | Epic Online Services P2P; through EOS's relay when a direct connection is not possible |
| What you need | A running relay (see "Relay setup" below) | The EOS SDK files and detphys_eos.ini (see "EOS setup" below) |
| Make a room (host, P1) | Enter host or host:port (port 40400 by default) under "Relay", then "Make a room (relay)" | "Make a room (EOS)" |
| Enter the room (guest, P2) | Enter the same relay and the 6 digits under "Room code", then "Enter the room (relay)" | Enter the 6 digits under "Room code", then "Enter the room (EOS)" |
| Entering before the host | There is no room yet: "Could not use the room (not_found)". Enter after the host has made the room | Tries again every second for up to 60 seconds |
| Path line during the match | Path RELAYED · room 123456 · relay RTT 17 ms | Path DIRECT · room 123456 (EOS) (no round trip time) |
Steps:
- On the host, make a room: the 6-digit room code appears in the middle of the match screen while it waits for the peer. Tell the other player this code.
- On the guest, enter the room code. While it connects, "Cancel" ("Menu" when the Unity sample was opened without the sample picker) goes back to the menu.
- When the peer is in, the match starts and the room code disappears. The path line is below the panel at the top left.
- The room code has 6 digits (5 digits plus a check digit). Typos are found before anything is sent: "The room code is not valid".
- The path is how this side reaches the peer:
DIRECT= directly,RELAYED= through a relay. A relay room is alwaysRELAYED. With EOS, if either side showsRELAYED, EOS's relay is in between. The confirmed ticks' hashes are the same on every path. - The EOS transport does not measure a round trip time to a relay, so with EOS the path line shows no round trip time.
- The room's bucket is
detphys-sample/by default. Use the same one on both sides (with different buckets the guest cannot find the room).gear
Relay setup
- Run
detphys_relaysomewhere both devices can reach (a VPS, or a PC on the same LAN for a quick test) and allow incoming UDP on its port (40400 by default). See 8. Transports and room codes. - Enter the same host or host:port under "Relay" on both devices.
EOS setup
- The EOS SDK is not included. Get it from Epic's developer portal and add
EOSSDK-Win64-Shipping.(Windows) anddll eossdk-StaticSTDC-release.(Android) (Unity:aar Assets/,Plugins/ x86_ 64 Assets/; Godot:Plugins/ Android addons/,detphys/ bin/ windows addons/. For Godot on Android, enable the DetPhys plugin in the project settings and export with the Gradle build). Details: Using it from Unity and Godot.detphys/ eos/ android - Add
detphys_eos.iniwith your portal values (ProductName,ProductVersion,ProductId,SandboxId,DeploymentId,ClientId,ClientSecretin[eos]). On a PC it goes next to the executable, or inApplication.(Unity) /persistentDataPath user://(Godot), which is the place to use when running in the editor; on Android, in the app's external files folder (/).sdcard/ Android/ data/<package>/ files/ - Keep
detphys_eos.iniout of version control (it holds the client secret). For the sample, put it only on the devices you test with. In your own game the values ship with the game (EOS P2P). - Test EOS rooms with two devices. Two processes on the same PC are the same EOS user, so they cannot connect.
- When a file is missing, the menu shows "EOS is not available: ..." with the reason. The LAN and relay rooms still work.
Launch options (rooms): relay=<host>[:<port>] or eos=<ini path, its folder, or 1> (1 = look in the usual places) use a room instead of the LAN UDP. The side with room=<room code> or peer=1 enters; the other side makes the room. Also roomseed=<n> (tests: the same n on both sides uses a fixed room code, and the guest tries again until the room exists), bucket=<name>, localport=<n> (this side's port with a relay), eosrelay=allow|force|never (how EOS's relay is used; EOS P2P). With auto=1 or roomseed=, a relay guest also tries again for 30 seconds until the room exists.
Measured
PC = i7-12700F / Windows 11, S9 = Galaxy S9 (SC-03K, Android 10), same Wi-Fi. 120 pieces, 60 Hz, 4 substeps, prediction window 10, input delay 0. 2026-11-11 (the two room rows: 2026-11-12, EOS SDK 1.19.2.1).
| Pairing | Confirmed ticks of 1800 | Notes |
|---|---|---|
| Unity editor / Godot (PC), two peers in one process | 30/30 equal to the reference (chain 0x9d7756fc3b41e1bd) | Same on Unity 6000.3 (Mono) and Godot 4.7.2 (.NET 8) |
| Godot ↔ Godot (two PC processes), no faults / 30–60 ms, 10 %, 2 % | all 30 lines equal on both, 30/30 equal to the reference | |
| Godot (PC) ↔ Unity (PC player), no faults / 30–60 ms / 120–150 ms | all 30 lines equal on both, 30/30 equal to the reference | Either side as host |
| Unity (PC) ↔ Godot (S9), no faults / 30–60 ms / 120–150 ms | all 30 lines equal on both, 30/30 equal to the reference, no tunnelling | S9: 59.9 fps, 2 of 1844 frames over 20 ms |
| Unity (PC) ↔ Godot (S9), relay room (relay on the PC) | all 30 lines equal on both, 30/30 equal to the reference | Either side making the room. Path RELAYED, round trip 17–45 ms |
| Unity (PC) ↔ Godot (S9), EOS room | all 30 lines equal on both, 30/30 equal to the reference | Either side making the room. Path DIRECT, round trip 16–19 ms |
| Nudge (guest shifted by 1 ULP at ticks 600 and 1200) | Both sides report the same (tick 600, body 122 = P2's rod, field x, 1 ULP, cause physics) → resync → equal to the reference again | Report ready 5–80 ms after detection |