Class DistanceLimit
- Namespace
- Jitter2.Dynamics.Constraints
- Assembly
- Jitter2.dll
Keeps the distance between two body anchors within a range, or at a fixed value. For a fixed distance of zero, use BallSocket.
public class DistanceLimit : Constraint<DistanceLimit.DistanceLimitData>, IDebugDrawable
- Inheritance
-
DistanceLimit
- Implements
- Inherited Members
Properties
Anchor1
Gets or sets the anchor point on the first rigid body in world space. The anchor point is fixed in the local reference frame of the first body.
[ReferenceFrame(ReferenceFrame.World)]
public JVector Anchor1 { get; set; }
Property Value
Anchor2
Gets or sets the anchor point on the second rigid body in world space. The anchor point is fixed in the local reference frame of the second body.
[ReferenceFrame(ReferenceFrame.World)]
public JVector Anchor2 { get; set; }
Property Value
Bias
Gets or sets the bias factor controlling how aggressively distance error is corrected.
public float Bias { get; set; }
Property Value
- float
Default is 0.2. Higher values correct errors faster but may cause instability.
Distance
Gets the current distance between anchor points in world space.
public float Distance { get; }
Property Value
Impulse
Gets the accumulated solver impulse from the last solved substep.
public float Impulse { get; }
Property Value
Softness
Gets or sets the softness (compliance) of the constraint.
public float Softness { get; set; }
Property Value
- float
Default is DefaultLinearSoftness. Higher values allow more distance error but improve stability.
TargetDistance
Gets or sets the target distance between anchor points.
public float TargetDistance { get; set; }
Property Value
- float
Set during initialization from the initial anchor separation.
Methods
Create()
Called when the world creates this constraint. Override to set DispatchId to the ID returned by registering the constraint's solver methods.
protected override void Create()
DebugDraw(IDebugDrawer)
Draws a debug visualization of this constraint.
public override void DebugDraw(IDebugDrawer drawer)
Parameters
drawerIDebugDrawerThe debug drawer to receive visualization primitives.
Exceptions
- NotImplementedException
Thrown if the derived class does not override this method.
DebugDraw(IDebugDrawer, in DebugDrawSettings)
Draws this constraint using the supplied visualization settings. Custom constraints that only override DebugDraw(IDebugDrawer) use their default visualization.
public override void DebugDraw(IDebugDrawer drawer, in DebugDrawSettings settings)
Parameters
drawerIDebugDrawersettingsDebugDrawSettings
Initialize(JVector, JVector)
Initializes the constraint with a fixed distance between anchor points.
public void Initialize(JVector anchor1, JVector anchor2)
Parameters
anchor1JVectorAnchor point on the first body in world space.
anchor2JVectorAnchor point on the second body in world space.
Exceptions
- ArgumentException
Thrown when
anchor1oranchor2contains a non-finite value.
Initialize(JVector, JVector, LinearLimit)
Initializes the constraint with distance limits between anchor points.
public void Initialize(JVector anchor1, JVector anchor2, LinearLimit limit)
Parameters
anchor1JVectorAnchor point on the first body in world space.
anchor2JVectorAnchor point on the second body in world space.
limitLinearLimitAllowed offsets from the initial distance between anchor points. For example, a limit of (-1, 1) allows the distance to change by at most one unit in either direction.
Remarks
Equal or reversed limits fix the distance offset at their midpoint. Default values: Softness = DefaultLinearSoftness, Bias = DefaultLinearBias.
Exceptions
- ArgumentException
Thrown when
anchor1oranchor2contains a non-finite value, or when either value inlimitis NaN.
IterateDistanceLimit(ref ConstraintData, in TimeStep)
public static void IterateDistanceLimit(ref ConstraintData constraint, in TimeStep timeStep)
Parameters
constraintConstraintDatatimeStepTimeStep
PrepareForIterationDistanceLimit(ref ConstraintData, in TimeStep)
public static void PrepareForIterationDistanceLimit(ref ConstraintData constraint, in TimeStep timeStep)
Parameters
constraintConstraintDatatimeStepTimeStep
ResetWarmStart()
Clears impulses saved from the previous solve, without changing constraint settings.
public override void ResetWarmStart()
Remarks
Use after restoring a saved state or making a sudden change to the bodies, when impulses from their previous state should no longer be reused.
ToString()
Returns a short description of the constraint's ID, connected bodies, and state.
public override string ToString()