Physics3DSystem class
Steps a Physics3DWorld and keeps it in step with the ECS: the 3-D
counterpart of the engine's 2-D Physics2DSystem (a 3-D game leaves that
one out), split the same way into bodies, joints, characters and
contacts.
Each update it
- makes, rebuilds and removes bodies for entities with a Collider3DComponent (a RigidBody3DComponent says how they move; without one they are static), and sends what gameplay did: forces, impulses and velocities queued on a RigidBody3DComponent, and transforms written by hand — a teleport, or for a kinematic body a move the physics carries what it touches along;
- makes, rebuilds and removes the joints for Joint3DComponents;
- moves each CharacterBody3DComponent, then steps the world;
- writes the moved bodies' poses back into their TransformComponents,
after
capturePrevious()so the renderer interpolates between steps; - fires CollisionEnter3DEvent, CollisionExit3DEvent, SensorEnter3DEvent and the rest on the world's event bus.
It runs at SystemPriorities.physics (90), after input and player control. Taking it out of its world or disposing it removes everything it made from physics; the world itself belongs to whoever made it.
The collision layers a world keeps apart start as it was made
(Physics3DWorldSettings.layerMasks). A grid edited while a 3-D scene
plays (EngineContext.physicsLayers set to a new one) reaches the
running world at the next update (Physics3DWorld.setLayerMasks). A
body's own layer can change at any time.
Constructors
- Physics3DSystem(Physics3DWorld physics, {Collider3DGeometry? geometry})
-
A system stepping
physics; mesh and hull colliders take their triangles fromgeometry. - Physics3DSystem.lazy(Physics3DWorld create(), {Collider3DGeometry? geometry})
-
A system that makes its world with
createonly when the first 3-D body or character appears. Until then an update costs a structure check and nothing else, and there is no world at all — no worker threads, no tables sized for thousands of bodies — so a game whose 3-D scenes come later (a 2-D menu first) pays nothing for them.
Properties
-
entities
→ Iterable<
Entity> -
Get all entities that match this system's requirements
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasWorld → bool
-
Whether the world exists (always, unless made with
Physics3DSystem.lazy and still waiting for its first body).
no setter
- isActive ↔ bool
-
Whether this system is active
getter/setter pairinherited
- physics → Physics3DWorld
-
The world it steps; a Physics3DSystem.lazy system makes it now if it
has not yet.
no setter
- priority ↔ int
-
Priority for system execution order (higher = earlier). Systems of
the same priority run in the order they were added.
getter/setter pairinherited
- profileName → String
-
What World.stats files this system's time under (
systemTimesMs).no setterinherited -
requiredComponents
→ List<
Type> -
Required component types for this system
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shapes → Collider3DShapes
-
Turns colliders into shapes.
final
- world ↔ World
-
World this system belongs to
getter/setter pairinherited
Methods
-
bodyOf(
Entity entity) → int -
entity's body, or 0. -
characterOf(
Entity entity) → int -
entity's character, or 0. -
dispose(
) → void -
Dispose system resources
override
-
entityOf(
int body) → Entity? -
The entity whose body, or character's body,
bodyis; null for one this system did not make. -
forEach(
void action(Entity entity)) → void -
Execute a function for each matching entity
inherited
-
initialize(
) → void -
Initialize the system
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onAddedToWorld(
) → void -
Called when system is added to world
inherited
-
onRemovedFromWorld(
) → void -
Called when system is removed from world
override
-
reloadModel(
String model) → void -
modelwas loaded again: its mesh and hull colliders take its new triangles. Call once they are there — theModelAssetat that path answers with them — and each such body is made again, with no enter or exit for what it touches; until the new triangles arrive, a body keeps its old shape. -
render(
Canvas canvas, Size size) → void -
Render the system (optional)
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
double deltaTime) → void -
Update the system
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- collisionStep → const double
- One collision pass per this much of a step; a longer step gets more.
- moveEpsilon → const double
- Below this a transform is where the system left it (metres).