Explosions that can't damage players through walls

Hello, I’m currently working on explosive items for my game, and I’ve encountered an issue that I’m pretty uncertain how to solve. Could there be a way to script an explosion that’s unable to damage players through walls? I’m not familiar with Raycasting, so if you have any solutions that would be able to help me I would really appreciate it.

1 Like

Is it only a specific type of wall tht they can go thru? Or can it go thru any object and hit the player if they are close enough?

The explosion can damage any player through parts/walls, although the grenade & player must be close to the wall, then the player will take damage.

Oh well since you added the close to a wall specification. I would use raycasting. You cast from grenade to player with a ray the size you specify. If it hits a wall you cast another ray from the hit position of the first to the player but this time you filter the wall so it isnt detected.

How would I go about making this script? I’m a bit new to Raycasting as I don’t use it as much…

Raycasting is actually very straight forward. You call the function ,provide a starting position and a direction. The length of the direction vector is how far the ray will travel.

The direction from point A to B is always
equal to B - A and from point B to A is equal to A - B

1 Like

Alright, I’ll check it out and try again after I learn a bit of Raycasting, thank you for the help, I really appreciate it!