Table of Contents

Class Simulation

Namespace
Stride.Physics
Assembly
Stride.Physics.dll
public class Simulation : IDisposable
Inheritance
Simulation
Implements
Extension Methods

Fields

DisableSimulation

Totally disable the simulation if set to true

public static bool DisableSimulation

Field Value

bool

OnSimulationCreation

Temporary solution to inject engine flags

public static Simulation.OnSimulationCreationDelegate OnSimulationCreation

Field Value

Simulation.OnSimulationCreationDelegate

Properties

ColliderShapesRenderGroup

public RenderGroup ColliderShapesRenderGroup { get; set; }

Property Value

RenderGroup

ColliderShapesRendering

Enables or disables the rendering of collider shapes

public bool ColliderShapesRendering { set; }

Property Value

bool

ContinuousCollisionDetection

public bool ContinuousCollisionDetection { get; set; }

Property Value

bool

CurrentCollisions

Every pair of components currently colliding with each other

public ICollection<Collision> CurrentCollisions { get; }

Property Value

ICollection<Collision>

FixedTimeStep

By decreasing the size of fixedTimeStep, you are increasing the “resolution” of the simulation. Default is 1.0f / 60.0f or 60fps

public float FixedTimeStep { get; set; }

Property Value

float

Gravity

Gets or sets the gravity.

public Vector3 Gravity { get; set; }

Property Value

Vector3

The gravity.

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly

IncludeStaticAgainstStaticCollisions

Should static - static collisions of StaticColliderComponent yield PhysicsComponent.NewCollision() and added to PhysicsComponent.Collisions ?

public bool IncludeStaticAgainstStaticCollisions { get; set; }

Property Value

bool

Remarks

Regardless of the state of this value you can still retrieve static-static collisions through CurrentCollisions.

MaxSubSteps

The maximum number of steps that the Simulation is allowed to take each tick. If the engine is running slow (large deltaTime), then you must increase the number of maxSubSteps to compensate for this, otherwise your simulation is “losing” time. It's important that frame DeltaTime is always less than MaxSubSteps*FixedTimeStep, otherwise you are losing time.

[Obsolete("Value is ignored, use MaxTickDuration instead")]
public int MaxSubSteps { get; set; }

Property Value

int

MaxTickDuration

public float MaxTickDuration { get; set; }

Property Value

float

SpeculativeContactRestitution

public bool SpeculativeContactRestitution { get; set; }

Property Value

bool

Methods

AddConstraint(Constraint)

Adds the constraint to the engine processing pipeline.

public void AddConstraint(Constraint constraint)

Parameters

constraint Constraint

The constraint.

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly

AddConstraint(Constraint, bool)

Adds the constraint to the engine processing pipeline.

public void AddConstraint(Constraint constraint, bool disableCollisionsBetweenLinkedBodies)

Parameters

constraint Constraint

The constraint.

disableCollisionsBetweenLinkedBodies bool

if set to true [disable collisions between linked bodies].

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly

ClearForces()

public void ClearForces()

CreateConstraint(ConstraintTypes, RigidbodyComponent, Matrix, bool)

Creates the constraint.

public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA = false)

Parameters

type ConstraintTypes

The type.

rigidBodyA RigidbodyComponent

The rigid body a.

frameA Matrix

The frame a.

useReferenceFrameA bool

if set to true [use reference frame a].

Returns

Constraint

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid or A Gear constraint always needs two rigidbodies to be created.

CreateConstraint(ConstraintTypes, RigidbodyComponent, RigidbodyComponent, Matrix, Matrix, bool)

Creates the constraint.

public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA = false)

Parameters

type ConstraintTypes

The type.

rigidBodyA RigidbodyComponent

The rigid body a.

rigidBodyB RigidbodyComponent

The rigid body b.

frameA Matrix

The frame a.

frameB Matrix

The frame b.

useReferenceFrameA bool

if set to true [use reference frame a].

Returns

Constraint

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid

CreateHingeConstraint(RigidbodyComponent, Vector3, Vector3, RigidbodyComponent, Vector3, Vector3, bool)

Creates a hinge constraint using a specialized constructor.

public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, RigidbodyComponent rigidBodyB, Vector3 pivotInB, Vector3 axisInB, bool useReferenceFrameA = false)

Parameters

rigidBodyA RigidbodyComponent

The rigid body a.

pivotInA Vector3

Pivot point in body a.

axisInA Vector3

Axis in body a.

rigidBodyB RigidbodyComponent

The rigid body b.

pivotInB Vector3

Pivot point in body b.

axisInB Vector3

Axis in body b.

useReferenceFrameA bool

if set to true [use reference frame a].

Returns

HingeConstraint

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly or Both RigidBodies must be valid

CreateHingeConstraint(RigidbodyComponent, Vector3, Vector3, bool)

Creates a hinge constraint using a specialized constructor.

public static HingeConstraint CreateHingeConstraint(RigidbodyComponent rigidBodyA, Vector3 pivotInA, Vector3 axisInA, bool useReferenceFrameA = false)

Parameters

rigidBodyA RigidbodyComponent

The rigid body a.

pivotInA Vector3

Pivot point in body a.

axisInA Vector3

Axis in body a.

useReferenceFrameA bool

if set to true [use reference frame a].

Returns

HingeConstraint

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly or RigidBody must be valid

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

OnSimulationBegin(SimulationArgs)

protected virtual void OnSimulationBegin(Simulation.SimulationArgs e)

Parameters

e Simulation.SimulationArgs

OnSimulationEnd(SimulationArgs)

