Class PhysicsUtilities
Contains several physics-related utility functions
Inherited Members
Namespace: Unity.CharacterController
Syntax
public static class PhysicsUtilities
Methods
DoesBodyHavePhysicsVelocityAndMass(in PhysicsWorld, Int32)
Determines if a hit body index has mass and velocity components, simply based on PhysicsWorld information
Declaration
public static bool DoesBodyHavePhysicsVelocityAndMass(in PhysicsWorld physicsWorld, int rigidbodyIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| PhysicsWorld | physicsWorld | The Physics World of the body |
| Int32 | rigidbodyIndex | The body index |
Returns
| Type | Description |
|---|---|
| Boolean |
GetBodyComponents(in PhysicsWorld, Int32, out LocalTransform, out PhysicsVelocity, out PhysicsMass)
Reconstructs physics velocity and mass components for a specified body, based on information stored in the Physics World
Declaration
public static bool GetBodyComponents(in PhysicsWorld physicsWorld, int rigidbodyIndex, out LocalTransform transform, out PhysicsVelocity physicsVelocity, out PhysicsMass physicsMass)
Parameters
| Type | Name | Description |
|---|---|---|
| PhysicsWorld | physicsWorld | The physics world |
| Int32 | rigidbodyIndex | The rigidbody index |
| LocalTransform | transform | The body's transform |
| PhysicsVelocity | physicsVelocity | The body's physics velocity |
| PhysicsMass | physicsMass | The body's physics mass |
Returns
| Type | Description |
|---|---|
| Boolean | If the components were found successfully |
GetHitFaceNormal(RigidBody, ColliderKey, out float3)
Gets the face normal of a hit triangle in a collision mesh
Declaration
public static bool GetHitFaceNormal(RigidBody hitBody, ColliderKey colliderKey, out float3 faceNormal)
Parameters
| Type | Name | Description |
|---|---|---|
| RigidBody | hitBody | The hit body |
| ColliderKey | colliderKey | The hit collider key |
| float3 | faceNormal |
Returns
| Type | Description |
|---|---|
| Boolean |
GetKinematicCharacterPhysicsMass(KinematicCharacterProperties)
Builds a physics mass struct based on a character's mass properties
Declaration
public static PhysicsMass GetKinematicCharacterPhysicsMass(KinematicCharacterProperties characterProperties)
Parameters
| Type | Name | Description |
|---|---|---|
| KinematicCharacterProperties | characterProperties | The character properties component |
Returns
| Type | Description |
|---|---|
| PhysicsMass | The resulting physics mass |
GetKinematicCharacterPhysicsMass(StoredKinematicCharacterData)
Builds a physics mass struct based on a character's mass properties
Declaration
public static PhysicsMass GetKinematicCharacterPhysicsMass(StoredKinematicCharacterData storedCharacterData)
Parameters
| Type | Name | Description |
|---|---|---|
| StoredKinematicCharacterData | storedCharacterData | The character component that stores character data |
Returns
| Type | Description |
|---|---|
| PhysicsMass | The resulting physics mass |
HasPhysicsTag(Material, PhysicsCustomTags)
Determines if the specified physics material has a given physics material tag
Declaration
public static bool HasPhysicsTag(Material hitMaterial, PhysicsCustomTags tag)
Parameters
| Type | Name | Description |
|---|---|---|
| Material | hitMaterial | The hit physics body material |
| PhysicsCustomTags | tag | The physics material tag to check for |
Returns
| Type | Description |
|---|---|
| Boolean |
HasPhysicsTag(in PhysicsWorld, Int32, CustomPhysicsBodyTags)
Determines if the specified physics body has a given physics body tag
Declaration
public static bool HasPhysicsTag(in PhysicsWorld physicsWorld, int bodyIndex, CustomPhysicsBodyTags tag)
Parameters
| Type | Name | Description |
|---|---|---|
| PhysicsWorld | physicsWorld | The Physics World of the body |
| Int32 | bodyIndex | The body index |
| CustomPhysicsBodyTags | tag | The physics body tag to check for |
Returns
| Type | Description |
|---|---|
| Boolean |
IsBodyDynamic(in PhysicsWorld, Int32)
Determines if a body is dynamic
Declaration
public static bool IsBodyDynamic(in PhysicsWorld physicsWorld, int rigidbodyIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| PhysicsWorld | physicsWorld | The Physics World of the body |
| Int32 | rigidbodyIndex | The body index |
Returns
| Type | Description |
|---|---|
| Boolean |
IsCollidable(in Material)
Determines if the physics material has a collideable collision response
Declaration
public static bool IsCollidable(in Material material)
Parameters
| Type | Name | Description |
|---|---|---|
| Material | material | The physics material |
Returns
| Type | Description |
|---|---|
| Boolean |
SetCollisionResponse(RigidBody, ColliderKey, CollisionResponsePolicy)
Sets a collider's collision response
Declaration
public static bool SetCollisionResponse(RigidBody rigidBody, ColliderKey colliderKey, CollisionResponsePolicy collisionResponse)
Parameters
| Type | Name | Description |
|---|---|---|
| RigidBody | rigidBody | The rigidbody to change |
| ColliderKey | colliderKey | The collider key representing the collider to change |
| CollisionResponsePolicy | collisionResponse | The desired collision response |
Returns
| Type | Description |
|---|---|
| Boolean |
SetCollisionResponse(RigidBody, CollisionResponsePolicy)
Sets a collider's collision response
Declaration
public static void SetCollisionResponse(RigidBody rigidBody, CollisionResponsePolicy collisionResponse)
Parameters
| Type | Name | Description |
|---|---|---|
| RigidBody | rigidBody | The rigidbody to change |
| CollisionResponsePolicy | collisionResponse | The desired collision response |
SolveCollisionImpulses(in PhysicsVelocity, in PhysicsVelocity, in PhysicsMass, in PhysicsMass, in RigidTransform, in RigidTransform, float3, float3, out float3, out float3)
Solves a collision between two bodies and outputs the impulses to apply on each body
Declaration
public static void SolveCollisionImpulses(in PhysicsVelocity physicsVelA, in PhysicsVelocity physicsVelB, in PhysicsMass physicsMassA, in PhysicsMass physicsMassB, in RigidTransform transformA, in RigidTransform transformB, float3 collisionPoint, float3 collisionNormalBToA, out float3 impulseOnA, out float3 impulseOnB)
Parameters
| Type | Name | Description |
|---|---|---|
| PhysicsVelocity | physicsVelA | Body A's physics velocity |
| PhysicsVelocity | physicsVelB | Body B's physics velocity |
| PhysicsMass | physicsMassA | Body A's physics mass |
| PhysicsMass | physicsMassB | Body B's physics mass |
| RigidTransform | transformA | Body A's transform |
| RigidTransform | transformB | Body B's transform |
| float3 | collisionPoint | The collision point between the two bodies |
| float3 | collisionNormalBToA | The collision normal, from body B towards body A |
| float3 | impulseOnA | The impulse to apply on body A |
| float3 | impulseOnB | The impulse to apply on body B |