Class PhysicsComponentExtensions
Utility functions acting on physics components.
Inherited Members
Namespace: Unity.Physics.Extensions
Assembly: Unity.Physics.dll
Syntax
public static class PhysicsComponentExtensions
Methods
ApplyAngularImpulse(ref PhysicsVelocity, in PhysicsMass, float, in float3)
Applies the angular impulse.
Declaration
public static void ApplyAngularImpulse(this ref PhysicsVelocity velocityData, in PhysicsMass massData, float bodyScale, in float3 impulse)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | velocityData | [in,out] Information describing the velocity. |
PhysicsMass | massData | Information describing the mass. |
float | bodyScale | The body scale. |
float3 | impulse | The impulse. |
ApplyAngularImpulse(ref PhysicsVelocity, in PhysicsMass, in float3)
Applies the angular impulse.
Declaration
public static void ApplyAngularImpulse(this ref PhysicsVelocity velocityData, in PhysicsMass massData, in float3 impulse)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | velocityData | [in,out] Information describing the velocity. |
PhysicsMass | massData | Information describing the mass. |
float3 | impulse | The impulse. |
ApplyExplosionForce(ref PhysicsVelocity, in PhysicsMass, in PhysicsCollider, in float3, in quaternion, float, in float3, in float, in float, in float3, in float, ForceMode)
Converts a force into an impulse based on the force mode and the bodies mass and inertia properties. Equivalent to UnityEngine.Rigidbody.AddExplosionForce. ExplosionFilter is set to CollisionFilter.Default Assumes that there is no scale. ApplyExplosionForce(ref PhysicsVelocity, PhysicsMass, PhysicsCollider, float3, quaternion, float, float, float3, float, float, float3, CollisionFilter,float, ForceMode)
Declaration
public static void ApplyExplosionForce(this ref PhysicsVelocity bodyVelocity, in PhysicsMass bodyMass, in PhysicsCollider bodyCollider, in float3 bodyPosition, in quaternion bodyOrientation, float explosionForce, in float3 explosionPosition, in float explosionRadius, in float timestep, in float3 up, in float upwardsModifier = 0, ForceMode mode = ForceMode.Force)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | [in,out] The body velocity. |
PhysicsMass | bodyMass | The body mass. |
PhysicsCollider | bodyCollider | The body collider. |
float3 | bodyPosition | The body position. |
quaternion | bodyOrientation | The body orientation. |
float | explosionForce | The explosion force. |
float3 | explosionPosition | The explosion position. |
float | explosionRadius | The explosion radius. |
float | timestep | The timestep. |
float3 | up | The up. |
float | upwardsModifier | (Optional) The upwards modifier. |
ForceMode | mode | (Optional) The mode. |
ApplyExplosionForce(ref PhysicsVelocity, in PhysicsMass, in PhysicsCollider, in float3, in quaternion, in float, float, in float3, in float, in float, in float3, in CollisionFilter, in float, ForceMode)
Converts a force into an impulse based on the force mode and the bodies mass and inertia properties. Equivalent to UnityEngine.Rigidbody.AddExplosionForce.
Declaration
public static void ApplyExplosionForce(this ref PhysicsVelocity bodyVelocity, in PhysicsMass bodyMass, in PhysicsCollider bodyCollider, in float3 bodyPosition, in quaternion bodyOrientation, in float bodyScale, float explosionForce, in float3 explosionPosition, in float explosionRadius, in float timestep, in float3 up, in CollisionFilter explosionFilter, in float upwardsModifier = 0, ForceMode mode = ForceMode.Force)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | [in,out] The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component. |
PhysicsCollider | bodyCollider | The body's PhysicsCollider component. |
float3 | bodyPosition | The body's world-space position. |
quaternion | bodyOrientation | The body's world-space rotation. |
float | bodyScale | The body's world-space scale. |
float | explosionForce | The force of the explosion (which may be modified by distance). |
float3 | explosionPosition | The centre of the sphere within which the explosion has its effect. |
float | explosionRadius | The radius of the sphere within which the explosion has its effect. |
float | timestep | The change in time from the current to the next frame. |
float3 | up |
in the opposite direction to PhysicsStep.Gravity. |
CollisionFilter | explosionFilter | Filter determining whether an explosion should be applied to the body. |
float | upwardsModifier | (Optional) Adjustment to the apparent position of the explosion to make it seem to lift objects. |
ForceMode | mode | (Optional) The method used to apply the force to its targets. |
ApplyImpulse(ref PhysicsVelocity, in PhysicsMass, in float3, in quaternion, float, in float3, in float3)
Applies the impulse.
Declaration
public static void ApplyImpulse(this ref PhysicsVelocity pv, in PhysicsMass pm, in float3 t, in quaternion r, float bodyScale, in float3 impulse, in float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | pv | [in,out] The velocity. |
PhysicsMass | pm | The mass. |
float3 | t | The body position. |
quaternion | r | Tge body rotation. |
float | bodyScale | The body scale. |
float3 | impulse | The impulse. |
float3 | point | The point. |
ApplyImpulse(ref PhysicsVelocity, in PhysicsMass, in float3, in quaternion, in float3, in float3)
Applies the impulse.
Declaration
public static void ApplyImpulse(this ref PhysicsVelocity pv, in PhysicsMass pm, in float3 t, in quaternion r, in float3 impulse, in float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | pv | [in,out] The velocity. |
PhysicsMass | pm | The mass. |
float3 | t | The body position. |
quaternion | r | The body rotation. |
float3 | impulse | The impulse. |
float3 | point | The point. |
ApplyLinearImpulse(ref PhysicsVelocity, in PhysicsMass, float, in float3)
Applies the linear impulse.
Declaration
public static void ApplyLinearImpulse(this ref PhysicsVelocity velocityData, in PhysicsMass massData, float bodyScale, in float3 impulse)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | velocityData | [in,out] Information describing the velocity. |
PhysicsMass | massData | Information describing the mass. |
float | bodyScale | The body scale. |
float3 | impulse | The impulse. |
ApplyLinearImpulse(ref PhysicsVelocity, in PhysicsMass, in float3)
Applies the linear impulse.
Declaration
public static void ApplyLinearImpulse(this ref PhysicsVelocity velocityData, in PhysicsMass massData, in float3 impulse)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | velocityData | [in,out] Information describing the velocity. |
PhysicsMass | massData | Information describing the mass. |
float3 | impulse | The impulse. |
ApplyScale(in PhysicsMass, float)
Scale the mass of the body using provided scale.
Declaration
public static PhysicsMass ApplyScale(this in PhysicsMass pm, float uniformScale)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | pm | The body's PhysicsMass component. |
float | uniformScale | The body's uniform scale. If this value is approximately 1.0, the function will early-out with no effect. |
Returns
Type | Description |
---|---|
PhysicsMass | A body's physics mass with respect to it's scale. |
Remarks
Do not use this function to scale physics mass for simulation purposes, that is done automatically by physics systems. Use it if you need PhysicsMass in one of your functions if the body has a non-identity scale component, and do not write back this mass to the body's entity components.
GetAngularVelocityWorldSpace(in PhysicsVelocity, in PhysicsMass, in quaternion)
Get the world-space angular velocity of a rigid body.
Declaration
public static float3 GetAngularVelocityWorldSpace(this in PhysicsVelocity bodyVelocity, in PhysicsMass bodyMass, in quaternion bodyOrientation)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component. |
quaternion | bodyOrientation | The body's world-space rotation. |
Returns
Type | Description |
---|---|
float3 | The angular velocity of a rigid body in world space. |
GetCenterOfMassWorldSpace(in PhysicsMass, float, in float3, in quaternion)
Get the center of mass in world space.
Declaration
public static float3 GetCenterOfMassWorldSpace(this in PhysicsMass bodyMass, float bodyScale, in float3 bodyPosition, in quaternion bodyOrientation)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body's PhysicsMass component. |
float | bodyScale | The body's uniform scale. |
float3 | bodyPosition | The body's world-space position. |
quaternion | bodyOrientation | The body's world-space rotation. |
Returns
Type | Description |
---|---|
float3 | The center of mass in world space. |
GetCenterOfMassWorldSpace(in PhysicsMass, in float3, in quaternion)
Get the center of mass in world space. Assumes that there is no scale.
Declaration
public static float3 GetCenterOfMassWorldSpace(this in PhysicsMass bodyMass, in float3 bodyPosition, in quaternion bodyOrientation)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body mass. |
float3 | bodyPosition | The body position. |
quaternion | bodyOrientation | The body orientation. |
Returns
Type | Description |
---|---|
float3 | The center of mass world space. |
See Also
GetEffectiveMass(in PhysicsMass, in float3, in quaternion, in float, float3, float3)
Get a body's effective mass in a given direction and from a particular point in world space.
Declaration
public static float GetEffectiveMass(this in PhysicsMass bodyMass, in float3 bodyPosition, in quaternion bodyOrientation, in float bodyScale, float3 impulse, float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body's PhysicsMass component. |
float3 | bodyPosition | The body's world-space position. |
quaternion | bodyOrientation | The body's world-space rotation. |
float | bodyScale | The body's uniform scale. |
float3 | impulse | An impulse in world space. |
float3 | point | A point in world space. |
Returns
Type | Description |
---|---|
float | A body's effective mass with respect to the specified point and impulse. |
GetEffectiveMass(in PhysicsMass, in float3, in quaternion, float3, float3)
Get a body's effective mass in a given direction and from a particular point in world space.
Declaration
public static float GetEffectiveMass(this in PhysicsMass bodyMass, in float3 bodyPosition, in quaternion bodyOrientation, float3 impulse, float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body mass. |
float3 | bodyPosition | The body position. |
quaternion | bodyOrientation | The body orientation. |
float3 | impulse | The impulse. |
float3 | point | The point. |
Returns
Type | Description |
---|---|
float | A body's effective mass with respect to the specified point and impulse. |
Remarks
Assumes that there is no scale.
GetImpulseFromForce(in PhysicsMass, float, in float3, in ForceMode, in float, out float3, out PhysicsMass)
Converts a force into an impulse based on the force mode and the bodies mass and inertia properties, and scale.
Declaration
public static void GetImpulseFromForce(this in PhysicsMass bodyMass, float bodyScale, in float3 force, in ForceMode mode, in float timestep, out float3 impulse, out PhysicsMass impulseMass)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body's PhysicsMass component. |
float | bodyScale | The body's uniform scale. |
float3 | force | The force to be applied to a body. |
ForceMode | mode | The method used to apply the force to its targets. |
float | timestep | The change in time from the current to the next frame. |
float3 | impulse | [out] A returned impulse proportional to the provided 'force' and based on the supplied 'mode'. |
PhysicsMass | impulseMass | [out] A returned PhysicsMass component to be passed to an Apply function. |
GetImpulseFromForce(in PhysicsMass, in float3, in ForceMode, in float, out float3, out PhysicsMass)
Converts a force into an impulse based on the force mode and the bodies mass and inertia properties. Assumes that there is no scale. GetImpulseFromForce(in PhysicsMass, float, in float3, in ForceMode, in float, out float3, out PhysicsMass)
Declaration
public static void GetImpulseFromForce(this in PhysicsMass bodyMass, in float3 force, in ForceMode mode, in float timestep, out float3 impulse, out PhysicsMass impulseMass)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body mass. |
float3 | force | The force. |
ForceMode | mode | The mode. |
float | timestep | The timestep. |
float3 | impulse | [out] The impulse. |
PhysicsMass | impulseMass | [out] The impulse mass. |
GetLinearVelocity(in PhysicsVelocity, PhysicsMass, float3, quaternion, float3)
Get the linear velocity of a rigid body at a given point (in world space)
Declaration
public static float3 GetLinearVelocity(this in PhysicsVelocity bodyVelocity, PhysicsMass bodyMass, float3 bodyPosition, quaternion bodyOrientation, float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component. |
float3 | bodyPosition | The body's world-space position. |
quaternion | bodyOrientation | The body's world-space rotation. |
float3 | point | A reference position in world space. |
Returns
Type | Description |
---|---|
float3 | The linear velocity of a rigid body at a given point (in world space) |
Integrate(in PhysicsVelocity, in PhysicsMass, float, ref float3, ref quaternion)
Compute a future position and orientation for a dynamic rigid body based on its current trajectory, after a specified amount of time.
Declaration
public static void Integrate(this in PhysicsVelocity physicsVelocity, in PhysicsMass physicsMass, float timestep, ref float3 position, ref quaternion orientation)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | physicsVelocity | The body's PhysicsVelocity component. |
PhysicsMass | physicsMass | The body's PhysicsMass component. |
float | timestep | The change in time from the current to the next frame. |
float3 | position | [in,out] The future position of the body. |
quaternion | orientation | [in,out] The future orientation of the body. |
MakeUnique(ref PhysicsCollider, in Entity, EntityCommandBuffer)
Makes this collider unique if this is not already the case.
Declaration
public static void MakeUnique(this ref PhysicsCollider collider, in Entity entity, EntityCommandBuffer ecb)
Parameters
Type | Name | Description |
---|---|---|
PhysicsCollider | collider | The PhysicsCollider component representing the collider. |
Entity | entity | The entity which contains the PhysicsCollider component. |
EntityCommandBuffer | ecb | An entity command buffer, required for this operation. |
MakeUnique(ref PhysicsCollider, in Entity, ParallelWriter, int)
Makes this collider unique if this is not already the case. This function can be used in a job.
Declaration
public static void MakeUnique(this ref PhysicsCollider collider, in Entity entity, EntityCommandBuffer.ParallelWriter ecbParallelWriter, int sortKey)
Parameters
Type | Name | Description |
---|---|---|
PhysicsCollider | collider | The PhysicsCollider component representing the collider. |
Entity | entity | The entity which contains the PhysicsCollider component. |
EntityCommandBuffer.ParallelWriter | ecbParallelWriter | An entity command buffer's parallel writer, required for this operation. |
int | sortKey | A unique index required for adding a component through the provided |
MakeUnique(ref PhysicsCollider, in Entity, EntityManager)
Makes this collider unique if this is not already the case.
Declaration
public static void MakeUnique(this ref PhysicsCollider collider, in Entity entity, EntityManager entityManager)
Parameters
Type | Name | Description |
---|---|---|
PhysicsCollider | collider | The PhysicsCollider component representing the collider. |
Entity | entity | The entity which contains the PhysicsCollider component. |
EntityManager | entityManager | An entity manager, required for this operation. |
SetAngularVelocityWorldSpace(ref PhysicsVelocity, in PhysicsMass, in quaternion, in float3)
Set the world-space angular velocity of a rigid body.
Declaration
public static void SetAngularVelocityWorldSpace(this ref PhysicsVelocity bodyVelocity, in PhysicsMass bodyMass, in quaternion bodyOrientation, in float3 angularVelocity)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | [in,out] The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component. |
quaternion | bodyOrientation | The body's world-space rotation. |
float3 | angularVelocity | An angular velocity in world space specifying radians per second about each axis. |
SetCenterOfMassWorldSpace(ref PhysicsMass, in float3, in quaternion, float3)
Set the center of mass in world space.
Declaration
public static void SetCenterOfMassWorldSpace(this ref PhysicsMass bodyMass, in float3 bodyPosition, in quaternion bodyOrientation, float3 com)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | [in,out] The body's PhysicsMass component. |
float3 | bodyPosition | The body's world-space position. |
quaternion | bodyOrientation | The body's world-space rotation. |
float3 | com | A position in world space for the new Center Of Mass. |
ToMesh(in PhysicsCollider)
Converts a PhysicsCollider to a Mesh.
Declaration
public static Mesh ToMesh(this in PhysicsCollider collider)
Parameters
Type | Name | Description |
---|---|---|
PhysicsCollider | collider | The collider to convert to a mesh. |
Returns
Type | Description |
---|---|
Mesh | The created mesh. |