Hi there folks.
I know this isn’t a maths forum, and I’m sure this must have been asked before, and yes I’ve searched, but I can’t find a working answer. I need to calculate the angle between two points. For this example we could assume the following:
Character A is at position 0,0.
Character B is at position 6,4.
And I need the angle from A to B.
Normally we would calculate the vector, but in this case it’s obviously 6,4. Or 3,2.
So if I Atan2(4,6) I should get the radians.
Then If I r*180/Pi I should get the degrees.
Dim x As Single = 6
Dim y As Single = 4
Dim r As Single = Math.Atan2(y, x)
Dim d As Single = r * (180 / Math.PI)
I have checked this with converters and calculators and the result is 33.69 degrees, give or take a couple of thousandths. I don’t dispute the results, but it’s not what I was expecting. Given the starting vector of 6,4 I was expecting a degrees value of over 90, probably around 110 (on screen direction)
Now, if I add 90 degrees to the result I get 123, which is round about what I was expecting, but as the values change they drift away from my required results.
If I start with a vector calculation from another quadrant (other direction) I get results that confuse me more!
I have tried negative values for different quadrants and still I’m confused.
I’m sure I’m missing something so idiotically simple. Could someone please help my befuddled brain?