Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Fluid Particles interaction Script
#33
(27-11-2020, 03:38 PM)josemendez Wrote: You can't just add this script to a emitter, programming doesn't work that way :/.
You should check if the particle belongs to a certain emitter, depending on the result you decide if you destroy the collider or not. To retrieve the emitter a particle belongs to, you can do:

Code:
ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
ObiEmitter emitter = pa.actor as ObiEmitter;

See "Retrieving the actor involved in a contact": http://obi.virtualmethodstudio.com/tutor...sions.html


Should look something like this? (No reaction to any fluid/emitter yet):

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

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

    ObiSolver solver;
    public ObiCollider2D player;
    public ObiEmitter emitter;
   

    Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

    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)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
                ObiEmitter emitter = pa.actor as ObiEmitter;

                ObiColliderBase collider = world.colliderHandles[contact.other].owner;
                if (collider == player && emitter == player)
                    GameObject.Destroy(collider.gameObject);
            }
        }
    }

}
Reply


Messages In This Thread
RE: Fluid Particles interaction Script - by JoseCarlos S - 27-11-2020, 04:00 PM