- Home /
Why isn't my OnParticleCollision working?
I have a large particle system ("Soul") which I want to detect collisions. I have some other particle systems called "Demons" which travel towards the "Soul". If the demons collide with the soul then they should be destroyed and make the soul do some iTween stuff.
My OnParticleCollision in a script attached to the soul looks like this:
function OnParticleCollision (other : GameObject) {
print("abc");
if(other.tag == "Demon")
{
iTween.ColorTo(gameObject, Color.red, 0.2);
iTween.ColorFrom(gameObject, Color.red, 0.2);
Destroy(other);
}
}
However I cannot even get the method to Print "abc". Both the soul and demons have world particle colliders. The soul has the "Send Collision Message" box ticked. All objects are tagged correctly.
I have tried adding colliders to both objects but with no luck...
Any ideas as to why this won't work??
Answer by equalsequals · Apr 27, 2011 at 06:11 PM
Unity does not support particle-to-particle collision. The calculations and SendMessage overhead would be such a performance killer that you wouldn't want to do it anyway, even if you could.
With that said what you could do is use a general collider that is the general shape of your character, this could be a capsule for an oblong shape, or sphere if you aren't adding any directional velocities to your ellipsoid emitter (assuming you are using one and not a mesh emitter).
This will be far more efficient and if done right, you likely won't be able to tell the difference.
Hope that helps.
==
I didn't realise this and thinking about it that would be a lot to calculate. I've simply added an empty gameobject with a collider around the player and it all works fine. Thanks for the answer.
Answer by AngryOldMan · Apr 27, 2011 at 06:20 PM
use the gameobject that the particles are attached to in order to detect collisions. Assuming your player isnt just a single particle floating about which you can some how control? A little more about how your game is set up would be useful if possible, like equalsequals says unity cant detect particle to particle collisions so you are going to have to use a work around to get the same effect but using different methods, if you tell us how it is set up we can tell you possible work arounds :)
Answer by xCRKx TyPHooN · Apr 25, 2011 at 04:37 PM
I haven't messed with particles myself, but here is a link to Unity's documentation that should help. Be sure to read the paragraph above the code that describes exactly what you need in order for the collision to register.
Hi, I read this prior to posting and am already acquanted with the set up.
Answer by Ben Holmes · Apr 27, 2011 at 05:55 PM
If you re-read the paragraph the other user linked to you it says that OnParticleCollision is called when a particle hits a collider. This means that the object you want to be able to collide with needs to have a collider on it. I don't believe Unity's particle system allows single particles to have their own colliders so it seems that getting collisions between particles in this way doesn't work.
GesterX did mention that he'd tried attaching colliders to his objects without any luck. Perhaps if there was something amiss with how he went about doing it?
adding a collider to the particle emitter gameobject doesn't help because the particles which are emitted still don't have colliders (and can't).
Answer by CarlLydon · Apr 17, 2014 at 12:44 AM
You can always code your own particle system using meshes with colliders on them. Particles are pretty fun and easy to program so maybe that would work for you?
Your answer
Follow this Question
Related Questions
Collide with Non-Moving Particle 0 Answers
Why can't I add non-prefab colliders to a particle effects triggers list? 0 Answers
OnParticleCollision only working for some objects and some particle emitters 2 Answers
Collision on zero-velocity particle 1 Answer
Position of an individual particle 1 Answer