06-07-2021, 10:29 PM
Hi,
I've been trying to simulate an evaporation/destruction event when fluids touch certain surfaces, where the obi fluid particle position is used to instantiate a particle effect that matches the fluid colour. In general this is just a collider check, wait until particle has sat on surface longer than a given time, then take position and colour, instantiate smoke and kill particle. This works at first but it quickly results in the smoke effect spawning randomly in previously used locations, immediately on particle contact, which I feel may be the result of the particle ID numbers being reused. When I separate all of the actual emitter.life = 0 events into a separate foreach loop at the end of the collision event by making a list of the affected particles after the smoke effects should have been completed I still see the same behaviour. I have attached the trimmed down code as an example.
Any help would be most appreciated!
I've been trying to simulate an evaporation/destruction event when fluids touch certain surfaces, where the obi fluid particle position is used to instantiate a particle effect that matches the fluid colour. In general this is just a collider check, wait until particle has sat on surface longer than a given time, then take position and colour, instantiate smoke and kill particle. This works at first but it quickly results in the smoke effect spawning randomly in previously used locations, immediately on particle contact, which I feel may be the result of the particle ID numbers being reused. When I separate all of the actual emitter.life = 0 events into a separate foreach loop at the end of the collision event by making a list of the affected particles after the smoke effects should have been completed I still see the same behaviour. I have attached the trimmed down code as an example.
Any help would be most appreciated!
Code:
void Solver_OnCollision (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (Oni.Contact contact in e.contacts)
{
if (contact.distance < 0.001)
{
ObiColliderBase collider = world.colliderHandles[contact.bodyB].owner;
if (collider != null)
{
if(collider.tag == "Evaporate"){
Vector4 userDataUpdate = solver.userData[contact.bodyA];
userDataUpdate[0] = userDataUpdate[0] + Time.fixedDeltaTime;
solver.userData[contact.bodyA] = userDataUpdate;
if (userDataUpdate[0] > evapTimer){
ObiSolver.ParticleInActor pa = solver.particleToActor[solver.simplices[contact.bodyA]];
ObiEmitter emitter1 = pa.actor as ObiEmitter;
Transform emitterTransform = emitter1.transform;
Vector3 particlePosition = solver.positions[contact.bodyA];
GameObject smoke = Instantiate(evaporationSmoke, particlePosition, Quaternion.identity);
Material smokeMat = smoke.GetComponent<ParticleSystemRenderer>().material;
smokeMat.SetVector("SmokeColor", solver.colors[contact.bodyA]);
emitter1.life[pa.indexInActor] = 0f;
}