Help with Penetration

Hi, I have added 50 cal snipers in my game. In real life these big bore rifles can penetrate through thin concrete walls.

I am using raycasting to deal damage to in-game objects. Now, for example, there is a target behind a wall so, how do I make the raycast hit wall 1, pass through it and hit the target?

I have an idea about using 2 raycasts where the first one collides with the wall and the second one will ignore the wall and just hit the target.

But I would like to just use one raycast and make it pass through at least 1 object and collide with the next one in its path. Is this possible?

I don’t know how much difference it would be, but you could use this? Unity - Scripting API: Physics.RaycastAll

1 Like

Use RaycastAll, as suggested, then organize the resulting hit objects by distance (if this isn’t done already, I can’t remember) and go through them one by one, triggering the impact event for them and checking if they should continue allowing the bullet to penetrate. If and when you get to one that should stop it, simply stop processing the rest of the objects in the list. Be sure to set a proper distance limit on the RaycastAll so that you don’t need to process every single object in 3 miles though (bullets that fly that far wouldn’t be in a straight line anymore anyways).

Order is unspecified, according to the docs… So, definitely sort 'em (and limit the range*) :slight_smile: