Check if player is facing an Object with Tag and set distance away

I have a player who approaches the automatic doors in my game (think Star Trek) and I want to check he’s both facing the door (with the door using a “Door” tag so I can put a few variations in the same category) and that he’s near enough for it to open. This way he can’t walk through it backwards for example, and doors won’t open if he’s too far away from them.

I also don’t want to use a raycast because there’s a collider box around the door, which will apparently stop raycasts working if they do a check within an object’s collider box, but when the player is inside the collider box is when I actually want the door to open.

Any suggestions for a really simple and easily-understandable way to do this?

And please make all the steps really clear without skipping anything obvious, because I’m very bad at figuring other steps you might leave out because you just assume they are a given but that I will need to do to get any of the code to work.

Thanks :slight_smile:

You can use Layer masks to cast rays that will only hit certain objects.

If you move the collision box onto another object or onto a child of the door, you should be able to put just the collider on the Ignore Raycast layer.
From there if you use the Physics.IgnoreRaycastLayer you should be able to cast rays without any issues.