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
- 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 CharacterSettings3D.innerBody), or 0. -
characterContacts(
int character) → List< CharacterContact3D> -
What
charactertouched in its last update. -
characterState(
int character, CharacterState3D out) → void -
Reads
character's state intooutwithout moving it; a dead character reads as zeros, in the air. -
createBody(
Shape3D shape, BodySettings3D 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(
CharacterSettings3D settings, Vector3 position) → int -
Makes a character whose feet are at
position; 0 when it cannot be made. -
createJoint(
int bodyA, int bodyB, JointSettings3D 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< PhysicsEvent3D> - What happened since the last drain, oldest first.
-
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, CharacterState3D 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, {QueryFilter3D filter = QueryFilter3D.all}) → List< QueryHit3D> -
The bodies
shapeatpositionandrotationoverlaps, one hit each. -
raycast(
Vector3 origin, Vector3 direction, {QueryFilter3D filter = QueryFilter3D.all, bool allHits = false}) → List< QueryHit3D> -
Casts a ray from
originalongdirection, whose length is the ray's. The closest hit, or every hit nearest first whenallHits. -
readBodies(
List< int> bodies, BodyPoses3D out) → void -
bodies' poses, in order, intoout; dead ones read as zeros. -
readMovedBodies(
BodyPoses3D 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, MotorState3D state, double target) → void -
Drives a hinge or slider
joint. -
setLayer(
int body, int layer) → void -
Moves
bodyto another collision layer. -
setLinearVelocity(
int body, Vector3 velocity) → void -
Sets
body's velocity (m/s), waking it. -
setMotionQuality(
int body, MotionQuality3D 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, {QueryFilter3D filter = QueryFilter3D.all, bool allHits = false}) → List< QueryHit3D> -
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