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?
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.
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!
answered Oct 19 '11 at 06:01 PM