Single-vehicle sync improvements
Model
Cluster topology
A cluster is a collection of $\displaystyle N$ rigid bodies. A truck with trailer is two bodies. An articulated bus is two bodies. Each body $\displaystyle B_i$ has a complete world-space transform that is synchronized independently.
State representation
The full cluster state at time $\displaystyle t$ is a set of body transforms:
$$\Large\mathbf{S}(t) = { \underbrace{(\mathbf{x}_i, \mathbf{q}_i, \mathbf{v}i, \boldsymbol{\omega}i)}{\text{body } i \text{ transform}} }{i=0}^{N-1}$$
Where for each body $\displaystyle B_i$:
- $\displaystyle \mathbf{x}_i \in \mathbb{R}^3$ is the body's position in world coordinates.
- $\displaystyle \mathbf{q}_i \in \mathbb{H}$ is the body's orientation as a unit quaternion.
- $\displaystyle \mathbf{v}_i \in \mathbb{R}^3$ is the body's linear velocity.
- $\displaystyle \boldsymbol{\omega}_i \in \mathbb{R}^3$ is the body's angular velocity.
Key principle: All body transforms are transmitted explicitly. Joint articulation is implicit in the relative transforms between bodies — joint angles are not part of wire state:
$$\Large\theta_{\text{joint}} = \text{angle}(\mathbf{q}_0^{-1} \cdot \mathbf{q}_1)$$
The wire carries only the outcome of the physics simulation, not the internal joint state.
Authority distribution
Physics ownership
The cluster owner simulates physics for all bodies using BeamNG's native couplers and solver. Non-owner peers perform direct state replay: they receive $\mathbf{S}(t)$ snapshots and set body transforms directly. Non-owner peers do not integrate forces or compute forward kinematics.
Formally, for any peer $\displaystyle P$ and any body $\displaystyle B_i$ in a cluster owned by $\displaystyle O \neq P$:
$$\Large T_i^P(t) = T_i^O(t - \text{latency})$$
All body transforms come from the wire, never from local simulation.
Invariant: replay peers execute direct state application only, no dynamics, no forward kinematics.
Rear steering
Bidirectional physics coupling occurs within the owner's BeamNG solver. The wire carries only the resulting body states. Rear-steer input is control state, not cluster state.
Invariant: control inputs and cluster state are separate message types. Steering angles are consumed by the owner to produce $\displaystyle \mathbf{S}(t+\Delta t)$. Replay peers receive the result — rear-steer angle need not be transmitted.
Invariants
If these four hold, drift is impossible by construction:
-
Single integrator. For each cluster, exactly one peer (the owner) integrates forces through BeamNG's native solver. All others replay.
-
Explicit body states. Wire state is $\displaystyle {(\mathbf{x}_i, \mathbf{q}_i, \mathbf{v}_i, \boldsymbol{\omega}i)}{i=0}^{N-1}$ — all body transforms explicit. No derived poses, no joint DOFs.
-
Direct replay. Replay peers set body transforms directly from wire data. No forward kinematics, no joint reconstruction, no independent physics.
-
Control/state separation. Control inputs flow peer → owner. State flows owner → peers. These are different message types with different guarantees.
The only drift sources are numerical (float precision) and latency (peer sees old state). Both are bounded by how recently the owner's last $\displaystyle \mathbf{S}(t)$ arrived.
Implementation Scope
This PR implements:
- Wire schema for $\displaystyle \mathbf{S}(t)$ with explicit per-body transforms (position, rotation, linear velocity, angular velocity)
component_idfield to distinguish bodies within a cluster group (reserved in Phase 1b, activated in Phase 2)- Replay peer path using direct state application (no independent trailer physics, no forward kinematics)
- Single-owner authority model (cross-owner handover deferred)
- Measurement primitives (divergence ring buffer, p50/p95/p99 statistics)
Out of Scope
- Cross-owner authority handover. Single owner per cluster assumed. Handover protocol (epoch system, two-phase commit) is deferred.
- Emergent contact clusters. Contact graph and automatic cluster formation (pile-ups, tow ropes, cars on trailers) specified separately.
- Split control. Co-op driving (separate players controlling front/rear) supported by model but not implemented.
- Damage sync. Broken beams and deformation state tracked separately.
Review Guidance
Wire schema
Verify all body transforms are explicit with no joint DOFs. Confirm component_id is reserved for cluster extension.
Replay path
Confirm direct state application is the sole source of body poses. Verify no residual forward kinematics or independent trailer physics simulation.
Authority boundary
Confirm owner simulates full cluster through BeamNG's native solver before broadcasting $\displaystyle \mathbf{S}(t)$. Verify control input handling is separated from state transmission.
Testing
- [ ] Single truck + trailer: no drift over 5 minutes (all observers)
- [ ] Hitch/unhitch: no pose snap at coupling or decoupling
- [ ] Articulated bus (rear steering): hinge angle p95 < 0.5° (owner vs observers)
- [ ] Packet loss 5-15%: dead-reckoning holds, no teleport on snapshot arrival
- [ ] Reconnection: mid-session join receives current cluster state
Known Risks
Two places where the model meets BeamNG's API and might need adjustment:
-
applyClusterLinearAngularAccelcompatibility. The foundation assumes the owner can integrate the cluster through its solver without the API imposing sync assumptions that fight the "owner simulates everything" invariant. This needs verification on Phase 1/2 work. -
Coupling handshake latency. The two-phase protocol adds at least one round-trip between detection and commitment. If this is perceptible to the player pulling up to a hitch, we may need speculative commit with server rollback rather than strict two-phase commit. That's a UX tradeoff to evaluate later.
References
- Full model derivation:
ClusterSyncFoundation.md - Implementation roadmap:
ClusterSyncRoadmap.md - Debugger toolchain (for testing):
HotReloadingDebuggerRoadmap.md
I wanted to let you know our current thoughts on your work:
Looking at some of your changes we are mainly concerned that it strays away from the relative simplicity and maintainability of the current codebase (i.e. KISS principle). In the current state of these mass changes, you still mention limitations like drift/error accumulation and potentially needing vehicle-specific presets. Also, you mention some other complex "Out of Scope" aspects, would you also be planning on having them implemented too? As this continues to raise the total complexity further.
As I said before, if you can break it down into modular changes it would be nicer to review, test and consider. You'd probably have a better idea on how to split this. Next, we can look into merging any stable and simple changes first, proven and consistent bugfixes. Cluster-sync and other crazy stuff should be kept on a separate branch. I'm wondering if it would be sensible to perhaps have an experimental toggle for this model, even, if it proves to be reliable eventually. Ideally this should be kept up to sync with the master branch. As you said correctly, this may be a bit of a faff but hopefully we can agree on a way to make it easier for you, especially as we are not currently working on mass changes to this logic (apart from refactoring from @DaddelZeit, which is sensible given that the codebase is years old). Ultimately, the rest of us are currently in a state of maintenance, bugfixing and gradual improvement.
The other concerns are impact on performance and updates to the game itself. The performance concern is both for local resources and effect of internet latency (which this game suffers from greatly, regardless of how great the sync implementation is). I'm not sure myself how realistic the latter is, so please correct me if I'm wrong, but your current changes seem very sensitive to parameters and increase reliance on game engine events which, when updated or tweaked, I assume would result in more maintenance being required from us.
I also notice a lot of AI agentic work being used. While it's powerful, it does seem to be doing some fairly large rewrites and bloating of the code which is daunting for us reviewers.
We appreciate this pretty significant effort, but hopefully you can understand our points as we're hoping to coordinate and experiment with these changes. And hopefully this is not read as some wacky corporate email as I wanted to be logical and polite :))
Also relevant to #188.
Hi there! Thanks for the feedback. The larger PR will be closed anyway.
drift/error accumulation and potentially needing vehicle-specific presets
This is the inherent limitation of the previous vehicle-syncing approach you've seen in all the videos I've posted with trailers. Different vehicle configurations, say, an eSBR 500 with a small tilt bed has its center point somewhere else than just the car, or a capsule bus.
You can tune some parameters in the vehicle clusters (or vehicle groups), and get it working quite well for an articulated bus, and it will pretty much fix the drift there - however, the car and trailer drift will now diverge from the true state again.
You just simply cannot fix this with PD/PID sync. Cluster sync with velocities applied to all nodes is pretty much the only way to avoid chasing targets you'll never catch.
If this even in a modularized state, for now just a single car, etc... is still too much (doesn't fit your definition of simple), I would drop the work on trailers.
your current changes seem very sensitive to parameters
The entire point of this rather dry mathematical model is to avoid that. It's a single branch of logic for everything. The opposite of the other PR that I will close.
Since you seem fine with going forward in a stepped and modular fashion ...
How about we simply start with cars turning correctly and closing a lot of the latency drift gap, thus position offset.
As far as I have tested master, the car position gets up to a meter off, diverging with acceleration and converging with deceleration, also, the car turns way too late, not because of angular prediction, but because the car turns around its centerpoint - and not where it's actually articulated (the front steered wheels).
This would be simplest case of node cluster sync (single vehicle, single cluster), pose hopefully no large risk of regression and would make the rendering of other cars visibly smoother and more realistic.
In principle this should even work for an articulated bus as all of the simulated positions and velocities are sent over the wire exactly as simulated on the owner's side.
What do you think? Have a wonderful day
The mathematical model in the PR description is mostly about the node velocity-sync that allows car movement to replay exactly for others how it did on the owner's instance.
Also, only one BeamNG instance should ever have the authority to simulate a cluster where ownership is fragmented (truck may be Person A and trailer Person B) but that's a corner case.
I think the term "cluster" here is a bit confusing because in BeamNG the term cluster refers to a part of the node/beam structure
It seems the only way to preserve both positions and velocities in tandem for a soft-body physics multiplayer mod like this is a trajectory sync with a specific set of selected actuating nodes. More specifically, a node triangle near the center of the vehicle chassis, and below 10 outer points as lever arms if necessary as the actuation of the center triangle is relatively weak. So-called "support nodes" along with a "support gain".
Already simulates bus movement at the most oscillation-sensitive seat of an articulated bus (the back) quite realistically.
https://www.youtube.com/watch?v=7zzush2qU4E
I'm currently still working on readying and testing the new trajectory sync approach.
- velocity for immediate motion
- tangent for heading
- normal for cross-track
- weak tangent assist for phase
- support only for vertical/tilt