19-05-2020, 06:39 PM
(19-05-2020, 06:32 PM)josemendez Wrote: 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 , 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.
Thank you!