Table of Contents

Class PhysicsWorld2D

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

Engine-agnostic 2D physics world wrapper around Box2D.NET: owns the native world and advances it on a fixed timestep. It deliberately avoids any dependency on Stride Entity types; pairing bodies with entities is Box2DStrideBridge's job.

public sealed class PhysicsWorld2D : IDisposable
Inheritance
PhysicsWorld2D
Implements

Constructors

PhysicsWorld2D(PhysicsStepSettings?)

Creates a new physics world with default gravity (0, -10).

public PhysicsWorld2D(PhysicsStepSettings? settings = null)

Parameters

settings PhysicsStepSettings

Optional stepping configuration; defaults to PhysicsStepSettings defaults.

Properties

MaxStepsPerFrame

Maximum number of fixed steps processed per frame, to avoid the spiral of death.

public int MaxStepsPerFrame { get; set; }

Property Value

int

SubStepCount

Box2D sub-step count passed to each world step.

public int SubStepCount { get; set; }

Property Value

int

TargetHz

Target simulation frequency in hertz used to derive the fixed step size.

public int TargetHz { get; set; }

Property Value

int

TimeScale

Multiplier applied to incoming delta time before fixed-step accumulation.

public float TimeScale { get; set; }

Property Value

float

WorkerCount

The number of solver worker threads the world was created with (1 = single-threaded).

public int WorkerCount { get; }

Property Value

int

WorldId

Gets the native world id.

public B2WorldId WorldId { get; }

Property Value

B2WorldId

Methods

Dispose()

Disposes the underlying Box2D world.

public void Dispose()

SetGravity(float, float)

Adjusts global gravity.

public void SetGravity(float x, float y)

Parameters

x float

Gravity along the X axis.

y float

Gravity along the Y axis (negative pulls down).

Step(float, Action<float>?, Action<float>?)

Advances the simulation using a fixed-timestep accumulator strategy.

public int Step(float deltaSeconds, Action<float>? perFixedStep = null, Action<float>? beforeFixedStep = null)

Parameters

deltaSeconds float

Elapsed real time in seconds since the last call.

perFixedStep Action<float>

Optional callback invoked after each fixed step with the step duration.

beforeFixedStep Action<float>

Optional callback invoked before each fixed step with the step duration.

Returns

int

The number of fixed steps performed this call.