How to tell if something is in front of the player, and if so by how much?

So I’m making an FPS and I’ve got enemy spawn points in my level that use dot product to determine whether they’re in front of or behind the player (as well as a bunch of other voodoo to test whether they’re being rendered or have been rendered recently). The problem I’m having right now is that the spawn points directly to the side of the player, while not technically behind them, and not rendered, are not viable from a gameplay standpoint unless I want enemies to spawn in, flank the player, and subsequently stomp the snot out of them.

Let you in on a little secret, I don’t want that, but that’s what I’m currently getting.

Is there any math kung fu I can layer over my current ‘in front of’ script to weed out these side points? Here’s my current setup:


I think this should do it ( untested ):

And that 90 should be a 45…

1 Like

Can be simplified to this:

And that’d need no normalisation, too. More here:


Thanks much to you both, seems to work like a charm!

Can this be used for enemies on the left and right?