PredictedPhysicsComponent class final
Drives the node of an owned TransformReplica by physics rollback
prediction with authoritative input-replay reconciliation.
Each fixed tick it samples and sends an input command, applies it to the owned body, steps the controller's prediction world, and retains the tick's world snapshot. When the server confirms the authoritative pose after an input tick, a diverged prediction is corrected by restoring the snapshot at that tick, teleporting the body to the authoritative pose (and velocity when replicated), and replaying the not-yet-applied inputs through the world. A correction decays through a visual error offset over smoothing rather than popping.
Snapshots are whole-world, so keep the prediction world small (the owned body plus static geometry). TODO(prediction): per-island snapshots to bound cost in larger predicted scenes.
Constructors
- PredictedPhysicsComponent(TransformReplica replica, {required PredictedPhysicsController controller, required ReplicationClient client, required int tickRate, Duration smoothing = const Duration(milliseconds: 120), double correctionThreshold = 0.05, int historyTicks = 64, int maxCatchUpTicks = 16, NowMicros now = defaultNowMicros})
Properties
- client → ReplicationClient
-
final
- controller → PredictedPhysicsController
-
final
- correctionThreshold → double
-
Positional divergence (metres) beyond which a snapshot triggers a replay
correction.
final
- enabled ↔ bool
-
Whether this component's
updatehook runs each frame.getter/setter pairinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- isAttached → bool
-
Whether this component is currently attached to a node.
no setterinherited
- isLoaded → bool
-
Whether
onLoadhas completed.no setterinherited - isMounted → bool
-
Whether the owning node is part of a live scene graph.
no setterinherited
- maxCatchUpTicks → int
-
Most ticks predicted in one update before the prediction snaps to
authority instead of catching up.
final
- node → Node
-
The node this component is attached to.
no setterinherited
- replica → TransformReplica
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- smoothing → Duration
-
Time constant over which an authoritative correction eases in.
final
Methods
-
cloneFor(
Node cloneOwner) → Component? -
Returns a copy of this component for
cloneOwner, theNode.clonecounterpart of the owning node, or null to not carry the component to clones (the default).inherited -
fixedUpdate(
double fixedDt) → void -
Called once per fixed physics step while the component is mounted,
enabled, and loaded.fixedDtis the fixed timestep of the surroundingPhysicsWorld, not the frame interval.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onAttach(
) → void -
Called when this component is added to a node.
inherited
-
onDetach(
) → void -
Called when this component is removed from a node.
inherited
-
onLoad(
) → Future< void> -
Optional asynchronous setup, such as loading an asset.
inherited
-
onMount(
) → void -
Called when the owning node enters a live scene graph.
inherited
-
onUnmount(
) → void -
Called when the owning node leaves a live scene graph.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
double deltaSeconds) → void -
Called once per frame while the component is mounted, enabled, and
loaded.
deltaSecondsis the elapsed time since the previous tick. A traversal visits each component at most once. Removing this component or an earlier sibling is safe. A component inserted before the current traversal position starts on the next frame. Reordering component or child lists during traversal is unsupported.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited