Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Destroy particle on collision
#11
(03-05-2018, 08:32 AM)josemendez Wrote: You could deactivate collisions and just iterate over all particles positions instead, yes.

Out of curiosity, I've tested this script and it only causes a 10% performance impact or so for 2500 particles. What platform are you targeting? and have you profiled to make sure this is the culprit?

I'm building on windows targeting windows. I haven't done extensive tests besides the deactivating and reactivating the script which seems to cause the slowdown. Deactivating it resumes back up to normal fps and reactivating causes the slowdown once the particles build back up.

Could you provide me with a code snippet to do this?
im assuming its a for(all particles){ if particle.x > num { particle.life = 0 }} 

Just not too sure on the specific code.

Thank you!
Reply
#12
(29-09-2017, 12:30 PM)Kalidor Wrote: i'am 

what made you think this was ok
Reply
#13
Hey, I want to kill particles that collide with the ground!! I tried the above approach but it's not working !!Please helppp
Reply
#14
(18-10-2021, 08:18 AM)shanu12joshi Wrote: Hey, I want to kill particles that collide with the ground!! I tried the above approach but it's not working !!Please helppp

Hi!

The approach outlined in this thread is valid. What have you tried exactly? Can you post your code? I can't do much to help if you don't specify what have you tried and how it fails to work.
Reply
#15
I know it's an old thread, but it comes up for the topic of killing fluid particles on contact with colliders.
The API has changed, so this seems to be useful for Obi 7 Fluids.

Code:
// FluidAbsorber.cs
//
using UnityEngine;

using Obi;

public class FluidAbsorber: MonoBehaviour
{
    [Tooltip("The solver for Obi Fluid particles")]
    public ObiSolver solver;

    [Tooltip("The Obi Collider that will destroy fluid particles")]
    public ObiColliderBase absorber;

    void Awake()
    {
        // unlike particle actors, this absorber
        // does not have to be a child of the solver,
        // but if left null we assume it is
        //
        if (solver == null)
            solver = GetComponentInParent<ObiSolver>();

        if (absorber == null)
            absorber = GetComponent<ObiColliderBase>();
    }

    void OnEnable()
    {
        if (solver != null)
            solver.OnCollision += Solver_OnCollision;
    }

    void OnDisable()
    {
        if (solver != null)
            solver.OnCollision -= Solver_OnCollision;
    }

    void Solver_OnCollision(object sender,
        ObiNativeContactList e)
    {
        ObiColliderWorld world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e)
        {
            // real contact or speculative?
            if (contact.distance > 0.01f)
                continue;

            // was it our specified Obi Collider?
            ObiColliderBase collider =
                world.colliderHandles[contact.bodyB].owner;
            if (collider != absorber)
                continue;

            // "kill" the particle by setting its life to zero
            int particleIndex = solver.simplices[contact.bodyA];
            solver.life[particleIndex] = 0;
        }
    }
}
Reply