x


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");
    }
    }
more ▼

asked Mar 23 '10 at 10:55 AM

VinDi 1 gravatar image

VinDi 1
11 1 1 2

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Mar 23 '10 at 11:07 AM

KvanteTore gravatar image

KvanteTore
1.5k 8 15 33

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 23 '10 at 02:14 PM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2482
x172

asked: Mar 23 '10 at 10:55 AM

Seen: 5892 times

Last Updated: Mar 23 '10 at 10:55 AM