Heya,
So what exactly are you trying to do with this as that will determine how to approach it.
What you can try is putting a collision box behind the player and parent to the player. Anything within that box can be consider behind them but may not work if you need to detect further away.
I have the enemy jumping on the player if they get too close, so depending on what way the player is facing when this happens, it will play the corresponding animation set.
Or raycast towards the player, with a hit box behind and a hit box in front, to see which one the ray hits?
That was my first approach but I'm trying to avoid using unique hit boxes for everything so I'm not dealing with all kinds of layers. I just have a hard time warping my head around them and the further along the game gets, the more I'm likely to need. The less the better I'm thinking.
[...]
Just check the distance to the camera for both your player and ennemy, use the square distance, it's faster then the real distance to to math.
[...]
Is this suggestion for a static camera? I have a free camera the player controls with the mouse or right analog stick on the game pad. It rotates around a 3rd person character so I'm not sure checking distance to it will work consistently. I could be misunderstanding you though. If you could explain in a little more detail.
--
I stumbled on to a kind of solution while looking at some C# scripts made for doing something similar:
Once the player is in range of the enemy, it gets the position of both the player and itself. It subtracts the two using the operator action to find the direction and then normalizes it. It takes the z direction of the player and turns it into a world space vector which is used in another operator along with the player transform to make a dot product which ends up being a float value somewhere around -1 or 1 depending on which way the player is facing.
This seems to work for the time being but I was using a lot of guess work to make it so I'm unsure if this is a good solution or if there is a nicer way to the same thing.
Thanks!