One simulation: bodies, joints and characters that see each other.
Bodies, joints and characters are plain int handles. Every method
accepts dead ones, and ones from another world, and does nothing with
them, so gameplay code never crashes on a body something else destroyed.
0 is never a handle. A handle can come back for a new body once its own
was destroyed (Jolt reuses a body's id after 256 bodies have used its
slot), so forget a handle when you destroy what it names.
Properties
- bodyCount → int
-
How many bodies it holds.
no setter
- gravity ↔ Vector3
-
Gravity, m/s². Setting it wakes nothing; bodies at rest stay asleep.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether dispose was called.
no setter
-
layerMasks
→ List<
int> -
The collision grid it uses now: 16 rows, as
Physics3DWorldSettings.layerMasks gives them.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addAngularImpulse(
int body, Vector3 impulse) → void -
Changes
body's spin at once (N·m·s). -
addForce(
int body, Vector3 force) → void -
Pushes
bodyfor the next step (N). -
addImpulse(
int body, Vector3 impulse) → void -
Changes
body's velocity at once (N·s). -
addTorque(
int body, Vector3 torque) → void -
Turns
bodyfor the next step (N·m). -
characterBody(
int character) → int -
The body that stands in for
character(see Character3DSettings.innerBody), or 0. -
characterContacts(
int character) → List< Character3DContact> -
What
charactertouched in its last update, as objects: one per contact, for code that runs rarely (see readCharacterContacts). -
characterState(
int character, Character3DState out) → void -
Reads
character's state intooutwithout moving it; a dead character reads as zeros, in the air. -
createBody(
Shape3D shape, Body3DSettings settings) → int -
Makes a body of
shape; 0 when it cannot be made (a shape that is not Shape3D.isValid, a mesh or a height field on a body that is not static, a layer outside 0–15, a full world). -
createCharacter(
Character3DSettings settings, Vector3 position) → int -
Makes a character whose feet are at
position; 0 when it cannot be made. -
createJoint(
int bodyA, int bodyB, Joint3DSettings settings) → int -
Joins
bodyAtobodyB, or to the world whenbodyBis 0; 0 when it cannot be made. Both must be bodies createBody made, not a character's body. -
debugLines(
{bool joints = false}) → Float32List? -
Every body (and joint, when
joints) as lines, seven floats each: x1 y1 z1 x2 y2 z2, then a colour (0xAARRGGBB) stored in the float's bits (read it withByteData.view(lines.buffer).getUint32(…, Endian.host)). Null when the backend cannot draw (Jolt outside its dev flavour). -
destroyBody(
int body) → void -
Destroys
bodyand every joint holding it. Only bodies createBody made: a character's body (characterBody) goes with its character. -
destroyCharacter(
int character) → void -
Destroys
character. -
destroyJoint(
int joint) → void -
Destroys
joint. -
dispose(
) → void - Destroys the world and everything in it. Safe to call twice.
-
drainEvents(
) → List< Physics3DEvent> - What happened since the last read, oldest first, as objects: one per event, for tests and code that runs rarely (see readEvents).
-
isAwake(
int body) → bool -
Whether
bodyis awake. -
isBody(
int body) → bool -
Whether
bodyis a live body of this world. -
isCharacter(
int character) → bool -
Whether
characteris a live character of this world. -
isJoint(
int joint) → bool -
Whether
jointis a live joint of this world. -
jointValue(
int joint) → double - A hinge's angle (radians) or a slider's position (metres) — body A's, measured from body B (or the world) — the same quantity a position motor drives; 0 for other joints.
-
moveCharacter(
int character, double dt, Vector3 velocity, Character3DState out, {required Vector3 stepDown, required Vector3 stepUp}) → void -
Moves
characterfor one update atvelocity: it slides along walls, keeps to the floor (stepDown, pointing down; zero to turn off) and climbs steps up tostepUp(pointing up; zero to turn off). Writes where it ended up intoout. -
moveKinematic(
int body, Vector3 position, Quaternion rotation, double dt) → void -
Moves a kinematic
bodyso it arrives atpositionandrotationafterdtseconds, giving it the velocity that takes. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
overlap(
Shape3D shape, Vector3 position, Quaternion rotation, {Query3DFilter filter = Query3DFilter.all}) → List< Query3DHit> -
The bodies
shapeatpositionandrotationoverlaps, one hit each. -
raycast(
Vector3 origin, Vector3 direction, {Query3DFilter filter = Query3DFilter.all, bool allHits = false}) → List< Query3DHit> -
Casts a ray from
originalongdirection, whose length is the ray's. The closest hit, or every hit nearest first whenallHits. -
readBodies(
List< int> bodies, Body3DPoses out) → void -
bodies' poses, in order, intoout; dead ones read as zeros. -
readCharacterContacts(
int character, Character3DContacts out) → void -
What
charactertouched in its last update, intoout: no object per contact. -
readEvents(
Physics3DEvents out) → void -
What happened since the last read, oldest first, into
out: no object per event, for a read every step. -
readMovedBodies(
Body3DPoses out) → void -
The bodies that moved in the last step — awake bodies, and those that
fell asleep since the last read — into
out. Static bodies and characters' bodies are left out. -
setAngularVelocity(
int body, Vector3 velocity) → void -
Sets
body's spin (rad/s), waking it. -
setBodyPose(
int body, Vector3 position, Quaternion rotation, {bool wake = true}) → void -
Teleports
body. Static bodies are moved this way; kinematic bodies should use moveKinematic so what they touch is carried along. -
setCharacterPosition(
int character, Vector3 position) → void -
Teleports
character's feet toposition. -
setFriction(
int body, double friction) → void -
Sets
body's friction. -
setGravityFactor(
int body, double factor) → void -
Sets how strongly gravity pulls
body. -
setJointEnabled(
int joint, bool enabled) → void -
Turns
jointon or off without destroying it. -
setJointMotor(
int joint, Motor3DState state, double target) → void -
Drives a hinge or slider
joint. -
setLayer(
int body, int layer) → void -
Moves
bodyto another collision layer. -
setLayerMasks(
List< int> masks) → void -
Replaces the collision grid:
masksas Physics3DWorldSettings.layerMasks takes them (see Physics3DWorldSettings.normalizeLayerMasks). The next step judges every pair by it: every body that can move is woken, so pairs at rest are looked at again, and characters take their layer's new row. A grid equal to the current one does nothing. -
setLinearVelocity(
int body, Vector3 velocity) → void -
Sets
body's velocity (m/s), waking it. -
setMotionQuality(
int body, Motion3DQuality quality) → void -
Switches
body's continuous collision on or off. -
setRestitution(
int body, double restitution) → void -
Sets
body's bounciness. -
shapeCast(
Shape3D shape, Vector3 position, Quaternion rotation, Vector3 direction, {Query3DFilter filter = Query3DFilter.all, bool allHits = false}) → List< Query3DHit> -
Sweeps
shapefrompositionandrotationalongdirection. The closest hit, or every hit nearest first whenallHits. -
step(
double dt, {int collisionSteps = 1}) → void -
Advances the simulation by
dtseconds, incollisionStepspasses (one per 1/60 s is plenty). Characters move in moveCharacter, before it. -
toString(
) → String -
A string representation of this object.
inherited
-
wake(
int body) → void -
Wakes
body.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited