Getting Hit direction to show hit indicator


I am trying to get direction of enemy when his bullet hits a player to show a hit indicator on screen.

I’ve Player’s location, Enemy’s location and all I want to show is from which direction did enemy hit player from (left, right, front or back).

Right now what I am doing is

But it gives direction. I want it in terms of left, right, back and front.

Please help me out on this.

Well, if you know the direction of the hit then that’s everything you need! I think the part you’re overlooking is that you know the direction the hit player is facing (their Forward vector), and you know the direction to the origin of the hit (i.e. to the enemy), you just need to know the angle between these two.

One you know that angle (let’s call it 100 degrees) then you can say “well that’s right and back”, if it were 180 degrees then it’s directly behind you.

I suggest reading up on Dot Products (Unity does provide a Vector3.Dot helper) and something like this might get you started: How to Find the Angle Between Two Vectors: Formula & Examples