Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Fluid Particles interaction Script
#6
(19-11-2020, 06:42 PM)JoseCarlosĀ S Wrote: Hi, i didnĀ“t find the spanish volg on the website you linked (It says i dont have permision on the blog)...could you pass me the complete link? How is the sample script going?

Thanks!

Hi,

I didn't link to any website and I don't keep any vlog Huh . I did share an email address: support(at)virtualmethodstudio.com. We can talk in spanish over there.
It's simply for not mixing up multiple languages in the forums, where most people would expect to read english only.

Here's the script. Just add it to the ObiSolver component in the FluidMixing sample scene, and you should see blue and yellow particles disappear as soon as they touch each other. I've commented the script to make it clear what each line does.

Code:
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class KillFluidOnContact : MonoBehaviour
{
    ObiSolver solver;

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

    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 josemendez - 20-11-2020, 10:11 AM