Class Box2DStrideBridge
Bridge responsible for mapping Box2D bodies to Stride entities and synchronizing transforms. This isolates engine-specific concerns away from the engine-agnostic PhysicsWorld2D.
public sealed class Box2DStrideBridge
- Inheritance
-
Box2DStrideBridge
Constructors
Box2DStrideBridge(PhysicsWorld2D)
Creates a bridge for the given world.
public Box2DStrideBridge(PhysicsWorld2D world)
Parameters
worldPhysicsWorld2DThe physics world bodies are created in.
Properties
Bodies
All body ids currently mapped to an entity.
public IEnumerable<B2BodyId> Bodies { get; }
Property Value
- IEnumerable<B2BodyId>
Methods
CreateBody(Vector3, B2BodyType, float)
Creates a body of the given type at a world position, without an associated entity.
public B2BodyId CreateBody(Vector3 position, B2BodyType type, float rotation = 0)
Parameters
positionVector3Initial world position (Z is ignored).
typeB2BodyTypeThe Box2D body type.
rotationfloatInitial rotation in radians about the Z axis.
Returns
- B2BodyId
The id of the created body.
CreateBody(Entity, Vector3, B2BodyType, float)
Creates a body of the given type at a world position and associates it with an entity, so SyncTransformsFromPhysics() keeps the entity transform in step with the body.
public B2BodyId CreateBody(Entity entity, Vector3 position, B2BodyType type, float rotation = 0)
Parameters
entityEntityThe entity driven by the body.
positionVector3Initial world position (Z is ignored).
typeB2BodyTypeThe Box2D body type.
rotationfloatInitial rotation in radians about the Z axis.
Returns
- B2BodyId
The id of the created body.
GetBody(Entity)
Gets the body registered for the given entity, or null.
public B2BodyId? GetBody(Entity entity)
Parameters
entityEntityThe entity to look up.
Returns
- B2BodyId?
GetEntity(B2BodyId)
Gets the entity registered for the given body id, or null.
public Entity? GetEntity(B2BodyId bodyId)
Parameters
bodyIdB2BodyIdThe body to look up.
Returns
RemoveBody(Entity)
Destroys the body associated with entity and forgets the mapping, if present.
public void RemoveBody(Entity entity)
Parameters
entityEntityThe entity whose body should be removed.
SyncTransformsFromPhysics()
Synchronizes Stride entity transforms from physics body positions and rotations. Call after each fixed step.
public void SyncTransformsFromPhysics()