Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Check for collision of last particle in rope
#2
(23-12-2022, 01:43 AM)docgonzzo Wrote: I understand the last point in the rope can be obtained by elements but I'm not sure how to check for the actual particle.

Hi!

The last point in the rope is the last particle. Each element contains the indices of 2 particles in the solver, and each contact contains the index of 1 simplex and 1 collider. So all you've got to do is get the particle index from the simplex, and check whether it is the same as the element's:

Code:
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();

        //iterate over all contacts in the current frame:
        foreach (Oni.Contact contact in e.contacts)
        {
            // if this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
                if (col != null)
                {
                    if (col.gameObject.layer == 15)
                    {
                        //if we are here we know particles are colliding with layer 15 objects.
                        if (rope.solver.simplices[contact.bodyA] == rope.elements[rope.elements.Count - 1].particle2)
                        {
                            //last particle in the rope hit a collider in layer 15!
                        }
                    }

                }
            }
        }
    }

See "retrieving the particle involved in a contact" in the scripting collisions section: http://obi.virtualmethodstudio.com/manua...sions.html

kind regards,
Reply


Messages In This Thread
RE: Check for collision of last particle in rope - by josemendez - 23-12-2022, 08:52 AM