Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  'ObiCollider' does not contain a definition for 'idToCollider'
#7
(23-10-2020, 11:53 AM)dabinzzang Wrote:
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.

What this does is it counts the amount of new particle hits any collider has experienced (cumulative over time), and stores that in the "counter" variable. Works perfectly fine. Note that the number logged to the console is the total amount of current contacts with *any* collider or trigger in the scene, the "targetCollider" variable is completely unused in the script.

What is it that you want to count?
Reply


Messages In This Thread
RE: 'ObiCollider' does not contain a definition for 'idToCollider' - by josemendez - 23-10-2020, 12:10 PM