Class PhysicsWorld2D
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
settingsPhysicsStepSettingsOptional 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
SubStepCount
Box2D sub-step count passed to each world step.
public int SubStepCount { get; set; }
Property Value
TargetHz
Target simulation frequency in hertz used to derive the fixed step size.
public int TargetHz { get; set; }
Property Value
TimeScale
Multiplier applied to incoming delta time before fixed-step accumulation.
public float TimeScale { get; set; }
Property Value
WorkerCount
The number of solver worker threads the world was created with (1 = single-threaded).
public int WorkerCount { get; }
Property Value
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
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
deltaSecondsfloatElapsed real time in seconds since the last call.
perFixedStepAction<float>Optional callback invoked after each fixed step with the step duration.
beforeFixedStepAction<float>Optional callback invoked before each fixed step with the step duration.
Returns
- int
The number of fixed steps performed this call.