Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Destroy particle on collision
#6
(29-09-2017, 02:45 PM)Kalidor Wrote: There is the same problem with this solution (with your new script).

Hi Kalidor,

I tested it with this code in a variety of situations, works as intended. Make sure that you set the particle's life to 0 instead of calling KillParticle().

Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class CollisionEventHandler : MonoBehaviour {

    ObiSolver solver;

   public Collider killer;

    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)
    {
        for(int i = 0;  i < e.contacts.Length; ++i)
       {
           if (e.contacts[i].distance < 0.001f)
           {

               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(e.contacts[i].other,out collider)){

                   if (collider == killer){

                       ObiSolver.ParticleInActor pa = solver.particleToActor[e.contacts[i].particle];
                       ObiEmitter emitter = pa.actor as ObiEmitter;

                       if (emitter != null)
                           emitter.life[pa.indexInActor] = 0;
                       
                   }
               }
           }
       }
   }
}
Reply


Messages In This Thread
Destroy particle on collision - by Kalidor - 29-09-2017, 10:50 AM
RE: Destroy particle on collision - by josemendez - 29-09-2017, 12:01 PM
RE: Destroy particle on collision - by Kalidor - 29-09-2017, 12:30 PM
RE: Destroy particle on collision - by josemendez - 29-09-2017, 02:09 PM
RE: Destroy particle on collision - by KalidorH8r - 26-10-2018, 04:28 PM
RE: Destroy particle on collision - by Kalidor - 29-09-2017, 02:45 PM
RE: Destroy particle on collision - by josemendez - 29-09-2017, 03:03 PM
RE: Destroy particle on collision - by Kalidor - 29-09-2017, 03:54 PM
RE: Destroy particle on collision - by Kalidor - 02-10-2017, 01:40 PM
RE: Destroy particle on collision - by Jaydena - 03-05-2018, 07:28 AM
RE: Destroy particle on collision - by josemendez - 03-05-2018, 08:32 AM
RE: Destroy particle on collision - by Jaydena - 04-05-2018, 01:44 AM
RE: Destroy particle on collision - by josemendez - 18-10-2021, 08:22 AM