Ok, these is a sort of article to explain some math in WoW.
1. Distance between 2 points
2. Rotation to a degree
3. Rotato to Point - Rotation needed
3.1 Rotato to Point - Rotation
1. Distance between 2 points
To measure the distance between 2 points you need to minilise the X and Y with the X and Y from the points you want to measure. So with this the code will look something like :
(PointX - PlayerX) + (PointY - PlayerY)
Wow, that was alot except one problem, what happens when their are -X numbers ? The distance will be then -145 or so ? Easy, how do we make numbers even in math ? We ² them :-D
(PointX - PlayerX) ^ 2 + (PointY - PlayerY) ^ 2
Ok, now we always get even numbers but another problem : all our numbers are now been (how do you say it in English) calculate with themself ? Or how must I explain it :P but most people would now what I mean, so we need to undo that ^ 2 and their is a math formula for it called Sqrt (if it is that called in English. So I will also put the explantion about it : Any nonnegative expression to get the square-root of).
So :
Sqrt ((PointX - PlayerX) ^ 2 + (PointY - PlayerY) ^ 2)
Will give you a nice good number.
An exemple :
Point X = 5
Point Y = -7
PlayerX = 8
Player Y = 9
Sqrt((5 - ^ 2 + (-7 - 9) ^2) = Sqrt ((-3) ^ 2 + ( - 16 ) ^ 2) = Sqrt (9 + 256) = Sqrt (265) = 16,...
So the distance between 2 points is 16.
2. Rotation to degree
Ok, you have the value of the current rotation of the player. Let's say it is : 3.541145... But what are we with it ? It just looks like a really ugly number or does it ?
From this number we can set it to a degree and with a degree we can calculate how much the player needs to move his rotation to set it to a current point. So let's start.
Rotation = 3.541145
Pi = 3.14159265358979 (try to use the function in your program. AutoIT pi's calculation is : 4 * ATan(1))
So : Rot * (PI * 4) will give you = 44 °
So now you know that your current view is 44° in the WoW world (A view can be from 0 to 360 ° )
3. Rotato to Point
Ok, we have found our own degree etc but how can we calculate how our degree would be when we are pointing to a point ? Easily, with a sort of Tangens (don't know how to call it again in English :P). But we start from the beginning ! I have made here a nice picture how you calculate the tangens :
Yhea, fun but how the **** must we know what is A and B <_<.
Just another formula ^-^
A = PointY - PlayerY
B = PlayerX - PointX
But is this math correctly ? Let's use an example.
The X and Y are wrong, It must be : X is horizontal and Y is Vertical, just a little wrong drawing from me ;-).
So i advise you, to check this if this is true take a paper and every 1 centimeter or so you do + 1 and then calculate :P But believe me, it is correct.
Ok, so now we now the tangens, but we don't need the tangens ! We need to do the Atan * RadtoDeg so we Untangens it :P
Easy code :
ATan((PointY - PlayerY) / (PlayerX - PointX))
(Some people see this as Tan ^ -1). Now we got again a nice good looking rot number. But wtf are we with a rot number ? Nothing so we are going to do the same as previous ^-^. But now if we look very good their will be a uneven number ! So we must kill that one but now it is easier then with ^2 we just do :
Radtodeg = - 180 / Pi
ATan((PointY - PlayerY) / (PlayerX - PointX)) * Radtodeg = Lovely degree :-D where we need to turn to !
But then another problem came :-( their still can be an uneven needed rot. So we are going to do 2 checks a If PlayerX is smaller as PointX then he must check if the degree is under zero and when this happens you just do : Degree = Degree + 360. But when PlayerX is bigger or equal to PointX and the degree is smaller as zero you need to do : Degree = Degree + 360
So the code will look like :
If PlayerX < PointX And Degree < 0 then
Degree = Degree + 360
elseif PlayerX >= PointX And Degree < 0 then
Degree = Degree + 360
Endif
Ok, so now we have calculated what rotation would be needed.
3.1 Rotato to point
We could do a slow way or a fast - tttommeke - way. Instead of rotating we use a sort of change it in memory tacktik. Because when you change it, your character will just follow you.
So we found out that an object is like on 44° from the player and the current player his rotation is 85 ° So we just write in the memory to change it to 44 ° =P But then we need to deconvert it.
So 44 * (PI / 180) is = 0,76794487087750501384642393813499
Then we just do :
_MemoryWrite(Playeraddress + Rotation Offset, $Handle, Degree * (PI / 180), 'float')
Then he will insta switch himself to that point.