RawPhysics class final
A physics world in the native library, used through ids: the layer the game's colliders and rigidbodies are built on. A step's moved bodies are read from one buffer (step, then movedKey and the rest), so a step is two calls however many bodies there are.
Its memory is freed by dispose, or when nothing reaches it any more.
- Implemented types
Constructors
- RawPhysics()
- A new, empty world, with Unity's gravity, (0, -9.81, 0).
Properties
- gravity ↔ Vec3
-
The world's gravity, in m/s²: (0, -9.81, 0) unless set.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stepLength ↔ double
-
How long each step is, in seconds: 1/50 at first. Throws an
ArgumentError unless it's more than 0 and finite.
getter/setter pair
Methods
-
addBody(
BodyKind kind, int key, {Vec3 position = Vec3.zero, Quat rotation = Quat.identity}) → int -
Adds a body at
positionandrotation, withkeyto know it by in movedKey, and returns its id. -
addBox(
int body, Vec3 halfExtents, {Vec3 position = Vec3.zero, Quat rotation = Quat.identity}) → int -
Adds a box collider, by half its size on each axis, to
body(or to the world, as a static collider, whenbodyis 0), and returns its id. -
addCapsule(
int body, double halfHeight, double radius, {Vec3 position = Vec3.zero, Quat rotation = Quat.identity}) → int -
Adds a capsule collider along Y:
halfHeightof cylinder between the two half-spheres' centres on each side of its middle. See addBox. -
addSphere(
int body, double radius, {Vec3 position = Vec3.zero, Quat rotation = Quat.identity}) → int - Adds a sphere collider; see addBox.
-
beginStep(
) → void - Starts a step of stepLength on a thread of the physics' own, and returns at once: nothing else may be asked of this world until endStep, which waits for it and returns what step does. (An experiment, docs/stage-5.md §6.)
-
bodyPose(
int body) → (Vec3, Quat) - Where a body is now.
-
dispose(
) → void - Frees the native world now. Using it after this throws.
-
endStep(
) → int - Waits for the step beginStep started; returns as step does.
-
movedAngularVelocity(
int i) → Vec3 -
How fast the
ith body the last step moved turns, in rad/s. -
movedKey(
int i) → int -
The key of the
ith body the last step moved. -
movedLinearVelocity(
int i) → Vec3 -
How fast the
ith body the last step moved goes, in m/s. -
movedPosition(
int i) → Vec3 -
Where the
ith body the last step moved is, in the world. -
movedRotation(
int i) → Quat -
How the
ith body the last step moved is turned, in the world. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
raycast(
Vec3 origin, Vec3 direction, double maxDistance) → double? -
How far along
directionfromorigina ray first hits a collider, withinmaxDistance, or null: every layer, triggers too. -
removeBody(
int body) → void - Removes a body and the colliders on it.
-
removeCollider(
int collider) → void - Removes a collider. Throws a StateError when no collider has this id.
-
setBodyPose(
int body, Vec3 position, Quat rotation) → void - Puts a body somewhere at once (a teleport), and wakes it.
-
step(
) → int - Moves the world on by stepLength and returns how many bodies the step moved: their keys and poses are movedKey, movedPosition and movedRotation from 0 to one less, until the next step.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited