Solomon Ubani D King
Solomon Ubani D King

Reputation: 15

Collision detection not working in model

I am trying to detect if a bullet(which has rigidbody and box collider) hit my model(which has CharacterController and a mesh collider) but it doesn't work. If i try the same script on a cube (which also has a CharacterController and a Box Collider) it works perfectly well. I have tried making it a trigger and use OnTriggerEnter but it still doesn't work on the model but also works well on the cube. Here is my code.

function OnControllerColliderHit (hit : ControllerColliderHit)
{       
    //doesnt work for either of them   
    if(hit.gameObject.tag == "bullet")
    {
        print("i have been hit by a bullet");
    }
}

function OnTriggerEnter(hit : Collider) 
{
    //works for the cube and not the model
    if(hit.gameObject.tag == "bullet")
    {
        print("i have been hit by trigger hit ");
    }
}
function OnCollisionEnter(hit: Collision) 
{
    //works for the cube and not the model
    if(hit.gameObject.tag == "bullet")
    {
        print("i have been hit by trigger hit ")
    }
}

Upvotes: 0

Views: 2806

Answers (1)

Nuno Duarte
Nuno Duarte

Reputation: 1036

Collision detection for character controller only works when the two objects collided contains character controller.

Therefore your bullet does not conflict with your model.

Your cube it collides with the model because it contains character controller. If you remove the box collider, cube it will still detect collision with the model.

You have to choose which collision system will use.

If you add a character controller on bullet the collision will work.

Hope this helps!

Upvotes: 0

Related Questions