Angle between enemy and player
Hi, how i calculate angle in degrees between enemy tank and me? I fire on the tank and i need calculate angle. I have position of hit point from Physics.Raycast. I tried Vector3.Angle() but resulting angles have bad values. The enemy tank has different positions and i need it calculate in local space. Example on picture:
Thanks for advices.
Vector3.Angle( me.transform.position - tank.transform.position, tank.transform.forward)
should do the trick. Please, edit your question, provide the code you have tried, the result you have and the result you expect.
Yes i use this cody what you write, and the resulst are good but when I move in front of the tank the angle is around 3 degrees but i want 90 degrees because my weapon and front armor of enemy tank give 90 degrees angle, if you know whati mean and i dont know how to solve this problem. Example in picture:
$$anonymous$$y code:
if (Physics.Raycast(_startPositionTransform.position, _startPositionTransform.forward, out hitInfo))
{
Debug.Log("Detecting collision with: " + hitInfo.transform.name);
Vector3 direction = _startPositionTransform.position - hitInfo.transform.position;
float angle = Vector3.Angle(direction, hitInfo.transform.forward);
Debug.Log("Angle is : " + angle);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612191436im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i force collision angle 1 Answer
How to calculate the tilt angle of an object? 0 Answers
How to make the object return to its last angle (before the angle limit) go back no so abruptly ? 0 Answers
Move a game object away from another game object based on the angle difference 1 Answer
Find First Parentheses in String 2 Answers