Struct Constraint
A linear or angular constraint in 1, 2, or 3 dimensions.
Inherited Members
Namespace: Unity.Physics
Syntax
public struct Constraint : IEquatable<Constraint>
Fields
ConstrainedAxes
The constrained axes.
Declaration
public bool3 ConstrainedAxes
Field Value
Type | Description |
---|---|
bool3 |
DefaultMaxImpulse
The default maximum impulse.
Declaration
public const float DefaultMaxImpulse = InfinityF
Field Value
Type | Description |
---|---|
Single |
DefaultSpringDamping
The default spring damping.
Declaration
public const float DefaultSpringDamping = 2530.126F
Field Value
Type | Description |
---|---|
Single |
DefaultSpringFrequency
(Immutable) Current values give tau = 0.6 damping = 0.99 at 60hz The values are huge and we can't get damping = 1 -- a stiff constraint is the limit of a damped spring as spring params go to infinity. Rather then baking them these values could be calculated using JacobianUtilities.CalculateSpringFrequencyAndDamping(0.6f, 0.99f, math.rcp(60.0f), 4, out DefaultSpringFrequency, out DefaultSpringDamping);
Declaration
public const float DefaultSpringFrequency = 74341.31F
Field Value
Type | Description |
---|---|
Single |
Max
The maximum.
Declaration
public float Max
Field Value
Type | Description |
---|---|
Single |
MaxImpulse
The impulse threshold after which ImpulseEvent will be raised from this constraint. In case of motorized constraints, represents the maximum impulse that can be applied to it during one step.
Declaration
public float3 MaxImpulse
Field Value
Type | Description |
---|---|
float3 |
Min
The minimum.
Declaration
public float Min
Field Value
Type | Description |
---|---|
Single |
SpringDamping
The spring damping.
Declaration
public float SpringDamping
Field Value
Type | Description |
---|---|
Single |
SpringFrequency
The spring frequency.
Declaration
public float SpringFrequency
Field Value
Type | Description |
---|---|
Single |
Target
The target a motor will drive towards. Can be set to zero for non-motor type constraints
Declaration
public float3 Target
Field Value
Type | Description |
---|---|
float3 |
Type
The constraint type.
Declaration
public ConstraintType Type
Field Value
Type | Description |
---|---|
ConstraintType |
Properties
ConstrainedAxis1D
Selects the constrained axis from a constraint with Dimension == 1
Declaration
public readonly int ConstrainedAxis1D { get; }
Property Value
Type | Description |
---|---|
Int32 |
Dimension
Number of affected degrees of freedom. 1, 2, or 3.
Declaration
public readonly int Dimension { get; }
Property Value
Type | Description |
---|---|
Int32 |
FreeAxis2D
Selects the free axis from a constraint with Dimension == 2
Declaration
public readonly int FreeAxis2D { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
AngularVelocityMotor(Single, Single, Single, Single)
Drives bodies to a specified target angular velocity, around one axis.
Declaration
public static Constraint AngularVelocityMotor(float target, float maxImpulseOfMotor = InfinityF, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Single | target | The target angular velocity of the motor around Joint's Axis, in rad/s. |
Single | maxImpulseOfMotor | The magnitude of the max impulse that a motor constraint can exert in a single step. Must be positive. This is a motor specific usage that does not represent the impulse threshold for event reporting. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
BallAndSocket(Single, Single)
Constrains linear motion about all three axes to zero.
Declaration
public static Constraint BallAndSocket(float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
BallAndSocket(float3, Single, Single)
Constrains linear motion about all three axes to zero.
Declaration
public static Constraint BallAndSocket(float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cone(Int32, Math.FloatRange, Single, Single)
Constrains angular motion about two axes within the specified range. Rotation around the third is unrestricted.
Declaration
public static Constraint Cone(int freeAxis, Math.FloatRange angularRange, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | freeAxis | The axis specifying the height of the cone within which the bodies may rotate. |
Math.FloatRange | angularRange | The minimum required angle and maximum possible angle between the free axis and its bind pose orientation. A minimum value of zero produces a conical range of motion, while a minimum value greater than zero results in motion restricted to the intersection of the inner and outer cones. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cone(Int32, Math.FloatRange, float3, Single, Single)
Constrains angular motion about two axes within the specified range. Rotation around the third is unrestricted.
Declaration
public static Constraint Cone(int freeAxis, Math.FloatRange angularRange, float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | freeAxis | The axis specifying the height of the cone within which the bodies may rotate. |
Math.FloatRange | angularRange | The minimum required angle and maximum possible angle between the free axis and its bind pose orientation. A minimum value of zero produces a conical range of motion, while a minimum value greater than zero results in motion restricted to the intersection of the inner and outer cones. |
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cylindrical(Int32, Math.FloatRange, Single, Single)
Constrains linear motion about two axes within the specified range. Movement about the third is unrestricted.
Declaration
public static Constraint Cylindrical(int freeAxis, Math.FloatRange distanceRange, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | freeAxis | The axis along which the bodies may freely translate. |
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies about the two constrained axes. A minimum value of zero produces a cylindrical range of motion, while a minimum value greater than zero results in a tube-shaped range of motion. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cylindrical(Int32, Math.FloatRange, float3, Single, Single)
Constrains linear motion about two axes within the specified range. Movement about the third is unrestricted.
Declaration
public static Constraint Cylindrical(int freeAxis, Math.FloatRange distanceRange, float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | freeAxis | The axis along which the bodies may freely translate. |
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies about the two constrained axes. A minimum value of zero produces a cylindrical range of motion, while a minimum value greater than zero results in a tube-shaped range of motion. |
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Equals(Object)
Tests if this object is considered equal to another.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare to this object. |
Returns
Type | Description |
---|---|
Boolean | True if the objects are considered equal, false if they are not. |
Overrides
Equals(Constraint)
Tests if this Constraint is considered equal to another.
Declaration
public bool Equals(Constraint other)
Parameters
Type | Name | Description |
---|---|---|
Constraint | other | The constraint to compare to this object. |
Returns
Type | Description |
---|---|
Boolean | True if the objects are considered equal, false if they are not. |
Implements
FixedAngle(Single, Single)
Constrains angular motion about all three axes to zero.
Declaration
public static Constraint FixedAngle(float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
FixedAngle(float3, Single, Single)
Constrains angular motion about all three axes to zero.
Declaration
public static Constraint FixedAngle(float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
GetHashCode()
Calculates a hash code for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this object. |
Overrides
Hinge(Int32, Single, Single)
Constrains angular motion about two axes to zero. Rotation around the third is unrestricted.
Declaration
public static Constraint Hinge(int freeAxis, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | freeAxis | The axis around which the bodies may freely rotate. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Hinge(Int32, float3, Single, Single)
Constrains angular motion about two axes to zero. Rotation around the third is unrestricted.
Declaration
public static Constraint Hinge(int freeAxis, float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | freeAxis | The axis around which the bodies may freely rotate. |
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
LimitedDistance(Math.FloatRange, Single, Single)
Constrains linear motion about all three axes within the specified range.
Declaration
public static Constraint LimitedDistance(Math.FloatRange distanceRange, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
LimitedDistance(Math.FloatRange, float3, Single, Single)
Constrains linear motion about all three axes within the specified range.
Declaration
public static Constraint LimitedDistance(Math.FloatRange distanceRange, float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies. |
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
LinearVelocityMotor(Single, Single, Single, Single)
Drives bodies to a specified target relative velocity, along one axis.
Declaration
public static Constraint LinearVelocityMotor(float target, float maxImpulseOfMotor = InfinityF, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Single | target | The target velocity for the motor (along Joint's Axis). |
Single | maxImpulseOfMotor | The magnitude of the max impulse that a motor constraint can exert in a single step. Must be positive. This is a motor specific usage that does not represent the impulse threshold for event reporting. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A constraint. |
MotorPlanar(Single, Single, Single, Single)
Moves bodies along one axis to specified target distance. Movement about the other two perpendicular axes is unrestricted.
Declaration
public static Constraint MotorPlanar(float target, float maxImpulseOfMotor = InfinityF, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Single | target | The target distance the motor drives towards (along Joint's Axis). |
Single | maxImpulseOfMotor | The magnitude of the max impulse that a motor constraint can exert in a single step. Must be positive. This is a motor specific usage that does not represent the impulse threshold for event reporting. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A constraint |
MotorTwist(Single, Single, Single, Single)
Constrains angular motion about one axis and drives towards the specified target rotation.
Declaration
public static Constraint MotorTwist(float target, float maxImpulseOfMotor = InfinityF, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Single | target | The target rotation around Joint's Axis the motor is driving towards, in radians. |
Single | maxImpulseOfMotor | The magnitude of the max impulse that a motor constraint can exert in a single step. Must be positive. This is a motor specific usage that does not represent the impulse threshold for event reporting. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A constraint. |
Planar(Int32, Math.FloatRange, Single, Single)
Constrains linear motion about one axis within the specified range. Movement about the other two is unrestricted.
Declaration
public static Constraint Planar(int limitedAxis, Math.FloatRange distanceRange, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | limitedAxis | The axis along which the bodies' translation is restricted. |
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies about the constrained axis. Identical minimum and maximum values result in a plane, while different values constrain the bodies between two parallel planes. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Planar(Int32, Math.FloatRange, float3, Single, Single)
Constrains linear motion about one axis within the specified range. Movement about the other two is unrestricted.
Declaration
public static Constraint Planar(int limitedAxis, Math.FloatRange distanceRange, float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | limitedAxis | The axis along which the bodies' translation is restricted. |
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies about the constrained axis. Identical minimum and maximum values result in a plane, while different values constrain the bodies between two parallel planes. |
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Twist(Int32, Math.FloatRange, Single, Single)
Constrains angular motion about about one axis within the specified range.
Declaration
public static Constraint Twist(int limitedAxis, Math.FloatRange angularRange, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | limitedAxis | The axis around which the bodies' rotation is restricted. |
Math.FloatRange | angularRange | The minimum required angle and maximum possible angle of rotation between the constrained bodies around the constrained axis. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Twist(Int32, Math.FloatRange, float3, Single, Single)
Constrains angular motion about about one axis within the specified range.
Declaration
public static Constraint Twist(int limitedAxis, Math.FloatRange angularRange, float3 impulseEventThreshold, float springFrequency = 74341.31F, float springDamping = 2530.126F)
Parameters
Type | Name | Description |
---|---|---|
Int32 | limitedAxis | The axis around which the bodies' rotation is restricted. |
Math.FloatRange | angularRange | The minimum required angle and maximum possible angle of rotation between the constrained bodies around the constrained axis. |
float3 | impulseEventThreshold | The max impulse needed to receive an impulse event for this constraint. |
Single | springFrequency | (Optional) |
Single | springDamping | (Optional) |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |