13-03-2019, 09:16 AM
(13-03-2019, 08:38 AM)josemendez Wrote: Hi,
You cannot change the size of fluid particles at runtime, because each one of them represents a fixed volume of fluid. Removing particles one by one is the only method of making fluid disappear.
Thanks! Can you help me with it? I know how delete particles on collision, but i'm not sure how to store all particle after collision and remove it while after some time.
Code:
private HashSet<int> currentParticles = new HashSet<int>();
void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
if (e.contacts.Count > 0)
{
currentParticles = new HashSet<int>();
for (int i = 0; i < e.contacts.Count; ++i)
{
if (e.contacts.Data[i].distance < 0.001f)
{
Component collider;
if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out collider))
{
if (collider == _targetCollider)
{
currentParticles.Add(e.contacts.Data[i].particle);
ObiSolver.ParticleInActor pa = _solver.particleToActor[e.contacts[i].particle];
ObiEmitter emitter = pa.actor as ObiEmitter;
if (emitter != null && emitter.fluidPhase != 4)
emitter.life[pa.indexInActor] = 0;
}
}
}
}
_particles.ExceptWith(currentParticles);
_counter += _particles.Count;
_particles = currentParticles;
}
}