GameObject particleSystemPrefab;
void OnCollisionEnter(Collision collision) {
foreach (ContactPoint contact in collision.contacts) {
//Instantiate your particle system here.
Instantiate(particleSystemPrefab, contact.point, Quaternion.identity)
}
}
This will instantiate a particle system at each contact point but if you want you can instantiate at certain points like only on first contact point or so by writing those conditions.
Thanks A lot dude. This is great! It worked. But I was doing a few testing with other emitters and when I tried to do a water ripple emitter with Collision Stay. It Emits waaaay to much particles I'm glagd it didn't crash my Cpu. Although collision enter works very nicely, it doesn't keep emitting from a different spot as my object moves. So is there a way I can also put a timer on my particle, for like an Emitting ratio time?
You can set the Emission Rate for your particle system to control how the particles are emitted. Or you can even set the particle lifetime as per your requirements. You need to play with various particle system attributes in order to achieve the effect you want. Also in order to make the particle system with the object you can make your instantiated particle system a child of that object so it will stay at the same position relative to that object.
Umm. I still cant find a work around this. I changed the emission ratio for the particle and everything. OnCollisionStay still keeps emitting too many particles. This is what I'm doing. I have a Sphere with a collider and rigidbody, and the I'm dropping it down on a simple plane collider. As it stays on that plane it emits my particles. But way too rapidly. Is there a way I can reduce the collision detection or something? Its drivig me nuts..
Just instantiate the particle system in OnCollisionEnter and then you can make the particle system to emit the particles at the start of the particle system and set this particle system to loop. So the particles will only be emitted each time the particle system loop starts. You can then stop this particle system once the collision exits (in OnCollisionExit).
ALRIGHT!ITS WORKING THANKS DUDE REALLY! But.. Man there's one more issue.. When my Sphere drops and enters the planes collider it constantly emits in that same exact spot. Its not the particle that's following my cube its like a duplicated clone.
Since this still shows up early in google I thought I’d add this!
You should avoid instantiating objects as it’s very inefficient. You can get away with it as a one off here and there, but using it regularly (as well as destroying things) will kill your performance.
Use object pooling instead. You have a “pool” of the object in your scene, and just take them from the pool and enable/disable them instead. It’s easy and you can find a great explanation and tutorial on it at https://www.raywenderlich.com/136091/object-pooling-unity
Thanks A lot dude. This is great! It worked. But I was doing a few testing with other emitters and when I tried to do a water ripple emitter with Collision Stay. It Emits waaaay to much particles I'm glagd it didn't crash my Cpu. Although collision enter works very nicely, it doesn't keep emitting from a different spot as my object moves. So is there a way I can also put a timer on my particle, for like an Emitting ratio time?
– Xeong-HuYou can set the Emission Rate for your particle system to control how the particles are emitted. Or you can even set the particle lifetime as per your requirements. You need to play with various particle system attributes in order to achieve the effect you want. Also in order to make the particle system with the object you can make your instantiated particle system a child of that object so it will stay at the same position relative to that object.
– HarshadKUmm. I still cant find a work around this. I changed the emission ratio for the particle and everything. OnCollisionStay still keeps emitting too many particles. This is what I'm doing. I have a Sphere with a collider and rigidbody, and the I'm dropping it down on a simple plane collider. As it stays on that plane it emits my particles. But way too rapidly. Is there a way I can reduce the collision detection or something? Its drivig me nuts..
– Xeong-HuJust instantiate the particle system in OnCollisionEnter and then you can make the particle system to emit the particles at the start of the particle system and set this particle system to loop. So the particles will only be emitted each time the particle system loop starts. You can then stop this particle system once the collision exits (in OnCollisionExit).
– HarshadKALRIGHT!ITS WORKING THANKS DUDE REALLY! But.. Man there's one more issue.. When my Sphere drops and enters the planes collider it constantly emits in that same exact spot. Its not the particle that's following my cube its like a duplicated clone.
– Xeong-Hu