Calculating Rotation For X,Y in AION

09/21/2009 05:12 nod43#1
I am working on a program that takes two coords from the game (X and Y, Z not relevent), and calculates how far point A (current position) is from point B (target position). However, i am having problems calculating which direction the object on point A needs to be facing (in degrees) to get to point B. I know there is some formula for this, however, I'm clueless.

So lets say my current position in the game is X-996 and Y-1071 currently facing a value of 100 (from what i see rotation is measured on a -180 to 180 scale, north being -90, east being 180, south being 90 and west being 0) and my target location is X-985 Y-1133, how would i go about calculating the rotation at which i need to be facing in order to reach my target position?

Below is the function i am currently using, that doesnt seem to work. what it does is grabs the coords from the objects current position then reads "waypoints" or pre-defined target positions from the text file. after that it tries to calculate the rotation (which is wrong) and then moves in that position towards the target position.

Code:
Func _Turn()
    Local $Cur_Coords = _GetCoords()
    Local $Next_Coords = StringSplit(FileReadLine(@ScriptDir & "\waypoints.txt",$Cur_Waypoint), ",") ;split x, y, z, map
 
    ;-------------------------------------------
    Local $PosX = $Cur_Coords[0]-$Next_Coords[1];x
    Local $PosY = $Cur_Coords[1]-$Next_Coords[2];y
 
                $Next_Rot = _ATan2($Next_Coords[2] - $Cur_Coords[1], $Next_Coords[1] - $Cur_Coords[0]) * 180 / $Pi
 
 
    GUICtrlSetData($Input6, $Next_Coords[1])
    GUICtrlSetData($Input7, $Next_Coords[2])
    GUICtrlSetData($Input10, Floor($Next_Rot))
 
        $Cur_Rot = _GetRotation()
 
        If $Next_Rot = $Cur_Rot Then Return $Next_Rot
 
        While $Cur_Rot <> $Next_Rot And $Run
                $Cur_Rot = _GetRotation()
                _MouseMovePlus()
                GUICtrlSetData($Input5, Floor($Cur_Rot))
        WEnd
 
    Return $Next_Rot
EndFunc
any help much appreciated :rolleyes:
09/21/2009 11:37 Hikkikomori#2
here's a code i used for another game's navigation bot, it's in C# but you can probably convert it to AutoIT.

Quote:
private void FacePositionXZ(double H, Double ToleranceH)
{
double RH = 180;

while (Math.Abs(RH) > ToleranceH)
{
RH = Math.Abs(H - PositionDegree);

if (PositionDegree() > H)
RH = 360 - RH;

if (RH > 180)
RH = RH - 360;

if (RH < -ToleranceH)
{
Aion.SendLeftArrow;
System.Threading.Thread.Sleep(100);
}
else if (RH > ToleranceH)
{
Aion.SendRightArrow;
System.Threading.Thread.Sleep(100);
}

System.Threading.Thread.Sleep(100);

}
}
this is to calculate the heading towards the waypoint,

Quote:
public double HeadingToPosXZ(double X, double Z)
{
X = X - CharacterX;
Z = Z - CharacterZ;
double p = 180 * Math.Atan2(X, Z) / Math.PI;

if (Z < 0)
return p + 360;
else
return p;

}

P.S.: why don't you two just contribute your pointer/offset findings to the community in [Only registered and activated users can see links. Click Here To Register...] thread? :/
no need to keep it for yourself really.
09/21/2009 21:59 Statistician#3
Let's hear it for a useful math major!

It is highly recommended that you make east = 0 degrees, because that's assumed as you do things such as sine, cosine, and tangent. I'm not going to bother assuming east = 180 degrees, sorry.

For your reference:
East = 0
North = 90
West = 180
South = 270

If whatever you're doing is in radians, post here and I'll get back to you. Or just learn this:
180 degrees = pi radians




Let's get to it!

Quote:
So lets say my current position in the game is X-996 and Y-1071 currently facing a value of 100 (from what i see rotation is measured on a -180 to 180 scale, north being -90, east being 180, south being 90 and west being 0) and my target location is X-985 Y-1133, how would i go about calculating the rotation at which i need to be facing in order to reach my target position?
Let us denote the start position as (X1, Y1) and the end positions as (X2, Y2).

Then the angle formed with the closest horizontal axis, assuming the line "x = X1" is the horizontal axis, is:

arctan((Y2-Y1)/(X2-X1))

And there's more to teach you but I'm a tad tired. You probably won't be getting angles that make immediate sense to you, just remember, I'm talking about the angle formed with the closest horizontal axis. Sounds weird, but think about it.


EDIT: Blech forgot to post this earlier today, the above poster beat me to it. Poop skee doop.

EDIT EDIT: Blech, Aion assumes west = 0 degrees. Not much of a hacker nowadays, poop.
09/21/2009 22:29 MetalSlug#4
Something like:

function degreePoints(x1, y1, x2, y2){

if ((x2 - x1) == 0) {
if (y2 > y1) {
radian = 0;
} else {
radian = Pi;
}
} else {
if (x2 > x1){
radian = Pi / 2 - aTan((y2 - y1) / (x2 - x1));
} else {
radian = Pi * 1.5 - aTan((y2 - y1) / (x2 - x1));
}
}

degree = rad2Degree(radian);
return degree;

}

But you'd still have to convert from -90 being north to 90 being north which isn't hard just add 180 and subtract 360 if over 360.
09/23/2009 18:47 kknb#5
Code:
$diff = sqrt((($ownx1 - $targetx)^2) + (($owny1 - $targety)^2))
$erg = Round($diff)
Return $erg