Collision between 'bullet' and object

I need to detect when a fired bullet hits a Cube GameObject, but I'm kinda failing

I am now using the script below, attached to my launcher (which is connected to my FPS controller), which shoots out spheres that have a Sphere Collider and a Rigidbody. I can't seem to get this working :/ (the Doorupperleft is a gameobject that I'm using to test the colliderhittest, it has trigger disabled and has a box collider)

So, mainly I just need to be able to get the collision thingie working, I'm failing bigtime :x please help!

    function OnControllerColliderHit(collision:Collision)
    {
    if(collision.gameObject.tag == "Doorupperleft")
    {
        Debug.Log("yay");
    }
    }

I assume you have an object with tag "Doorupperleft", and not an object named "Doorupperleft"?

If so, could it be that the bullets are small and moving too fast, and can therefore be on one side of the door in one frame, and passed through the door on the next frame? You could test this by making the collider of the door thicker.

If this is the problem, consider using raycasts to detect your bullet collisions.

If you bullet is moving very fast it could be on one side of the door in one frame and on the other side in the next frame, which would prevent the physics engine from detecting the collision.

You can fix that by using raycasts:

  • Either just use raycasts instead of an actual collider for the bullet. This is a great solution if your bullet is going so fast that it's not going to be seen anyway (like a real bullet).

  • If your bullet goes slow enough to be seen, you can still use a collider but use raycasts to detect collisions that the physics engine might miss. There's a script on the wiki - DontGoThrouhThings - for that.