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
1113
406
13 hours ago 00:03:47 1
Color-Me-Crazy Lighting Beast: The Aputure Amaran 300c That’ll Melt Your Boring Gear Regrets - YouTube
3 weeks ago 00:15:40 1
Master Reboot, Gameplay Playthrough w/ Facecam Part 8 (Fairground Memory) - CANDY AND BUMPER CARS!
6 months ago 00:07:16 1
Ana Čižmek plays M. Castelnuovo-Tedesco’s “Caprichos de Goya: No Hubo Remedio“ on a Jean-Noël Rohé
6 months ago 00:03:50 1
Sleaford Mods ft. Amy Taylor - Nudge It (Official Video)
6 months ago 00:03:26 1
Parmalee - Gonna Love You (Official Music Video)
6 months ago 00:12:16 1
Fairfax Police Officer Shoots Woman After She Slashes His Face
6 months ago 00:48:51 1
Dark Origins of the Matrix EXPOSED - Satanic Secrets illuminati Gnostic Film Theory
6 months ago 00:53:15 1
Rui Palha: A Legend in Street Photography
6 months ago 00:30:54 1
The Shark - The Most META Zerg Base in 2022 - Rust Base Tutorial 4K
6 months ago 02:06:31 1
Ex-Mormon Exposes All: Masonic Secret Societies | LED Live • EP88
6 months ago 00:16:01 1
🚨BREAKING: CAUGHT ON TAPE! “Line Up Trump Voters, Shoot Them“ - Prof’s SICK Classroom Rant Exposed!
6 months ago 00:04:38 1
Sunstorm - “Love’s Not Gone“ - Official Video
6 months ago 00:07:03 1
Tupac-2 of Amerikaz Most Wanted Live from:The House of Blues.
6 months ago 00:02:26 25
[GTA.W] HoodTalk (Official Video)
6 months ago 00:02:21 1
How To Convert HLG Footage to in Premiere Pro
6 months ago 01:04:57 1
Toxic Crusaders (SEGA GENESIS/MEGA DRIVE) Longplay/Walkthrough NO COMMENTARY HD 1080p
6 months ago 00:00:16 1
.50 BMG Raptor 50 vs. DA Targets
6 months ago 00:04:12 1
29,000 Feet Up Mount Everest with DJI Mavic 3 Pro
6 months ago 00:02:45 1
FNF - Friday Night Funkin’: Pibby Corrupted 1.5 - Wish Come True (FC)
6 months ago 00:06:36 3
SUICIDAL ANGELS - Bloody Ground (OFFICIAL VIDEO CLIP)
6 months ago 00:10:32 1
John F. Kennedy’s speech in Berlin
6 months ago 00:05:28 1
Angélica Garcia - El Que
6 months ago 00:01:51 1
屋根の漏り (Yane No Mori) | Risk of Rain 2: Seekers of the Storm | Guitar Solo Playthrough
6 months ago 00:15:43 1
An evening on the BNSF Hereford Sub: July 23, 2024