PhysicsWorld3D class abstract interface

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 body for 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 body for 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 character touched in its last update.
characterState(int character, CharacterState3D out) → void
Reads character's state into out without 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 bodyA to bodyB, or to the world when bodyB is 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 with ByteData.view(lines.buffer).getUint32(…, Endian.host)). Null when the backend cannot draw (Jolt outside its dev flavour).
destroyBody(int body) → void
Destroys body and 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 body is awake.
isBody(int body) → bool
Whether body is a live body of this world.
isCharacter(int character) → bool
Whether character is a live character of this world.
isJoint(int joint) → bool
Whether joint is 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 character for one update at velocity: it slides along walls, keeps to the floor (stepDown, pointing down; zero to turn off) and climbs steps up to stepUp (pointing up; zero to turn off). Writes where it ended up into out.
moveKinematic(int body, Vector3 position, Quaternion rotation, double dt) → void
Moves a kinematic body so it arrives at position and rotation after dt seconds, 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 shape at position and rotation overlaps, one hit each.
raycast(Vector3 origin, Vector3 direction, {QueryFilter3D filter = QueryFilter3D.all, bool allHits = false}) → List<QueryHit3D>
Casts a ray from origin along direction, whose length is the ray's. The closest hit, or every hit nearest first when allHits.
readBodies(List<int> bodies, BodyPoses3D out) → void
bodies' poses, in order, into out; 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 to position.
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 joint on 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 body to 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 shape from position and rotation along direction. The closest hit, or every hit nearest first when allHits.
step(double dt, {int collisionSteps = 1}) → void
Advances the simulation by dt seconds, in collisionSteps passes (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