protected virtual void OnSimulationEnd(Simulation.SimulationArgs e)

Parameters

e Simulation.SimulationArgs

Raycast(Vector3, Vector3, CollisionFilterGroups, CollisionFilterGroupFlags, bool, EFlags)

Raycasts and returns the closest hit

public HitResult Raycast(Vector3 from, Vector3 to, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false, EFlags eFlags = EFlags.None)

Parameters

from Vector3

The starting point of this raycast

to Vector3

The end point of this raycast

filterGroup CollisionFilterGroups

The collision group of this raycast

filterFlags CollisionFilterGroupFlags

The collision group that this raycast can collide with

hitTriggers bool

Whether this test should collide with PhysicsTriggerComponentBase

eFlags EFlags

Flags that control how this ray test is performed

Returns

HitResult

The result of this test

Raycast(Vector3, Vector3, out HitResult, CollisionFilterGroups, CollisionFilterGroupFlags, bool, EFlags)

Raycasts, returns true when it hit something

public bool Raycast(Vector3 from, Vector3 to, out HitResult result, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false, EFlags eFlags = EFlags.None)

Parameters

from Vector3

The starting point of this raycast

to Vector3

The end point of this raycast

result HitResult

Information about this test

filterGroup CollisionFilterGroups

The collision group of this raycast

filterFlags CollisionFilterGroupFlags

The collision group that this raycast can collide with

hitTriggers bool

Whether this test should collide with PhysicsTriggerComponentBase

eFlags EFlags

Flags that control how this ray test is performed

Returns

bool

True if the test collided with an object in the simulation

RaycastPenetrating(Vector3, Vector3, ICollection<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags, bool, EFlags)

Raycasts penetrating any shape the ray encounters. Filtering by CollisionGroup

public void RaycastPenetrating(Vector3 from, Vector3 to, ICollection<HitResult> resultsOutput, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false, EFlags eFlags = EFlags.None)

Parameters

from Vector3

The starting point of this raycast

to Vector3

The end point of this raycast

resultsOutput ICollection<HitResult>

The collection to add intersections to

filterGroup CollisionFilterGroups

The collision group of this raycast

filterFlags CollisionFilterGroupFlags

The collision group that this raycast can collide with

hitTriggers bool

Whether this test should collide with PhysicsTriggerComponentBase

eFlags EFlags

Flags that control how this ray test is performed

RemoveConstraint(Constraint)

Removes the constraint from the engine processing pipeline.

public void RemoveConstraint(Constraint constraint)

Parameters

constraint Constraint

The constraint.

Exceptions

Exception

Cannot perform this action when the physics engine is set to CollisionsOnly

ShapeSweep(ColliderShape, Matrix, Matrix, CollisionFilterGroups, CollisionFilterGroupFlags, bool)

Performs a sweep test using a collider shape and returns the closest hit

public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false)

Parameters

shape ColliderShape

The shape used when testing collisions with colliders in the simulation

from Matrix

The starting point of this sweep

to Matrix

The end point of this sweep

filterGroup CollisionFilterGroups

The collision group of this shape sweep

filterFlags CollisionFilterGroupFlags

The collision group that this shape sweep can collide with

hitTriggers bool

Whether this test should collide with PhysicsTriggerComponentBase

Returns

HitResult

The result of this test

Exceptions

ArgumentException

This kind of shape cannot be used for a ShapeSweep.

ShapeSweepPenetrating(ColliderShape, Matrix, Matrix, ICollection<HitResult>, CollisionFilterGroups, CollisionFilterGroupFlags, bool)

Performs a sweep test using a collider shape and never stops until "to"

public void ShapeSweepPenetrating(ColliderShape shape, Matrix from, Matrix to, ICollection<HitResult> resultsOutput, CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterFlags = (CollisionFilterGroupFlags)-1, bool hitTriggers = false)

Parameters

shape ColliderShape

The shape against which colliders in the simulation will be tested

from Matrix

The starting point of this sweep

to Matrix

The end point of this sweep

resultsOutput ICollection<HitResult>

The collection to add hit results to

filterGroup CollisionFilterGroups

The collision group of this shape sweep

filterFlags CollisionFilterGroupFlags

The collision group that this shape sweep can collide with

hitTriggers bool

Whether this test should collide with PhysicsTriggerComponentBase

Exceptions

ArgumentException

This kind of shape cannot be used for a ShapeSweep.

Events

PostTick

Called right after processing a tick of the physics simulation, this may never occur before many updates, or occur multiple times between updates depending on this Simulation properties

public event Simulation.SimulationTickEvent PostTick

Event Type

Simulation.SimulationTickEvent

PreTick

Called right before processing a tick of the physics simulation, this may never occur before many updates, or occur multiple times between updates depending on this Simulation properties

public event Simulation.SimulationTickEvent PreTick

Event Type

Simulation.SimulationTickEvent

SimulationBegin

Called before the physics simulation. This event might not be fired by the main thread.

[Obsolete("The simulation is not guaranteed to tick following this call, use PreTick instead. This is the same thing as Update")]
public event EventHandler<Simulation.SimulationArgs> SimulationBegin

Event Type

EventHandler<Simulation.SimulationArgs>

SimulationEnd

Called after the physics simulation. This event might not be fired by the main thread.

[Obsolete("The simulation is not guaranteed to have ticked before this call, use PostTick instead. This is the same thing as Update")]
public event EventHandler<Simulation.SimulationArgs> SimulationEnd

Event Type

EventHandler<Simulation.SimulationArgs>