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:

Thanks!

I think this should do it ( untested ):

And that 90 should be a 45…

3 Likes

Can be simplified to this:

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

6 Likes

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

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

Yes, replace get actor forward vector with get actor right vector, and you can do it with left and right as well. If you would rather work in degrees, you can take the inverse cosine (acosd), and that will tell you the relative angle around the forward vector, or right vector.

I’m curious is this solution cheaper than using a trace?