23-10-2020, 11:53 AM
(23-10-2020, 11:39 AM)josemendez Wrote: Works just fine for me, can you share the exact code you're using?
Code:
[RequireComponent(typeof(ObiSolver))]
public class CollisionEventHandler : MonoBehaviour
{
ObiSolver solver;
public int counter = 0;
public Collider targetCollider = null;
Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;
HashSet<int> particles = new HashSet<int>();
void Awake()
{
solver = GetComponent<Obi.ObiSolver>();
}
void OnEnable()
{
solver.OnCollision += Solver_OnCollision;
}
void OnDisable()
{
solver.OnCollision -= Solver_OnCollision;
}
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
HashSet<int> currentParticles = new HashSet<int>();
var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
{
// this one is an actual collision:
if (contact.distance < 0.00001)
{
ObiColliderBase collider = world.colliderHandles[contact.other].owner;
if (collider != null)
{
currentParticles.Add(contact.particle);
}
}
}
Debug.Log(currentParticles.Count);
particles.ExceptWith(currentParticles);
counter += particles.Count;
particles = currentParticles;
}
}
Here you are. Thank you very much.