13-05-2021, 02:37 PM
Hi all!
Is it possible to tear after changing length?
Here is my code for tearing:
It works for pre-created rope, but when I change length, it cuts somewhere at the end, not at collision point.
Please help.
Is it possible to tear after changing length?
Here is my code for tearing:
Code:
void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
// just iterate over all contacts in the current frame:
foreach (Oni.Contact contact in e.contacts)
{
// if this one is an actual collision:
if (contact.distance > 0.01) continue;
ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
TearRope(col, contact);
}
}
private void TearRope(ObiColliderBase col, Oni.Contact contact)
{
if (!col || !col.CompareTag(StaticData.tear)) return;
ObiSolver.ParticleInActor pa = solver.particleToActor[contact.bodyA];
if (pa == null) return;
var actor = pa.actor as ObiRope;
if (!actor) return;
if (pa.indexInActor >= actor.elements.Count) return;
actor.Tear(actor.elements[pa.indexInActor]);
actor.RebuildConstraintsFromElements();
}
It works for pre-created rope, but when I change length, it cuts somewhere at the end, not at collision point.
Please help.