So I’m trying to make a game about Radiation, and so far I’ve made a radiation source and the player who can receive it, and a wall that can protect the player from radiation. But I was wondering if I could do so that some walls only reduce the radiation with 50%. So I was wondering how to make a Raycast go through colliders with specific tags but still know that I has gone through the wall.
You might need to do 2 raycasts to make this work. You can specify a mask in Physics.RayCast to indicate which layers to recognize for a ray hit.
The first raycast would go from the source to the player to determine if the player was hit by the radiation. This raycast would ignore walls.
The second raycast would go from the source to the player to determine if a wall was in the way, and this raycast would not ignore walls.
Assuming the relevant tags are “player” and “wall”, something like this should work (C# example):
var playerHit = Physics.Raycast(
radiationSource.transform.position,
radiationSource.transform.forward,
10
1 << LayerMask.NameToLayer("player"));
var wallHit = Physics.Raycast(
radiationSource.transform.position,
radiationSource.transform.forward,
10
1 << LayerMask.NameToLayer("wall"));
if (playerHit && wallHit) {
// half damage
} else if (playerHit) {
// full damage
}