Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detect Collision between rope and collider
#2
Quote:I want to make a condition that return true when all those ropes didn't collide with any wall

Your code will return true if the last contact in the list is against a wall, false otherwise. You constantly overwrite TouchingWall. Its value will always be that of the last contact.

Instead you should set TouchingWall to true at the beginning of the method, then set it to false when you find at least one contact against the wall.  Actually, renaming it to NotTouchingWall would be better Guiño, since you want "true" when no rope is colliding against a wall.


Code:
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       frame = e;
       NotTouchingWall = true;
       for (int i = 0; i < e.contacts.Count; ++i)
       {
           if (e.contacts.Data[i].distance < 0.1f)
           {
               Component thecollider;
               if (ObiColliderBase.idToCollider.TryGetValue(e.contacts.Data[i].other, out thecollider))
               {

                   if (thecollider.CompareTag("Wall"))
                       NotTouchingWall = false;
               }
           }
       }

   }

Btw, it does not matter how many actors (ropes) are there in a solver, the list of contacts returned is for all particles in the solver.
Reply


Messages In This Thread
RE: Detect Collision between rope and collider - by josemendez - 19-05-2020, 06:32 PM