Skip to content

PhysicsServiceCollectionExtensions.AddPhysics(this IServiceCollection, Action) Method

Definition

Namespace: Brine2D.Physics

Adds Box2D physics services. Each scene scope gets its own PhysicsWorld.

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>(). Add the debug draw overlay with world.AddSystem<Box2DDebugDrawSystem>() — both are registered in DI by this call and 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>().