I need a way to simulate bullet penetration using a raycast.

The system is as follows...

1. Each gun has a max_penetration variable, which determines the thickness of objects it can go through (in godot editor units).
When the gun is fired, it creates a raycast that has the variable current_penetration, which decreases as it passes through objects.
2. If the raycast hits an object, it creates another ray facing the opposite direction current_penetrationunits ahead to find where the bullet would exit. This is to find the thickness of the object, so I can subtract it from current_penetrationand adjust damage accordingly.
3. Add the object as an exception and repeat the process until current_penetration is less than or equal to 0.

This worked fine initially, but then I needed more complex levels.

For level design, I'm using TrenchBroom and the TBLoader plugin for Godot. TBLoader groups meshes based on the TrenchBroom layers, which is a big problem with how my system works. It adds an exception, and now two separate walls that are a part of the same mesh are treated as one wall.

The easiest fix would be a way to determine the thickness of an object without the 2nd ray and just spawn a new ray at the end of the intersection, but I haven't found a way to do that in Godot.

Is there something I'm missing, or is there a way to overcome this? I haven't developed the map or the penetration system too deeply, so I'm willing to make dramatic changes.

TL;DR I have system. Have big flaw. Two walls a part of a single mesh are treated as one wall due to imprecise calculation. No likey. Need help.

  • If the walls are hollow, just start a new ray cast from the point of intersections, plus some small value times the ray direction. It should escape the back side (since I think only facing polys are checked) and then get the hit you want.

If the walls are hollow, just start a new ray cast from the point of intersections, plus some small value times the ray direction. It should escape the back side (since I think only facing polys are checked) and then get the hit you want.

The answer always seems so simple in retrospect, huh... (THANKS)