x


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.

more ▼

asked Jun 11 '12 at 01:50 PM

ExTheSea gravatar image

ExTheSea
2k 12 23 30

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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())

more ▼

answered Jun 11 '12 at 02:28 PM

Branx gravatar image

Branx
65 1

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??

Jun 11 '12 at 02:38 PM ExTheSea

How about you shoot the ray again from the HitPosition? Maybe 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..

Jun 11 '12 at 03:47 PM Branx

Thanks for your answer I already had similar thoughts but never found a way they would work myself.

Jun 11 '12 at 03:55 PM ExTheSea
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1528
x329
x150
x70
x61

asked: Jun 11 '12 at 01:50 PM

Seen: 441 times

Last Updated: Jun 11 '12 at 03:55 PM