Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Problem with detecting collisions between different ropes
#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


Messages In This Thread
RE: Problem with detecting collisions between different ropes - by josemendez - 15-08-2023, 07:26 AM