Shooting Through Walls With Bullet Penetration in Unity
Lets take a look at how you might build a solution that allows you to fire projectiles through walls of varying sizes. This will combine two different types of raycasts in opposing directions, the first will work as you might expect: a raycast from the end of our gun or whatever else is shooting in the direction the bullet should travel. The second raycast we’ll use occurs only when we have hit an object. When that happens we want to test if our bullet came out the other side.
To test if a bullet has gone through an object we’ll need to things: the first is some measure of how far our bullet or projectile should go into the object we are shooting into. This is important so we can accurately predict whether our bullet has actually traveled through the object and allows more powerful weapons to have more penetrating power than something lighter.
The second feature we need to accomplish this is a way to Raycast against a single specific collider. This is provided by the Unity `` function which allows a ray to be cast against a single collider.
With these two features we can test for basic projectile penetration. First we fire a ray forward until it hits an object. If that occurs we save the collider we struck, the point we hit and move on. We want to continue tracing the projectile from the point it hit and we can do this by adding the point to the result of the penetrating distance times the projectiles forward velocity. This will result in a new point somewhere inside or on the other side of the object we hit.
To test if the bullet has left the object or was unable to fully break through we can use a second raycast which is cast backwards. The goal here is to see if we collide with the back face of whatever object we originally impacted. If we are now hitting the back side of the collider with our ray that means we successfully exited and were able to shoot through the surface. If our ray does not intersect the collider then the bullet has ended up somewhere inside of the surface and never exited the other side.
This entire process can be repeated as needed to allow a single projectile to move through a number of objects before being stopped.
More about the Raycasting functions we used here:
* :
* :
Join the World of Zero Discord channel:
1 view
855
344
9 years ago 00:01:42 225
Shoot Through Drill
7 years ago 00:07:36 78
Top 10 - Gliders Shooting Through Mountain Gaps
8 years ago 00:11:20 178
TF2 - Shooting Through Walls Exploit
11 years ago 00:01:32 152
Prisming Photography Technique / Shooting through a prism -
9 years ago 00:05:47 916
Airsoft Sniper Gameplay - Shooting through knotholes
9 months ago 00:07:13 1
Shooting Through a Windshield
12 years ago 00:01:27 60
» barney + robin • your shooting through the sky
3 years ago 00:04:54 81
Joachim Meyer’s Longsword: Shooting Through
8 years ago 00:07:38 923
Will a Glock 19 Shoot Through Every iPhone Ever?
4 years ago 00:01:57 347
Dash camera captures man shooting through own windshield in Orange County
9 years ago 00:05:05 7
Shooting Through Walls
11 years ago 00:08:52 66
Infestation Survivor Stories Day 107 Shooting Through the Wall!
5 years ago 00:01:06 1
The Shoot-Through
8 years ago 00:01:13 1.7K
New Uses for the Zeus’ (Shooting through walls)
4 years ago 00:36:40 2
Unreal Engine - Shooting Through Walls (2/3)
9 years ago 00:44:18 45
Glider Pilot Shooting Through Gaps in Salt River Mountains
10 years ago 00:02:30 45
Gun Training at the Shooting Range | Through the Lens
5 years ago 00:05:40 76
How To Shoot Through Bullet Proof Glass | Marine Force Recon Technique | Tactical Rifleman
9 years ago 00:02:39 25
Kyle Lamb - Shooting Through a Windshield
5 years ago 00:00:21 112
Shooting through palisad
4 years ago 00:04:36 3
Unreal Engine - Shooting Through Walls (3/3)
5 years ago 00:02:11 19
Ирландец | Фичуретка: Shooting Through Time; Cinematography on The Irishman
1 year ago 00:28:03 1
Shooting Through Walls With Bullet Penetration in Unity