Table of Contents

Class Box2DStrideBridge

Namespace
Stride.CommunityToolkit.Box2D
Assembly
Stride.CommunityToolkit.Box2D.dll

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

world PhysicsWorld2D

The 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

position Vector3

Initial world position (Z is ignored).

type B2BodyType

The Box2D body type.

rotation float

Initial 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

entity Entity

The entity driven by the body.

position Vector3

Initial world position (Z is ignored).

type B2BodyType

The Box2D body type.

rotation float

Initial 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

entity Entity

The 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

bodyId B2BodyId

The body to look up.

Returns

Entity

RemoveBody(Entity)

Destroys the body associated with entity and forgets the mapping, if present.

public void RemoveBody(Entity entity)

Parameters

entity Entity

The 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()