Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to detect number of particles in collision?
#1
Hi,

So how do i detect the number of particles currently in contact with a plane/collider? For example, If i my blueprint has 2000 particles, And I make a few fall off the edge, How do i detect the current remaining particles?


Thanks
Reply
#2
(15-07-2020, 06:50 PM)anulagarwal Wrote: Hi,

So how do i detect the number of particles currently in contact with a plane/collider? For example, If i my blueprint has 2000 particles, And I make a few fall off the edge, How do i detect the current remaining particles?


Thanks

Hi,

Obi simply provides the full contact list each frame, it is your responsibility to filter it any way you need. See:
http://obi.virtualmethodstudio.com/tutor...sions.html

In your case, you can simply keep track of the previous contact list, and use list operations (such as union, intersect, except) to determine which contacts have disappeared since the last frame and which ones still exist.
Reply
#3
Iterating through them via foreach every frame causes the game to lag!
Any other solution?

Edit: Figured it out, Thanks!
Reply
#4
Hey,
The number seems to be fluctuating tho.
I cannot get the exact number of particles in contact with the collision, they seem to go up and down every frame.
Reply
#5
(16-07-2020, 09:59 AM)anulagarwal Wrote: Hey,
The number seems to be fluctuating tho.
I cannot get the exact number of particles in contact with the collision, they seem to go up and down every frame.

Hi,

The amount of contacts should always be correct, as the data structure passed to the collision event is the exact same used by the engine to resolve collisions. Missing/excess collisions would result in incorrect physical behavior.

How are you counting the amount of particles in contact?
Reply
#6
Code:
  ObiSolver solver;
    bool isHit;

    Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

    List<Oni.Contact> c;
    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)
    {
       
       
        GameManager.instance.SetCompletion(e.contacts.Count);
       
    }
Basically this is attached on the Solver object, and the e.contacts.Count keeps fluctuating for some reason
Reply
#7
(16-07-2020, 05:37 PM)anulagarwal Wrote:
Code:
  ObiSolver solver;
    bool isHit;

    Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

    List<Oni.Contact> c;
    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)
    {
      
       
        GameManager.instance.SetCompletion(e.contacts.Count);
      
    }
Basically this is attached on the Solver object, and the e.contacts.Count keeps fluctuating for some reason

contacts.Count will of course fluctuate over multiple frames, as some frames more particles will be in contact that in others depending on the situation. Not all particles will be in contact with all colliders all the time. You need to check for actual contacts by the way, not just speculative ones. For this, you need to make sure the contact distance is negative (or smaller than a small positive value). Check the sample in the docs:
http://obi.virtualmethodstudio.com/tutor...sions.html
Reply
#8
Hey,
I still cannot figure it out! Triste
Is it possible you could write a code snippet and explain me how it would work?
Reply