DetPhysDocs日本語

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/Runtime/Shared in the imported samples) and Godot (samples/gear_arena/shared). Unity on a PC and Godot on Android agree on every confirmed tick's hash.
  • 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

UnityGodot
OpenImport the samples (Package Manager > In Project > DetPhys > Samples), open Scenes/SampleMenu.unity and pick "Gear arena" (or play Scenes/GearArena.unity)Open engines/godot/DetPhysSample, F5, then "Gear arena" in the menu (res://samples/gear_arena/gear_arena.tscn; C#, so the .NET build of Godot)
Two players on one device"Two players on this device" in the menuThe same
Two devicesOne side "Host (waits)", the other "Guest (connects)" with the host's IP. Port 47700The same (connects to Unity or Godot)
Two devices (room code)"Make a room" / "Enter the room" (relay, EOS). See Play in a roomThe same
Windows playerAdd Scenes/GearArena.unity (or the sample picker and all four samples) to the build and build a Windows playerThe 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:

ItemMeaning
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 delayThe current input delay [ticks] (default 0)
LampGreen = the confirmed ticks' hashes match the peer's, red = a desync was found and the session is resyncing, grey = nothing compared yet
RollbackTicks re-simulated by the last advance and the maximum within one second (meter)
OpponentThe peer's engine and platform (e.g. Godot 4.7.2 (.NET, Android)), sent by the link wrapper in a separate datagram (never part of the simulation)
Nudge 1 ULPShifts 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 piecesDraws 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_line_params "--,detphys=game=gear;..."): 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.

RelayEOS
How it connectsThrough your own relay (detphys_relay); both devices use the same relayEpic Online Services P2P; through EOS's relay when a direct connection is not possible
What you needA 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 hostThere is no room yet: "Could not use the room (not_found)". Enter after the host has made the roomTries again every second for up to 60 seconds
Path line during the matchPath RELAYED · room 123456 · relay RTT 17 msPath DIRECT · room 123456 (EOS) (no round trip time)

Steps:

  1. 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.
  2. 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.
  3. 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 always RELAYED. With EOS, if either side shows RELAYED, 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/gear by default. Use the same one on both sides (with different buckets the guest cannot find the room).

Relay setup

  • Run detphys_relay somewhere 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.dll (Windows) and eossdk-StaticSTDC-release.aar (Android) (Unity: Assets/Plugins/x86_64, Assets/Plugins/Android; Godot: addons/detphys/bin/windows, addons/detphys/eos/android. 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.
  • Add detphys_eos.ini with your portal values (ProductName, ProductVersion, ProductId, SandboxId, DeploymentId, ClientId, ClientSecret in [eos]). On a PC it goes next to the executable, or in Application.persistentDataPath (Unity) / 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.ini out 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).

PairingConfirmed ticks of 1800Notes
Unity editor / Godot (PC), two peers in one process30/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 msall 30 lines equal on both, 30/30 equal to the referenceEither side as host
Unity (PC) ↔ Godot (S9), no faults / 30–60 ms / 120–150 msall 30 lines equal on both, 30/30 equal to the reference, no tunnellingS9: 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 referenceEither side making the room. Path RELAYED, round trip 17–45 ms
Unity (PC) ↔ Godot (S9), EOS roomall 30 lines equal on both, 30/30 equal to the referenceEither 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 againReport ready 5–80 ms after detection

DetPhys is not affiliated with Box2D or Box3D and is not endorsed or recommended by Box2D, Box3D or their author. It uses Box2D v3 and Box3D, both under the MIT license, as its physics.

LicensesMatches the current versions (2026-11)

© 2026 PetafProductsContactPrivacy

This site uses no analytics or tracking.

↑↓ to choose, Enter to open, Esc to close