Obi Official Forum
Help Rope Collision Detection - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Rope Collision Detection (/thread-4248.html)



Rope Collision Detection - kripa1415 - 10-06-2024

Hi,
 I have 3 ropes tanged. I am untangling first rope and avoided collision from the other 2 ropes. How do I detect this ?
 I have the on collision subscribed on the solver and getting the contacts. But I want to filter rope wise

RopeGenerator.solver.OnParticleCollision += Solver_OnParticleCollision;

private void Solver_OnParticleCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs contacts)
{
   
    if (contacts.contacts.Count <= 0)
    {
        
    }
    else
    {
        
    }
}


RE: Rope Collision Detection - josemendez - 10-06-2024

Hi!

You can just check which rope the particles involved in each contact belong to. See "Retrieving the actor involved in a contact":
http://obi.virtualmethodstudio.com/manual/6.3/scriptingcollisions.html


RE: Rope Collision Detection - kripa1415 - 10-06-2024

Hi,
 yes its partially working now. As I said I have 3 ropes and all 3 of them are in contact. But the below code only giving two rope collision. I 've set ids for each rope. 1, 2 and 3 in ropeOrder variable. I am getting only 2 and 3 in logs. top rope collisioin is missing. Am I missing something ? Do I have to consider c.bodyB somewhere ?

Code:
foreach (var c in contacts.contacts)
{
    int particleIndex = solver.simplices[c.bodyA];
    ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];
    TangledRope tr = pa.actor.GetComponent<TangledRope>();
    tr.collided = true;
    tr.lastCollidedTime = Time.time;
    Debug.Log("pa: " + pa + ", actor: " + tr.ropeOrder);

}



RE: Rope Collision Detection - josemendez - 10-06-2024

Contacts always take place between two things. Your code only checks one of the 2 particles involved in each contact,  so this will miss information. You need to do the same thing for c.bodyB.