Code:
private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.025f)
{
ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
if (col != null && col.gameObject.layer==LayerMask.NameToLayer("CarFrontCollider"))
{
// get the index of the particle involved in the contact:
int particleIndex = solver.simplices[contact.bodyA];
ObiRope contactedRope = solver.particleToActor[particleIndex].actor as ObiRope;
contactedRope.GetComponent<SpecificRopeTearer>().TearRope(particleIndex);
}
}
}
}
Code:
public void TearRope(int particleIndex)
{
this.GetComponent<RopeBehaviour>().enabled = false;
if (this.didTear == false)
{
BusSystem.CallOnRopeToreApart(this.endParticle.target.GetComponent<FuelLineEndController>());
StartCoroutine(DestroyRope());
this.rope.stretchingScale = 1f;
this.endParticle.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
this.endParticle.target = this.rope.transform;
this.startParticle.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
this.startParticle.target = this.rope.transform;
this.didTear = true;
}
this.TearAtIndex(particleIndex);
}
void TearAtIndex(int index)
{
Debug.Log(index);
if (index < rope.elements.Count)
{
this.rope.Tear(rope.elements[index]);
}
this.rope.RebuildConstraintsFromElements();
}
Hi ! I am working on a project and using ObiRope. I have problem with detecting collision with particles. I read documents and tried to use them as best as I can.
I need to know which particle collided with a object that has specific layer. And I want to tear the rope at collided particles. Here is some screenshots for explaining it better. At right (teared rope) image behaviour acts like I want. But after I spawn new ropes it doesn't work. When I am Debug.Log the shown indexes are beyond existing particle count (I may be wrong in here.).
If you need any additional info please tell me, I don't want to scare people with a long post
Thank you !
I think I solved it . Just changed parameter "particleIndex" to "this.solver.particleToActor[particleIndex].indexInActor" I think I solved it . Still don't have idea why it didn't work.
Code:
private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.025f)
{
ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
if (col != null && col.gameObject.layer==LayerMask.NameToLayer("CarFrontCollider"))
{
// get the index of the particle involved in the contact:
int particleIndex = solver.simplices[contact.bodyA];
ObiRope contactedRope = solver.particleToActor[particleIndex].actor as ObiRope;
contactedRope.GetComponent<SpecificRopeTearer>().TearRope(this.solver.particleToActor[particleIndex].indexInActor); ;
}
}
}
}