Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Problem with detecting collisions between different ropes
#1
I'm trying to detect collisions between multiple ropes with the code below. However, even if the colliding ropes are different, both pa.actor.gameObject and po.actor.gameObject point to the same object. Both bodyA and bodyB show the same rope. I want to detect different colliding ropes. I looked into the forum and believe that detection should be done with this method. However, I wonder if I'm making a mistake when creating the Rope or Solver.
solver.OnParticleCollision += Solver_OnCollision;

void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{

foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.01)
{
ObiSolver.ParticleInActor pa = solver.particleToActor[solver.simplices[contact.bodyA]];
ObiSolver.ParticleInActor po = solver.particleToActor[solver.simplices[contact.bodyB]];
if (pa.actor.gameObject != po.actor.gameObject)
{
Debug.Log("rope collides: " + pa.actor.blueprint.name + " " + po.actor.blueprint.name, pa.actor.gameObject);
}
}

}
}
Reply
#2
Hi!

Your code won't work in the general case, as it assumes all simplices in the solver contain a single particle. This won't be the case if any rope is using surface collisions, as explained in the manual: http://obi.virtualmethodstudio.com/manua...sions.html

Correct code would be:

Code:
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {

        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                int simplexStartA = solver.simplexCounts.GetSimplexStartAndSize(contact.bodyA, out _);
                int simplexStartB = solver.simplexCounts.GetSimplexStartAndSize(contact.bodyB, out _);

                ObiSolver.ParticleInActor pa = solver.particleToActor[solver.simplices[simplexStartA]];
                ObiSolver.ParticleInActor po = solver.particleToActor[solver.simplices[simplexStartB]];
                if (pa.actor.gameObject != po.actor.gameObject)
                {
                    Debug.Log("rope collides: " + pa.actor.blueprint.name + " " + po.actor.blueprint.name, pa.actor.gameObject);
                }
            }

        }
}

Also note that you're Debug.Logging the blueprint's name, not the rope's name. In case both ropes share the same blueprint, the same name will be written even if the ropes involved in the collision are different.


Let me know if you need further help,

kind regards
Reply
#3
Thanks. This method solved my problem.
Reply