PhysicsSystem3D class
Steps a PhysicsWorld3D and keeps it in step with the ECS: the 3-D
counterpart of the engine's 2-D PhysicsSystem (a 3-D game leaves that
one out).
Each update it
- makes, rebuilds and removes bodies for entities with a Collider3D (a RigidBody3D says how they move; without one they are static), characters for CharacterBody3Ds and joints for Joint3Ds;
- sends what gameplay did: forces, impulses and velocities queued on a RigidBody3D, and transforms written by hand — a teleport, or for a kinematic body a move the physics carries what it touches along;
- moves each character, 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.
Constructors
- PhysicsSystem3D(PhysicsWorld3D physics, {ColliderGeometry3D? geometry})
-
A system stepping
physics; mesh and hull colliders take their triangles fromgeometry. - PhysicsSystem3D.lazy(PhysicsWorld3D create(), {ColliderGeometry3D? 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
PhysicsSystem3D.lazy and still waiting for its first body).
no setter
- isActive ↔ bool
-
Whether this system is active
getter/setter pairinherited
- physics → PhysicsWorld3D
-
The world it steps; a PhysicsSystem3D.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 → ColliderShapes3D
-
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).
- scaleTolerance → const double
- The smallest change of an entity's scale, as a fraction of the scale its body was made at, that makes the body again. Less is float noise — an animation or a tween ending at 1.0000001 — and making the body again for it every step also made its joints again each step.