Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Fluid Particles interaction Script
#7
[attachment=812 Wrote:             josemendez pid='8245' dateline='1605863505']
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);
                }
            }
        }
       
    }
}


Nice! And if i wanted to kill both particles? Okay, didnt realize it was an email adress, thought there was a spanish forum, ill mail you my next questions (wich i promise ill have a few.... Lengua). But lets finish this thread here, so people can find it and maybe help them.

On the sample it works perfectly, but on my own ObiSolver i get this fatal Error:
   
Thanks!
Reply


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