- Home /
Shuriken collision detection is sparse
I'm having trouble with my particle collisions. They seem to happen much less frequently than it would seem they should. In this picture, the system has an emission rate of 100 and has been emitting for a few seconds already, but the collision detection has only registered three hits.
Here's my code for the particle system:
using UnityEngine;
using System.Collections;
public class SprayGun : MonoBehaviour {
public float freezeDecrement = 10.0f;
private ParticleSystem prtSys;
private CharacterInput scriptCharInput;
void Start()
{
prtSys = GetComponent<ParticleSystem>();
scriptCharInput = GameObject.Find("Character").GetComponent<CharacterInput>();
}
void OnParticleCollision(GameObject other)
{
ParticleSystem.CollisionEvent[] colEvents = new ParticleSystem.CollisionEvent[prtSys.safeCollisionEventSize];
int numCollisionEvents = prtSys.GetCollisionEvents(other, colEvents);
for (int i = 0; i < numCollisionEvents; i++)
{
if (colEvents[i].collider.name == "Character")
{
scriptCharInput.xTransferEnergy -= freezeDecrement * Time.deltaTime;
print("BOOM");
}
}
}
}
Any ideas? Does it have anything to do with using World (currently selected) vs Plane collision? I couldn't find any good documentation explaining the difference.
Answer by Cherno · Oct 21, 2013 at 11:01 PM
World Collision means that the particles will collide with any colliders that are in one of the layers specified in the dialog. Plane means just that, you have to specify which planes in your scene will act as colliders (I guess it's only rarely useful, such as when there's a completely flat ground). You can also, if using world, set the collision quality to high and see if that helps.
Thanks. I do have my collision set to High, so I'm not sure where to look next. It also doesn't seem to matter if they are billboards or cubes.
$$anonymous$$aybe do a purely visual approach for testing purposes. Disable the script, and just set up everything in the Collision dialog of the Particle System, and see if the particles hitting colliders actually fall through without colliding or if most of them stop. Then you at least know if it's a script or general issue. For this case, the plane collison might come in handy for once :)
The particles are definitely colliding a lot, but with the ground mostly. It's not a problem of collision.