hi pipposanta, interesting problem!
Like the others said, the particles won’t collide in the normal sense, but you could loop through the particles testing for closeness and still get an equivalent effect. If our two enemy particles get too close, we kill one or both or do whatever.
The downside is it’s testing array against array, so will scale quite badly, but there are some tricks you could do to improve that. Here is a very quick and dirty example I knocked together to show the concept :
http://www.timdawson.com/unity/watervsfire.html
At first I just had the water and fire particles dying when they touched, but that seemed boring so I added steam puffs at the point where the water died.
Here’s the code that does the work :
var waterEmitter : Transform;
var fireEmitter : Transform;
var tollerance : float = 0.1;
var steamEmitter : Transform;
function Update () {
var waterParticles = waterEmitter.particleEmitter.particles;
var fireParticles = fireEmitter.particleEmitter.particles;
for (var i=0; i<waterParticles.Length; i++) {
for (var j=0; j<fireParticles.Length; j++) {
if (waterParticles[i].energy != 0 fireParticles[j].energy != 0){
if ((waterParticles[i].position - fireParticles[j].position).sqrMagnitude < tollerance) { // for accurate results, we should use "magnitude" but sqrMagnitude gives acceptable results in this case
waterParticles[i].energy = 0;
fireParticles[j].energy = 0;
if (steamEmitter.gameObject.active)
steamEmitter.particleEmitter.Emit(waterParticles[i].position, Random.insideUnitSphere *3, 0.5, 2, Color.black);
}
}
}
}
waterEmitter.particleEmitter.particles = waterParticles;
fireEmitter.particleEmitter.particles = fireParticles;
}
The logic is very simple, just get both particle emitters, get both arrays of particles, then run through them. If you have a lot of particles, this will get very slow, but you could probably do some simple broad phase checks to reduce the work done.
I spawn a steam particle when they hit as an example but other obvious ways to extend this would be to make either the fire or water particle only lose some of their energy on collision - you could have a fire particle that takes multiple water particles to kill it, or visa versa.
Hope this is helpful!