- Home /
Cannot get a collision with my player
Hi I'm trying to get a collision between my player and another gameObject. I've added the script to the player, a collider to the player, and a collider to the object. I've tried different types of colliders but no matter what I cannot get a collision. Here's my current version of the code:
function OnCollisionEnter(col : Collision)
{
Instantiate(explosionPrefab, this.transform.position, this.transform.rotation);
Destroy(col.gameObject);
}
I also tried getting OnParticleCollision to work. Copied and pasted the example code from the unity docs, added the script to the object I was hitting with the particles, and the following happened: When I used the standard asset flame as the particle emitter, I could get OnParticleCollision to work. But then I tried using the lightning emitter from the Procedural Examples folder on asset store, I no longer got collision. Here's my particle collision code:
function OnParticleCollision(GameObject)
{
Destroy( gameObject );
}
No idea what I could be missing. Any help much appreciated. Cheers
Answer by clunk47 · Feb 19, 2014 at 06:52 PM
Is your player a rigidbody or a CharacterController? If it's a CharacterController, try using OnControllerColliderHit. Note: This only detects collisions while controller is moving.
Answer by Stormizin · Feb 19, 2014 at 01:37 PM
Did you add the Collider Physics and RigidBody to the objects that you are trying to collide?
Your answer
![](https://koobas.hobune.stream/wayback/20220613134022im_/https://answers.unity.com/themes/thub/images/avi.jpg)