Prevent triggers going through walls?

I have a sphere trigger that when it comes into contact with a rigidbody, will push it away. The problem is that it affects rigidbodies behind walls too. I don't want it to affect that stuff. So how can I somehow detect and not push rigidbodies if they are behind an obstacle?

I thought of using a raycast to check if sphere can "see" the rigidbody, but the problem is that if there's a small rb hiding behind a bigger rb, the small one is not affected anymore.

Any tips?

1 Answer

1

Try putting the objects that you don't want to interact with your triggers / colliders on a separate layer or tag them appropriately and use that to differentiate between how they react to one another.

It shouldn't matter as long as they are tagged / layered differently. I haven't tested this, it's just a theory.

–