08-05-2020, 10:58 AM
(07-05-2020, 09:24 PM)pQuex Wrote: I found an interesting thing and it's exactly the opposite of what I would expect.
When I set the offset parameter of batch.AddConstraint() to vector3.zero, it pins the rope to the center of the collider and the attached object is free to rotate.
Of course the physics goes bonkers because of the conflicting constraints, but if I change the phase, it hangs there and rotates around the local center freely.
Any other value of the offset I tried, within or outside of the block, prevents the rotation.
Hi,
Thing is you're passing Quaternion.identity as the target rotation of the pin constraint. By default, pins constraint both translation and orientation. So after instantiating the blueprint, you need to increase the rotation compliance. Paste this right after the "rope.GetComponent<MeshRenderer>().enabled = true;" line at the end of AttachHook() method.
Code:
var runtimePins = rope.GetConstraintsByType(Oni.ConstraintType.Pin);
var runtimeBatch = runtimePins.GetBatchInterfaces()[0] as ObiPinConstraintsBatch;
for (int i = 0; i < runtimeBatch.constraintCount; i++)
{
runtimeBatch.stiffnesses[i * 2] = 0; // 0 translation compliance.
runtimeBatch.stiffnesses[i * 2 + 1] = 10000; // very large rotation compliance (allows rotations)
}
This will grab the runtime pin constraints batch, and set the orientation compliance to a high value for all of them, allowing free rotation. This isn't yet documented anywhere (working on it), so my apologies: it wasn't exactly easy to figure out, and I would not expect anyone to be able to do so without a bit of help.