Getting Hit direction to show hit indicator
Hello,
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 http://answers.unity3d.com/questions/801419/get-hit-direction-from-one-gameobject-hitting-anot.html
But it gives direction. I want it in terms of left, right, back and front.
Please help me out on this.
Answer by phil_me_up · Mar 01, 2016 at 12:31 PM
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: http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors
Your answer
![](https://koobas.hobune.stream/wayback/20220612070144im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Plane.RayCast not hitting at all 0 Answers
Slowing down while loops 2 Answers
How to carry over remaining damage hit points from armor to health? 1 Answer
NullReferenceException when changing Canvas text via code 0 Answers
http://answers.unity3d.com/questions/8472/help-with-error-expression-denotes-a-type-where-a.html 1 Answer