Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get an angle between 3 points?

I need to get the angle between the direction ball A is moving and Ball B on the x and z axis. Also i am using Unity Netcode (idk if it makes a difference or not)

enter image description here

so far i have tried to get i with 3 points
A-ball A position,
B-ball B position,
C-ball A position on last frame.
i’ve tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

float angle = Mathf.Atan2(B.y - A.y, B.x - A.x) - Mathf.Atan2(A.y - C.y, A.x - C.x);

and it gave me an angle but it was nowhere close to what it should have been. Then i copied some Acos code off of here but that didn’t work ither.

float dot = C.x * B.x + C.y * B.y;
float angle = Mathf.Acos(dot);

then i tried Vector3.Angle and it sometimes worked but sometimes it didn’t.

float angle = Vector3.Angle(B, C);

plz help, i’m new to this.

>Solution :

A, B and C are not vectors, they are points. If you want to compute the angle between two vectors, you should use B - A and A - C.

float angle = Vector3.Angle(B - A, A - C);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading