Class PhysicsComponentExtensions
Utility functions acting on physics components.
Inherited Members
Namespace: Unity.Physics.Extensions
Syntax
public static class PhysicsComponentExtensions
Methods
ApplyAngularImpulse(ref PhysicsVelocity, in PhysicsMass, Single, 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. |
Single | 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, Single, in float3, in Single, in Single, in float3, in Single, 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.
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 = 0F, 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. |
Single | explosionForce | The explosion force. |
float3 | explosionPosition | The explosion position. |
Single | explosionRadius | The explosion radius. |
Single | timestep | The timestep. |
float3 | up | The up. |
Single | upwardsModifier | (Optional) The upwards modifier. |
ForceMode | mode | (Optional) The mode. |
ApplyExplosionForce(ref PhysicsVelocity, in PhysicsMass, in PhysicsCollider, in float3, in quaternion, in Single, Single, in float3, in Single, in Single, in float3, in CollisionFilter, in Single, 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 = 0F, 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. |
Single | bodyScale | The body's world-space scale. |
Single | 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. |
Single | explosionRadius | The radius of the sphere within which the explosion has its effect. |
Single | 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. |
Single | 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, Single, 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. |
Single | 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, Single, 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. |
Single | 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, Single)
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. |
Single | 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, Single, 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. |
Single | 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 Single, 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. |
Single | bodyScale | The body's uniform scale. |
float3 | impulse | An impulse in world space. |
float3 | point | A point in world space. |
Returns
Type | Description |
---|---|
Single | 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 |
---|---|
Single | A body's effective mass with respect to the specified point and impulse. |
Remarks
Assumes that there is no scale.
GetImpulseFromForce(in PhysicsMass, Single, in float3, in ForceMode, in Single, 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. |
Single | 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. |
Single | 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 Single, 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, Single, in float3, in ForceMode, in Single, 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. |
Single | 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, Single, 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. |
Single | 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. |
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. |