Struct Constraint
A linear or angular constraint in 1, 2, or 3 dimensions.
Implements
Inherited Members
Namespace: Unity.Physics
Assembly: Unity.Physics.dll
Syntax
public struct Constraint : IEquatable<Constraint>
Fields
ConstrainedAxes
The constrained axes.
Declaration
public bool3 ConstrainedAxes
Field Value
Type | Description |
---|---|
bool3 |
DampingRatio
The damping ratio.
Declaration
public float DampingRatio
Field Value
Type | Description |
---|---|
float |
DefaultDampingRatio
The default damping ratio.
Declaration
public const float DefaultDampingRatio = 2530.126
Field Value
Type | Description |
---|---|
float |
DefaultMaxImpulse
The default maximum impulse.
Declaration
public const float DefaultMaxImpulse = Infinity
Field Value
Type | Description |
---|---|
float |
DefaultSpringDamping
Deprecated. Use DefaultDampingRatio instead.
The default damping ratio.Declaration
[Obsolete("DefaultSpringDamping has been deprecated (RemovedAfter 2023-05-09). Use DefaultDampingRatio instead. (UnityUpgradable) -> DefaultDampingRatio", false)]
public const float DefaultSpringDamping = 2530.126
Field Value
Type | Description |
---|---|
float |
DefaultSpringFrequency
The default spring frequency.
(Immutable) Current default 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 than baking them these values could be calculated using JacobianUtilities.CalculateSpringFrequencyAndDamping(0.6f, 0.99f, math.rcp(60.0f), 4, out DefaultSpringFrequency, out DefaultDampingRatio);
Declaration
public const float DefaultSpringFrequency = 74341.31
Field Value
Type | Description |
---|---|
float |
Max
The maximum.
Declaration
public float Max
Field Value
Type | Description |
---|---|
float |
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 |
---|---|
float |
SpringDamping
Deprecated. Use DampingRatio instead.
The spring damping ratio.Declaration
[Obsolete("SpringDamping has been deprecated (RemovedAfter 2023-05-09). Use DampingRatio instead. (UnityUpgradable) -> DampingRatio", false)]
public float SpringDamping
Field Value
Type | Description |
---|---|
float |
SpringFrequency
The spring frequency.
Declaration
public float SpringFrequency
Field Value
Type | Description |
---|---|
float |
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 int ConstrainedAxis1D { get; }
Property Value
Type | Description |
---|---|
int |
Dimension
Number of affected degrees of freedom. 1, 2, or 3.
Declaration
public int Dimension { get; }
Property Value
Type | Description |
---|---|
int |
FreeAxis2D
Selects the free axis from a constraint with Dimension == 2
Declaration
public int FreeAxis2D { get; }
Property Value
Type | Description |
---|---|
int |
Methods
AngularVelocityMotor(float, float, float, float)
Drives bodies to a specified target angular velocity, around one axis.
Declaration
public static Constraint AngularVelocityMotor(float target, float maxImpulseOfMotor = Infinity, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | target | The target angular velocity of the motor around Joint's Axis, in rad/s. |
float | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
BallAndSocket(float, float)
Constrains linear motion about all three axes to zero.
Declaration
public static Constraint BallAndSocket(float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
BallAndSocket(float3, float, float)
Constrains linear motion about all three axes to zero.
Declaration
public static Constraint BallAndSocket(float3 impulseEventThreshold, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float3 | impulseEventThreshold | The minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cone(int, FloatRange, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | freeAxis |
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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cone(int, FloatRange, float3, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | freeAxis |
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 minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cylindrical(int, FloatRange, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Cylindrical(int, FloatRange, float3, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | 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 minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
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 |
---|---|
bool | 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 |
---|---|
bool | True if the objects are considered equal, false if they are not. |
FixedAngle(float, float)
Constrains angular motion about all three axes to zero.
Declaration
public static Constraint FixedAngle(float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
FixedAngle(float3, float, float)
Constrains angular motion about all three axes to zero.
Declaration
public static Constraint FixedAngle(float3 impulseEventThreshold, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float3 | impulseEventThreshold | The minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
GetHashCode()
Calculates a hash code for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for this object. |
Overrides
Hinge(int, float, float)
Constrains angular motion about two axes to zero. Rotation around the third is unrestricted.
Declaration
public static Constraint Hinge(int freeAxis, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | freeAxis | The axis around which the bodies may freely rotate. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Hinge(int, float3, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | freeAxis | The axis around which the bodies may freely rotate. |
float3 | impulseEventThreshold | The minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
LimitedDistance(FloatRange, float, float)
Constrains linear motion about all three axes within the specified range.
Declaration
public static Constraint LimitedDistance(Math.FloatRange distanceRange, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
LimitedDistance(FloatRange, float3, float, float)
Constrains linear motion about all three axes within the specified range.
Declaration
public static Constraint LimitedDistance(Math.FloatRange distanceRange, float3 impulseEventThreshold, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
Math.FloatRange | distanceRange | The minimum required distance and maximum possible distance between the constrained bodies. |
float3 | impulseEventThreshold | The minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
LinearVelocityMotor(float, float, float, float)
Drives bodies to a specified target relative velocity, along one axis.
Declaration
public static Constraint LinearVelocityMotor(float target, float maxImpulseOfMotor = Infinity, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | target | The target velocity for the motor (along Joint's Axis). |
float | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A constraint. |
MotorPlanar(float, float, float, float)
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 = Infinity, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | target | The target distance the motor drives towards (along Joint's Axis). |
float | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A constraint |
MotorTwist(float, float, float, float)
Constrains angular motion about one axis and locks the angle at the specified target rotation.
Declaration
public static Constraint MotorTwist(float target, float maxImpulseOfMotor = Infinity, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | target | The target rotation around Joint's Axis the motor is driving towards, in radians. |
float | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A constraint. |
MotorTwist(float, FloatRange, float, float, float)
Constrains angular motion about one axis and locks the angle at the specified target rotation while limiting the motion range.
Declaration
public static Constraint MotorTwist(float target, Math.FloatRange angleRange, float maxImpulseOfMotor = Infinity, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
float | target | The target rotation around Joint's Axis the motor is driving towards, in radians. |
Math.FloatRange | angleRange | The minimum required angle and maximum possible angle of rotation of the constrained bodies about the constraint's axis, in radians. |
float | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A constraint. |
Planar(int, FloatRange, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Planar(int, FloatRange, float3, float, float)
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.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | 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 minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Twist(int, FloatRange, float, float)
Constrains angular motion about one axis within the specified range.
Declaration
public static Constraint Twist(int limitedAxis, Math.FloatRange angularRange, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | 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. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |
Twist(int, FloatRange, float3, float, float)
Constrains angular motion about one axis within the specified range.
Declaration
public static Constraint Twist(int limitedAxis, Math.FloatRange angularRange, float3 impulseEventThreshold, float springFrequency = 74341.31, float dampingRatio = 2530.126)
Parameters
Type | Name | Description |
---|---|---|
int | 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 minimum impulse needed to receive an impulse event for this constraint. |
float | springFrequency | The spring frequency used to relax this constraint. |
float | dampingRatio | The damping ratio used to relax this constraint. |
Returns
Type | Description |
---|---|
Constraint | A Constraint. |