Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Fluid Particles interaction Script
#19
(22-11-2020, 04:35 PM)JoseCarlos S Wrote: I added this code (to the Kill fluid script you passed). But its seems to not be working (it dosent set the speed to 0)... any advice? Thanks!

using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class KillFluidOnContact : MonoBehaviour
{
    ObiSolver solver;
    ObiEmitter emitter;
    public float targetTime = 2.0f;


    void Awake()
    {
        solver = GetComponent<ObiSolver>();
        emitter = GetComponent<ObiEmitter>();
     
    }

    private void Update()
    {
        targetTime -= Time.deltaTime;

        if (targetTime <= 0.0f)
        {
            timerEnded();
        }

    }

    void timerEnded()
    {
        emitter.speed = 0;
    }


    void LateUpdate()
    {

       
        if (!isActiveAndEnabled)
            return;

        // iterate over all particles in the solver, looking for particles
        // that have had their diffusion data altered by contact with other particles.
        for (int i = 0; i < solver.particleToActor.Length; ++i)
        {
            // if this particle is part of an actor,
            if (solver.particleToActor[i] != null)
            {
                // if the "user" (aka diffusion) data is not either (1,0,0,0) or (0,0,0,0)
                if (solver.userData[i].x < 0.9f && solver.userData[i].x > 0.1f)
                {
                    // take a reference to the emitter that the particle belongs to, and kill it.
                    var emitter = solver.particleToActor[i].actor as ObiEmitter;
                    emitter.KillParticle(solver.particleToActor[i].indexInActor);
                }
            }
        }

    }
}
Reply


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