Obi Official Forum
Help Collide between two ropes - 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 Collide between two ropes (/thread-2036.html)



Collide between two ropes - tda777 - 11-02-2020

I'm using Obi Rope 5.1 and i need detect collisions (or lack of collisions)  between two ropes. I put two ropes with different tags under common Obi Solver and and I received messages from ObiSolver.OnCollision.

Code:
   private void M_ObiSolver_OnCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs contact)
   {
       foreach (Oni.Contact contactItem in contact.contacts)
       {
           ObiSolver.ParticleInActor pa = solver.particleToActor[contactItem.particle];

           Component collider;
           if (ObiCollider.idToCollider.TryGetValue(pa.actor.GetInstanceID(), out collider))
           {
               //avoid floor collision
               if (collider.CompareTag("floorTag"))
                   return;

               if (contactItem.distance < 0.01)
               {

                   if (!pa.actor.CompareTag(collider.tag))
                   {
                       print($"rope({pa.actor.name}) touched another rope({collider.name})");
                   }
                   else if (pa.actor.CompareTag(collider.tag))
                   {
                       print($"rope({pa.actor.name}) touched itself({collider.name})");
                   }
               }
           }


       }
   }

But i did not get collider of another rope. 
How I can get collision between two ropes?


RE: Collide between two ropes - josemendez - 11-02-2020

(11-02-2020, 01:44 PM)tda777 Wrote: I'm using Obi Rope 5.1 and i need detect collisions (or lack of collisions)  between two ropes. I put two ropes with different tags under common Obi Solver and and I received messages from ObiSolver.OnCollision.

Code:
   private void M_ObiSolver_OnCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs contact)
   {
       foreach (Oni.Contact contactItem in contact.contacts)
       {
           ObiSolver.ParticleInActor pa = solver.particleToActor[contactItem.particle];

           Component collider;
           if (ObiCollider.idToCollider.TryGetValue(pa.actor.GetInstanceID(), out collider))
           {
               //avoid floor collision
               if (collider.CompareTag("floorTag"))
                   return;

               if (contactItem.distance < 0.01)
               {

                   if (!pa.actor.CompareTag(collider.tag))
                   {
                       print($"rope({pa.actor.name}) touched another rope({collider.name})");
                   }
                   else if (pa.actor.CompareTag(collider.tag))
                   {
                       print($"rope({pa.actor.name}) touched itself({collider.name})");
                   }
               }
           }


       }
   }

But i did not get collider of another rope. 
How I can get collision between two ropes?

Ropes do not use colliders. They use particles. That's the whole point of a particle-based physics engine.  Guiño  

To get the particle-particle collision events that happened during a frame, subscribe to solver.OnParticleCollision. The contact will contain the indices of the 2 particles involved, instead of a particle index and a collider index.