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
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. **** skee doop.
EDIT EDIT: Blech, Aion assumes west = 0 degrees. Not much of a hacker nowadays, ****.
Calculating Height, Z axis 06/07/2010 - Kal Online - 36 Replies Yo yo,
Any of you got experiences with implementing correct moving system in Kal by packets?
What is the best way to calculate it correctly?
I am doing like that.
Calculating step in X axis and Y axis. Then calculate Z step like that.
MoveZ = CurrentPlayerZ - GetHeight(CurrentPlayerX+MoveX, CurrentPlayerY+MoveY);
Ofcourse its not complete thinking as every step must be reversed by multiplying it by -1. Calculated CoordZ must be multiplyed by 10.
Given X and Y arguments to GetHeight...
Calculating damage 05/11/2009 - Silkroad Online - 10 Replies How do you can calculate silkroad damage? not average damage. but every factor like
how accesory change that damage?
how other buff attack buff change it?
how the damage change when it hits more that 1 target?
Calculating Eudemon checksum 04/04/2008 - EO PServer Hosting - 1 Replies Hi all,
i was wondering if anyone knew what the function is that EO uses to calculate the chksum field in the cq_eudemon table? I tried to find it in the source code, but came up blank.
Any help is appreciated :)
Calculating Atack or MAtack 05/04/2007 - CO2 Guides & Templates - 4 Replies Sometimes you wanted know the atack of an trojan and him dont told you?
with thats easy guide, you just need open him equipaments window!
"JUST 1 percent error"
TROJAN ATACK:
The follow instructions is both used to lower and higher atack:
Calculating Hours of Pkp 11/23/2006 - CO2 Guides & Templates - 15 Replies Ever have a black name or more than 30 pk points? This is how to calculate The total time u will have to wait for those 'awful' pk points to get off.
1. Multiply # of pk points by 6. (EX- 100pkp X 6 =600)
2. Divide that number by 60. (EX- 600 / 60)
3. The end number will be the # of hours it will take to get your pkp off.