Well, I'm going to kick the compass and minimap angle functions out of SCAR soon because I feel that it's more convenient for the scripters to make them themselves so they can also be fast and easily updated. And I'm confident that they will do a great job for it, so I'm releasing the math algorithm for my compass function. (Not saying it's better than what people are currently using, but it might offer some insight...
SCAR Code:dX1 := mx - tx;
dY1 := my - ty;
dX2 := mx - pp.x;
dY2 := my - pp.y;
tmp := ((dX1 * dX2) + (dY1 * dY2)) / (Sqrt(Sqr(dX1) + Sqr(dY1)) * Sqrt(Sqr(dX2) + Sqr(dY2)));
Result := Abs(ArcCos(tmp) - Pi);
if pp.x > mx then Result := 2 * Pi - Result;
mx and my are the coordinates of the center point of the compass.
tx and ty are the coordinates of the middle, top point of the compass. (The highest point on the compass, at the same x coordinate as the center)
pp is the point at which the South indicator is located.
As some might've noticed, my algorithm is based on the law of cosines.
(Note that this is for calculating the radians)
(You might also have noticed that "dX1 := mx - tx;" will always be 0, but I just made it that way in case I'd ever need to change it)
if you leave out dX1 you'd get:
SCAR Code:dY1 := my - ty;
dX2 := mx - pp.x;
dY2 := my - pp.y;
tmp := (dY1 * dY2) / (dY1 * Sqrt(Sqr(dX2) + Sqr(dY2)));
Result := Abs(ArcCos(tmp) - Pi);
if pp.x > mx then Result := 2 * Pi - Result;









Reply With Quote




















{not sure how to spell it in english}, so trigonometry is still an unkown area for me {I'm only a 9th grader atm}). But still, thanks a lot, will be a nice challenge. 