I’ve looked at different posts on how to script a wallbang with raycasting. If you don’t know what a wallbang is, it’s a feature in shooter games which allows bullets to travel through thin objects or weak materials (imagine a bullet going through a piece of wood that’s half an inch thick)
The only post that I could find which made sense to me required 3 raycasts:
Raycast number 1:
Detects the wall that the player shoots at, and the 3D position where the bullet enters the wall
Raycast number 2:
Uses TargetFilter on raycast parameters to filter out the wall, allowing the raycast to travel through the wall
I would need to detect where the bullet leaves the wall (I don’t know how to do that) and then find the distance between where the bullet enters and leaves the wall to figure out if the distance is too far for the bullet to wallbang
Raycast number 3:
Actually shoots the bullet (which damages players, creates a bullet hole, etc.)
This requires 3 raycasts per bullet which I could imagine being very performance heavy when the player is using a gun with a fast fire rate (P90 shooting about 1,000 bullets per minute)
Is there a more efficient way to script wallbangs?