How to give a specific object permissions to go through another specific object

for example, say i have player1 (a cube with a collider), player2 (another cube with a collider), Wall1 (a wall with a collider, and wall2 (another wall with a collider. Normally, if player1 one or player2 tried to walk through wall1 or wall2 two they would not be able to pass through it. What i want to happen is when player1 hits wall1, it will not be able to pass through it, but if player1 hits wall2, it will pass through it instead. taking the collider off wall2 will not solve this problem though, because when player2 isn’t allowed to pass through wall1 nor wall2(player2 will pass through wall2 if wall2 has no collider). So how would i make player1 not be able to pass through wall1, but be able to pass through wall2. player2 must not be able to pass through either wall.

Thanks in advance! If anyone is having trouble understanding what i’m trying to explain i can make a video that shows the problem that i’m having.

You probably want Physics.IgnoreCollision(). It can also be done using the collision matrix: