Class PhysicsComponentExtensions
Utility functions acting on physics components.
Namespace: Unity.Physics.Extensions
Syntax
public static class PhysicsComponentExtensions
Methods
ApplyAngularImpulse(ref PhysicsVelocity, in PhysicsMass, in float3)
Declaration
public static void ApplyAngularImpulse(this ref PhysicsVelocity velocityData, in PhysicsMass massData, in float3 impulse)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | velocityData | |
PhysicsMass | massData | |
float3 | impulse |
ApplyExplosionForce(ref PhysicsVelocity, in PhysicsMass, in PhysicsCollider, in Translation, in Rotation, 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 ApplyExplosionForce(ref PhysicsVelocity, in PhysicsMass, in PhysicsCollider, in Translation, in Rotation, Single, in float3, in Single, in Single, in float3, in CollisionFilter, in Single, ForceMode)
Declaration
public static void ApplyExplosionForce(this ref PhysicsVelocity bodyVelocity, in PhysicsMass bodyMass, in PhysicsCollider bodyCollider, in Translation bodyPosition, in Rotation 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 | |
PhysicsMass | bodyMass | |
PhysicsCollider | bodyCollider | |
Translation | bodyPosition | |
Rotation | bodyOrientation | |
Single | explosionForce | |
float3 | explosionPosition | |
Single | explosionRadius | |
Single | timestep | |
float3 | up | |
Single | upwardsModifier | |
ForceMode | mode |
ApplyExplosionForce(ref PhysicsVelocity, in PhysicsMass, in PhysicsCollider, in Translation, in Rotation, 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 Translation bodyPosition, in Rotation bodyOrientation, 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 | The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component. |
PhysicsCollider | bodyCollider | The body's PhysicsCollider component. |
Translation | bodyPosition | The body's Translation component. |
Rotation | bodyOrientation | The body's Rotation component. |
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 | A vector defining the up direction, generally a unit vector in the opposite direction to PhysicsStep.Gravity. |
CollisionFilter | explosionFilter | Filter determining whether an explosion should be applied to the body. |
Single | upwardsModifier | Adjustment to the apparent position of the explosion to make it seem to lift objects. |
ForceMode | mode | The method used to apply the force to its targets. |
ApplyImpulse(ref PhysicsVelocity, in PhysicsMass, in Translation, in Rotation, in float3, in float3)
Declaration
public static void ApplyImpulse(this ref PhysicsVelocity pv, in PhysicsMass pm, in Translation t, in Rotation r, in float3 impulse, in float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | pv | |
PhysicsMass | pm | |
Translation | t | |
Rotation | r | |
float3 | impulse | |
float3 | point |
ApplyLinearImpulse(ref PhysicsVelocity, in PhysicsMass, in float3)
Declaration
public static void ApplyLinearImpulse(this ref PhysicsVelocity velocityData, in PhysicsMass massData, in float3 impulse)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | velocityData | |
PhysicsMass | massData | |
float3 | impulse |
GetAngularVelocityWorldSpace(in PhysicsVelocity, in PhysicsMass, in Rotation)
Get the world-space angular velocity of a rigid body.
Declaration
public static float3 GetAngularVelocityWorldSpace(this in PhysicsVelocity bodyVelocity, in PhysicsMass bodyMass, in Rotation bodyOrientation)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component |
Rotation | bodyOrientation | The body's Rotation component |
Returns
Type | Description |
---|---|
float3 | The angular velocity of a rigid body in world space |
GetCenterOfMassWorldSpace(in PhysicsMass, in Translation, in Rotation)
Get the center of mass in world space
Declaration
public static float3 GetCenterOfMassWorldSpace(this in PhysicsMass bodyMass, in Translation bodyPosition, in Rotation bodyOrientation)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body's PhysicsMass component |
Translation | bodyPosition | The body's Translation component |
Rotation | bodyOrientation | The body's Rotation component |
Returns
Type | Description |
---|---|
float3 | The center of mass in world space |
GetEffectiveMass(in PhysicsMass, in Translation, in Rotation, 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 Translation bodyPosition, in Rotation bodyOrientation, float3 impulse, float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body's PhysicsMass component. |
Translation | bodyPosition | The body's Translation component. |
Rotation | bodyOrientation | The body's Rotation component. |
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. |
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.
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's PhysicsMass component. |
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 | A returned impulse proportional to the provided 'force' and based on the supplied 'mode'. |
PhysicsMass | impulseMass | A returned PhysicsMass component to be passed to an Apply function. |
GetLinearVelocity(in PhysicsVelocity, PhysicsMass, Translation, Rotation, 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, Translation bodyPosition, Rotation bodyOrientation, float3 point)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component |
Translation | bodyPosition | The body's Translation component |
Rotation | bodyOrientation | The body's Rotation component |
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 | The future position of the body. |
quaternion | orientation | The future orientation of the body. |
SetAngularVelocityWorldSpace(ref PhysicsVelocity, in PhysicsMass, in Rotation, 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 Rotation bodyOrientation, in float3 angularVelocity)
Parameters
Type | Name | Description |
---|---|---|
PhysicsVelocity | bodyVelocity | The body's PhysicsVelocity component. |
PhysicsMass | bodyMass | The body's PhysicsMass component |
Rotation | bodyOrientation | The body's Rotation component |
float3 | angularVelocity | An angular velocity in world space specifying radians per second about each axis. |
SetCenterOfMassWorldSpace(ref PhysicsMass, in Translation, in Rotation, float3)
Set the center of mass in world space
Declaration
public static void SetCenterOfMassWorldSpace(this ref PhysicsMass bodyMass, in Translation bodyPosition, in Rotation bodyOrientation, float3 com)
Parameters
Type | Name | Description |
---|---|---|
PhysicsMass | bodyMass | The body's PhysicsMass component |
Translation | bodyPosition | The body's Translation component |
Rotation | bodyOrientation | The body's Rotation component |
float3 | com | A position in world space for the new Center Of Mass |