PhysicsAPI reference
Namespace MicroEngine.Physics
The 2D physics contract: worlds of bodies owned by entities, box shapes with collision layers, collide-and-slide moves with their contacts, ray and overlap queries, sensors with buffered events, declared capabilities and the typed capability error, and the module that steps worlds and writes body poses to transforms.
Guide: Physics worlds
Namespaces
Classes
The collision layers of the contract: 64 bits, any meaning the game gives them. A shape is in the layers of its Category and collides with the layers of its Mask; two shapes collide only when each one’s mask holds the other’s category.
A request needed a physics capability the backend does not declare (Capabilities). It is thrown before anything changes: the world is as it was.
The version of the 2D physics contract (IPhysicsWorld2D); a change to its rules raises it.
The physics module: registers a PhysicsSystem service and steps it in Physics (system SystemName), once per fixed step, after the simulation’s FixedUpdate.
Copies body poses to the transforms of the entities that own them.
Steps physics worlds, each optionally bound to the scene world whose entities own its bodies. A bound physics world steps only in the engine steps its scene world stepped in, by that world’s scaled step (Delta), so a paused, frozen or covered scene’s physics stands still too; after the step, the pose of every kinematic and dynamic body is written to its owner’s transform (WriteTransforms), which the scene world interpolates for drawing. An unbound world steps by the engine’s fixed step.
Structs
What CreateBody creates.
A body of an IPhysicsWorld2D: a slot index and the generation of the body that held the slot when the
id was made. A destroyed body’s slot is reused with a new generation, so an old id never reaches the new body.
default is None (generation 0 is never issued).
Two shapes began or stopped touching during the latest Step; only pairs with at least one dynamic body report them (a kinematic body’s contacts come from MoveResult).
The contacts of one MoveResult, stored inline (no allocation).
A surface a moving body touched (Contacts).
What Move did: where the body ended, how far it went, and every surface it was stopped by or touches at the end (within the backend’s Skin), each one with its normal. A kinematic body’s contacts and its ground come from here, never from ContactEvents.
Which shapes a query (RayCast, Overlap) or a
Move considers. A shape matches when its category is in the filter’s
Mask and the filter’s Category is in the shape’s mask. default is
Default: category Default, every layer, sensors left out.
The closest shape a ray hit (RayCast).
A shape entered or left a sensor during the latest Step. The ids and owners are copied when the event is made, so an exit caused by destroying a shape still names it.
What AddShape attaches to a body. Build one with Box (common) or a capability’s factory.
A shape of an IPhysicsWorld2D (a box, a tile grid, or a shape of a declared capability), attached to one
body. Generation-checked like BodyId; default is None.
Interfaces
A 2D physics world: bodies owned by entities, shapes with collision layers, kinematic collide-and-slide moves, ray and overlap queries, sensors, and a step. The members below are the common contract every backend passes (one conformance suite); everything else is a declared capability (Capabilities), and a request that needs an undeclared one throws PhysicsCapabilityException without changing the world.
Enums
How a body moves.
Whether a contact event is a begin or an end.
What a physics backend offers beyond the common contract of IPhysicsWorld2D. Every backend passes the common conformance suite; each flag it declares has a suite of its own that runs only on backends declaring it. A request that needs an undeclared flag fails with PhysicsCapabilityException: a backend never emulates a capability silently.
Whether a sensor event is an entry or an exit.
The geometry of a shape.