Class PhysicsManager
Inheritance
Namespace: Motphys.Rigidbody
Assembly: solution.dll
Syntax
public static class PhysicsManager
Fields
DefaultRaycastLayers
Declaration
public const int DefaultRaycastLayers = default(int)
Field Value
Type | Description |
---|---|
System.Int32 | Ignore raycast is layer2 in unity. That means the layer mask of all layers without layer2 is 0xFFFFFFFB, which is -5 in decimal. |
Properties
allowExpandSpeculativeMargin
Declaration
public static bool allowExpandSpeculativeMargin { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | If true, the engine will use speculative margin to improve the potential collision detection accuracy. |
defaultContactOffset
Declaration
public static float defaultContactOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The default contact offset for newly created colliders. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | contactOffset must be greater than separationOffset |
defaultSeparationOffset
Declaration
public static float defaultSeparationOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The default separation offset for newly created colliders. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | separationOffset must be less than contactOffset |
defaultSolverIterations
Declaration
public static uint defaultSolverIterations { get; set; }
Property Value
Type | Description |
---|---|
System.UInt32 | The default number of position solver iterations for all constraints in each substep. Increase the number of solver iterations will improve the stability and accuracy of the simulation but will also increase the computation cost. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | numSolverIter must be greater than 0 |
defaultSolverVelocityIterations
Declaration
public static uint defaultSolverVelocityIterations { get; set; }
Property Value
Type | Description |
---|---|
System.UInt32 | The default number of velocity solver iterations for all constraints in each substep. Increase the number of solver iterations will get more accurate simulation about bouncing and dynamic friction. |
gravity
Declaration
public static Vector3 gravity { get; set; }
Property Value
Type | Description |
---|---|
Vector3 | The gravity of the default physics world. |
isContactEventOn
Declaration
public static bool isContactEventOn { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | If false, collision event will not work, such as OnCollisionEnter and so on. |
isSceneQueryOn
Declaration
public static bool isSceneQueryOn { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | If false, raycast and overlap test will not work. |
numSubstep
Declaration
public static uint numSubstep { get; set; }
Property Value
Type | Description |
---|---|
System.UInt32 | The number of substeps per physics step. Improve the numSubstep will improve the stability and accuracy of the simulation but will also increase the computation cost. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | numSubstep must be greater than 0 |
simulationMode
Declaration
public static SimulationMode simulationMode { get; set; }
Property Value
Type | Description |
---|---|
SimulationMode | The simulation mode of the default physics world. |
visualizeDataMask
Declaration
public static VisualizeDataType visualizeDataMask { get; set; }
Property Value
Type | Description |
---|---|
VisualizeDataType | The visualize data mask, used for drawing gizmos. |
Methods
CheckBox(Vector3, Vector3, out BaseCollider, Quaternion, Int32, Boolean, SceneQueryFlags)
Test whether there is an object intersecting the given box in the scene.
Declaration
public static bool CheckBox(Vector3 center, Vector3 halfExtents, out BaseCollider result, Quaternion orientation, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | center | Center of the given box. |
Vector3 | halfExtents | Half the size of the given box. |
BaseCollider | result | The object that intersect the given box. |
Quaternion | orientation | Rotation of the given box. |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.Boolean | True if an object intersects the given box |
CheckCapsule(Vector3, Vector3, Single, out BaseCollider, Int32, Boolean, SceneQueryFlags)
Test whether there is an object intersecting the given capsule in the scene.
Declaration
public static bool CheckCapsule(Vector3 point0, Vector3 point1, float radius, out BaseCollider result, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point0 | The center of the sphere at the start of the capsule. |
Vector3 | point1 | The center of the sphere at the end of the capsule. |
System.Single | radius | The radius of the capsule. |
BaseCollider | result | The object that intersect the given capsule. |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.Boolean | True if an object intersects the given capsule |
CheckSphere(Vector3, Single, out BaseCollider, Int32, Boolean, SceneQueryFlags)
Test whether there is an object intersecting the given sphere in the scene.
Declaration
public static bool CheckSphere(Vector3 center, float radius, out BaseCollider result, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | center | Center of the given sphere. |
System.Single | radius | |
BaseCollider | result | The object that intersect the given sphere. |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.Boolean | True if an object intersects the given sphere |
IgnoreLayerCollision(Int32, Int32, Boolean)
Ignore all collisions between any collider in layerA and any collider in layerB. It does not affect the generated colliders temporarily.
Declaration
public static bool IgnoreLayerCollision(int layerA, int layerB, bool ignore = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | layerA | Valid layer is in [0, 31] |
System.Int32 | layerB | Valid layer is in [0, 31] |
System.Boolean | ignore |
Returns
Type | Description |
---|---|
System.Boolean | Return false if the input layer is invalid |
OverlapBoxNonAlloc(Vector3, Vector3, BaseCollider[], Quaternion, Int32, Boolean, SceneQueryFlags)
Find objects that intersect with the given box and write the overlaps to results
, and report up to 2048 results
Declaration
public static uint OverlapBoxNonAlloc(Vector3 center, Vector3 halfExtents, BaseCollider[] results, Quaternion orientation, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | center | Center of the given box. |
Vector3 | halfExtents | Half the size of the given box. |
BaseCollider[] | results | All objects that intersect the given box. |
Quaternion | orientation | Rotation of the given box. |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.UInt32 | The number of objects intersecting the given box |
OverlapCapsuleNonAlloc(Vector3, Vector3, Single, BaseCollider[], Int32, Boolean, SceneQueryFlags)
Find objects that intersect with the given capsule and write the overlaps to results
, and report up to 2048 results
Declaration
public static uint OverlapCapsuleNonAlloc(Vector3 point0, Vector3 point1, float radius, BaseCollider[] results, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point0 | The center of the sphere at the start of the capsule. |
Vector3 | point1 | The center of the sphere at the end of the capsule. |
System.Single | radius | The radius of the capsule. |
BaseCollider[] | results | All objects that intersect the given capsule. |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.UInt32 | The number of objects intersecting the given capsule |
OverlapSphereNonAlloc(Vector3, Single, BaseCollider[], Int32, Boolean, SceneQueryFlags)
Find objects that intersect with the given sphere and write the overlaps to results
, and report up to 2048 results
Declaration
public static uint OverlapSphereNonAlloc(Vector3 center, float radius, BaseCollider[] results, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | center | Center of the given sphere. |
System.Single | radius | |
BaseCollider[] | results | All objects that intersect the given sphere. |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.UInt32 | The number of objects intersecting the given sphere |
RaycastAllNonAlloc(Vector3, Vector3, RaycastHit[], Single, Int32, Boolean, SceneQueryFlags)
Casts a ray against the scene and write the hits to results
, and report up to 2048 results
Declaration
public static uint RaycastAllNonAlloc(Vector3 origin, Vector3 direction, RaycastHit[] results, float maxDistance = 3.40282347E+38F, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | origin | The starting position of the ray. |
Vector3 | direction | The direction of the ray. |
RaycastHit[] | results | If the ray hit something, |
System.Single | maxDistance | Hits further than |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.UInt32 | Number of hits |
RaycastAny(Vector3, Vector3, out RaycastHit, Single, Int32, Boolean, SceneQueryFlags)
Casts a ray against the scene and immediately returns a hit, if any object is hit. The hit is not guaranteed to be the closest.
Declaration
public static bool RaycastAny(Vector3 origin, Vector3 direction, out RaycastHit hit, float maxDistance = 3.40282347E+38F, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | origin | The starting position of the ray. |
Vector3 | direction | The direction of the ray. |
RaycastHit | hit | If the ray hit something, |
System.Single | maxDistance | Hits further than |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.Boolean | Whether an object was hit by the ray |
Examples
PhysicsManager.RaycastAny(new Vector3(0.0f, 0.0,f 0.0f), new Vector3(0.0f, 0.0,f 1.0f), out RaycastHit hit, 100.0f, -1, true, SceneQueryFlags.All);
RaycastClosest(Vector3, Vector3, out RaycastHit, Single, Int32, Boolean, SceneQueryFlags)
Casts a ray against the scene and return the closest hit.
Declaration
public static bool RaycastClosest(Vector3 origin, Vector3 direction, out RaycastHit hit, float maxDistance = 3.40282347E+38F, int layerMask = default(int), bool queryTrigger = true, SceneQueryFlags sceneQueryFlags = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | origin | The starting position of the ray. |
Vector3 | direction | The direction of the ray. |
RaycastHit | hit |
|
System.Single | maxDistance | Hits further than |
System.Int32 | layerMask | The target layers to query |
System.Boolean | queryTrigger | Whether the trigger should be reported. |
SceneQueryFlags | sceneQueryFlags | What type of object should be reported |
Returns
Type | Description |
---|---|
System.Boolean | Whether an object was hit by the ray |
Examples
PhysicsManager.RaycastClosest(new Vector3(0.0f, 0.0,f 0.0f), new Vector3(0.0f, 0.0,f 1.0f), out RaycastHit hit, 100.0f, -1, true, SceneQueryFlags.All);
RequestVisualizeDataOnce(VisualizeDataType, Action<VisualizeData>)
Register a callback to receive visualize data. The callback will be called once after a step complete. The requested data type should be configured in the dataFilter.
Declaration
public static void RequestVisualizeDataOnce(VisualizeDataType dataFilter, Action<VisualizeData> callback)
Parameters
Type | Name | Description |
---|---|---|
VisualizeDataType | dataFilter | |
System.Action<VisualizeData> | callback |
Simulate(Single)
Manually step the physics engine with a given time step
Declaration
public static void Simulate(float deltaTimeSeconds)
Parameters
Type | Name | Description |
---|---|---|
System.Single | deltaTimeSeconds | the advanced delta time |
Events
onCollisionEnter
The global "OnCollisionEnter" event onCollisionEnter
Declaration
public static event Action<CollisionEvent> onCollisionEnter
Event Type
Type | Description |
---|---|
System.Action<CollisionEvent> |
onCollisionExit
The global "OnCollisionExit" event onCollisionExit
Declaration
public static event Action<CollisionEvent> onCollisionExit
Event Type
Type | Description |
---|---|
System.Action<CollisionEvent> |
onCollisionStay
The global "OnCollisionStay" event onCollisionStay
Declaration
public static event Action<CollisionEvent> onCollisionStay
Event Type
Type | Description |
---|---|
System.Action<CollisionEvent> |
onPostUpdate
The event after each engine update.
Declaration
public static event Action onPostUpdate
Event Type
Type | Description |
---|---|
System.Action |
onPreUpdate
The event before each engine update.
Declaration
public static event Action onPreUpdate
Event Type
Type | Description |
---|---|
System.Action |
onSleepDown
The global "rigidbody sleep down" event
Declaration
public static event Action<Rigidbody3D> onSleepDown
Event Type
Type | Description |
---|---|
System.Action<Rigidbody3D> |
onTriggerEnter
The global "OnTriggerEnter" event onTriggerEnter
Declaration
public static event Action<TriggerEvent> onTriggerEnter
Event Type
Type | Description |
---|---|
System.Action<TriggerEvent> |
onTriggerExit
The global "OnTriggerExit" event onTriggerExit
Declaration
public static event Action<TriggerEvent> onTriggerExit
Event Type
Type | Description |
---|---|
System.Action<TriggerEvent> |
onTriggerStay
The global "OnTriggerStay" event onTriggerStay
Declaration
public static event Action<TriggerEvent> onTriggerStay
Event Type
Type | Description |
---|---|
System.Action<TriggerEvent> |
onWakeUp
The global "rigidbody wake up" event.
Declaration
public static event Action<Rigidbody3D> onWakeUp
Event Type
Type | Description |
---|---|
System.Action<Rigidbody3D> |
requestMetrics
Register a callback to receive metrics data once after step.
Declaration
public static event Action<StepMetrics> requestMetrics
Event Type
Type | Description |
---|---|
System.Action<StepMetrics> |