(17-08-2021, 01:27 PM)TheMunk Wrote: As title says, when using
Code:
batch.AddConstraint(solverIndex, obiCollider, positionCS, Quaternion.identity, linearCompliance, rotationalCompliance, breakThreshold);
setting breakThreshold to a small positive number does not make the constraint break. It seems to always be infinite. Why is this? Normal dynamic Particle Attachments works fine in my scene.
The break threshold is
used by attachments to deactivate pin constraints when they exceed it. It's
not automatically evaluated by the constraints themselves. Particle attachments have a BreakDynamicAttachment() method that is called at the end of every physics step. It iterates trough all pin constraints in the batch and checks their force against the break threshold. If it's over the threshold, the constraint gets deactivated.
The force is calculated from the constraint's positional lagrange multiplier (lambda). To convert from lagrange multiple to force, you divide by timeDelta squared. Hence (copy pasted from ObiParticleAttachment.cs):
Code:
if (-solverBatch.lambdas[(offset + i) * 4 + 3] / sqrTime > pinBatch.breakThresholds[i])
{
pinBatch.DeactivateConstraint(i);
dirty = true;
}
The minus (-) sign in there means we're interested in
stretching forces only, no compression.
You can basically copy the entire BreakDynamicAttachment() method from ObiParticleAttachment.cs (might need some adjustments depending on what your specific use case is) and call it when you deem necessary.