0
votes

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 ")
    }
}
1
i dont think mesh colliders move with the model you have to use simple colliders attached to the rig of the model or the model itselfJRowan
What happens if you set the Collision Detection property of the bullet rigidbody to Continuous Dynamic and the model rigidbody to Continuous?nwellnhof

1 Answers

0
votes

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!