- Home /
Shoot through walls
Hello there guys,
I have a question about raycasts and layers. Is it possible to make it so that if you shoot a wall with a raycast the bullets/raycast passes through the wall if it has a specific layer/tag and then can hit a player standing behind it? I know I could set a layer which get ignored by the raycast BUT... Is it possible that you can make it so that a bullethole and a hitparticle gets instantiated at the point the raycast enters the passable collider?
Btw. I know how to make raycasts, hitcolliders and bulletholes so ther is no need to explain that.
Answer by Branx · Jun 11, 2012 at 02:28 PM
Pretty sure there is no other solution than to cast multiple Rays. Use the RaycastHit class to find out where you want to instantiate bulletholes. Maybe you want to consider writing your own Raycast function that has a parameter for the number of hits and returns an array with z-sorted contacts. (basically a function that calls two or more Physics.Raycast())
I also thought of that and this sounds like a good way BUT.... What if there are 2 passable walls and then a player. I don't think there is a way to get it done so that particles and bulletholes gets instantiated on both walls and on the player. The only way ther would be multiple layers,.....Right??
How about you shoot the ray again from the HitPosition? $$anonymous$$aybe with a little offset to not hit the same wall again. Once the ray has found a target (either a nonpassalbe object or its max. distance), start shooting the ray backwards to find the holes on the rear side of the wall. I understand this may get messy..
Thanks for your answer I already had similar thoughts but never found a way they would work myself.