- Home /
Best way to calculate angle between series of Vector3 points
I'm trying to calculate the angle of acuteness between a series of Vector3 points. They will eventually be a waypoint path and the angle will be used to determine how much the agent should slow down based on a sharp turn. I want to do this at waypoint creation rather than when the agent navigates the path. The problem I am having with Vector3.Angle is that it is calculating the angle from the origin point as it treats them as vectors.
Just wondering what would be the best method of going about this. I'm guessing it would probably be normal trigonometry in some capacity but am not sure. I'm trying to determine the vector that is at right angles to both points by using Cross Product but it's not working as intended.
Here's some pictures of what I'm hoping to achieve.
The second drawing looks a little inaccurate, but I'm guessing the almost-vertical edges of those triangles should ideally be totally vertical, like in the top drawing, right?
Here's a question, though: If the use case of this is to slow down the character's movement based on how sharp a turn is, why do you need the angles in the drawing? Shouldn't you be using the angle between two consecutive road segments? Following the logic above, imagine if you have two consecutive road segments which are almost horizontal in the drawing. They'd get an almost 90 degree angle against those vertical lines, making for a drastic slow-down, right? But if they're almost parallel, the slow-down should close to 0 ins$$anonymous$$d - which you'd get if you took the angle between the segment vectors ins$$anonymous$$d.
Yes, that is exactly the angle I mean. :) Doesn't that better denote how sharply the line turns and thus, how much you need the character to slow down?
Well... By "exactly", I mean you have the right concept, but you've drawn it slightly wrong. :) The angle I'm talking about is the angle between two consecutive road segments, if they shared a starting point. That's not entirely the same as you drew. Basically, I'm suggesting this, where the P's are the points, the V's are the vectors between them. The angle you should calculate is theta, and it would simply be Vector3.Angle(V0, V1) in code:
Oh crud, I forgot adding the "V1" label. But it's the lower segment, of course.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I get a normalized vector2D from an angle? 1 Answer
How to find how much an object has rotated? 2 Answers
Trouble Understanding Vector3.Angle() Result 2 Answers
How can I calculate the Vector3 b using Vector 3 a pos with an angle? 1 Answer