Having trouble detecting collision with the player controller or the collider

I have been trying for a while to detect collision between the Player and a Projectile. It just isn’t detecting any of it. They bot have rigid bodies and colliders with IsTrigger checked.

    void OnCollisionEnter(Collision collider)
    {
        print("collision!");
        if (collider.gameObject.tag == "Player")
        {
            print("Hit Player");
        }
    }

Uncheck “Is Trigger”. If you use that, you have to use OnTriggerEnter(), which essentially turns off the physics and treats the collider as a trigger object only.

In JS;

function OnCollisionEnter (hit : Collision)
{
if (hit.gameObject.tag == "Player")
{
print ("Hit Player");
}
}

Thanks for the help i’m going to test it soon.

I’m still having problems. When using that basic code even just for a debug unity tells me Function must be of type Collision. Well the message must. It’s code CS0161

Not sure what’s wrong. perhaps you can post your entire code. Also, what do you have it attached to?

Script Error: OnTriggerEnter
This message parameter has to be of type: Collider

I have the script that detects a trigger enter on a player with a Character controller. He has a Rigid Body and the object that is going to hit it has a sphere Collider and Is Trigger is checked.

Change

function OnCollisionEnter (hit : Collision)

to

function OnCollisionEnter (hit : Collider)

Wow thanks man that worked. I’m surprised i had not seen that this whole time. It’s one of those tiny things that you can’t believe you missed it.

my bad. I guess I gave you the wrong info. Although, the following link confuses me in that case:

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

I thought the Collider class was for OnTriggerEnter() only.