x


Machine gun bullets - Raycast or Collider?

I'm trying to figure out which would be the best method to handle machine gun bullets. They don't fire fast enough to warrant using a single Raycast the second they are fired so I am considering which of these two would be more performant:

1) Cast a a single ray very slightly forward from my bullet object every update(). If the ray connect with anything, I can assume my bullet hit something.

2) Attach a trigger collider and a kinematic rigidbody to my bullet and watch for a collision inside my OnTriggerEnter event. The annoyance here is that I'd need to tell it to specifically ignore any collisions with my player, since the bullet spawn inside my player collider. (I know I can use layer masks here, but my Player is not on it's own layer)

Can anyone suggest which method is best or perhaps there is a better option I am missing?

more ▼

asked Aug 11 '11 at 02:03 PM

Disaster gravatar image

Disaster
482 48 57 67

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

2 answers: sort voted first

Use a raycast for bullets, the reason for this is that collisions arent checked all the time but updated x times per second, so if your bullet passes through the collider before the game updates, the collision will not be detected.

If you had a slow moving rocket instead, then you'd use a collider.

Edit: raycast only, most games dont create bullet meshes, but just have some particle effects spray out from the wall where your raycast hits it.

more ▼

answered Aug 11 '11 at 02:05 PM

Kacer gravatar image

Kacer
705 14 17 31

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

I dont know yet, what will be the best approach to make a shoot, but in the case you are using fisic bullets instead of raycast, you can attach this script to your bullets: DontGoThroughThings.js, this will give your bullets a Raycast and no matter how fast your bullets go, they will collide always, that solves the undetected collision on fast moving objects.

If anybody knows if its definitely better using Raycast instead of fisic bullets, please let us know. Thanks!

more ▼

answered Oct 19 '11 at 06:01 PM

Edyvargas gravatar image

Edyvargas
86 12 13 15

(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:

x1865
x308

asked: Aug 11 '11 at 02:03 PM

Seen: 1864 times

Last Updated: Oct 19 '11 at 06:01 PM