PhysicsServiceCollectionExtensions.AddPhysics(this IServiceCollection, Action) Method
Definition
Namespace: Brine2D.Physics
Configures Box2D physics \(gravity, layers, thresholds, filters\). PhysicsWorld
and the default physics systems are always registered by AddBrine2D
\(see [AddPhysicsCore\(this IServiceCollection\)](AddPhysicsCore(thisIServiceCollection).md 'Brine2D.Physics.PhysicsServiceCollectionExtensions.AddPhysicsCore\(this Microsoft\.Extensions\.DependencyInjection\.IServiceCollection\)')) — this call is purely about configuration, not existence.
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPhysics(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Brine2D.Physics.PhysicsOptions>? configure=null);
Parameters
services Microsoft.Extensions.DependencyInjection.IServiceCollection
configure System.Action<PhysicsOptions>
Returns
Microsoft.Extensions.DependencyInjection.IServiceCollection
Remarks
Add simulation to a scene with world.AddSystem<Box2DPhysicsSystem>() —
this is already done automatically as a default system unless excluded via
builder.ExcludeDefaultSystem<Box2DPhysicsSystem>().
Add the debug draw overlay with world.AddSystem<Box2DDebugDrawSystem>();
both are zero-cost when not added as systems.
PixelsPerMeter maps to B2.SetLengthUnitsPerMeter,
which is a process-wide global. All AddPhysics registrations across the
entire application must use the same value.
Use AddPhysicsLayers\(this IServiceCollection, Action<PhysicsLayerRegistry>\) to register named physics layers before building bodies. The PhysicsLayerRegistry singleton is available via DI throughout the application.
Add the kinematic character controller to a scene with
world.AddSystem<PrePhysicsKinematicCharacterSystem>() and
world.AddSystem<PostPhysicsKinematicCharacterSystem>().