Runescapian321
2010-06-13 00:45:42
I'm trying to make a function in reflection (so I'm using Simba) that finds the camera angle that you need to use to point towards a certain tile.
Here is what I have (technically it should be fully functional):
I've tried testing, and it works most of the time, except when you're northeast or southeast of the tile. For example, I'm 4 spaces south and 2 spaces west of the tile. The function tells me the angle is about 18 degrees and thus shifts the compass to 288 degrees (north east east), when it clearly should be much closer to 360 degrees and north north east. Something is probably wrong with my math leading up to the ArcTan, anyone see the problem?
EDIT: Tested some more and it seems being directly south and directly east to the tile also don't work
Here is what I have (technically it should be fully functional):
function GetTileDir(Tile: TTile): Extended;
var
Adjacent, Opposite: extended;
MyPos, MyTile: TPoint;
begin
MyPos := TileToPoint(GetMyPos);
MyTile := TileToPoint(Tile);
Adjacent := Abs(MyPos.y - MyTile.y);
Opposite := Abs(MyPos.x-MyTile.x);
result := ArcTan2(Opposite, Adjacent)*(180/Pi);
writeln('result = '+floattostr(result));
if MyPos.x > MyTile.x then
begin
if MyPos.y > MyTile.y then
result := 90 + result;
end else
if MyPos.y > MyTile.y then
result := 180 + result
else
result := 270 + result;
end; I've tried testing, and it works most of the time, except when you're northeast or southeast of the tile. For example, I'm 4 spaces south and 2 spaces west of the tile. The function tells me the angle is about 18 degrees and thus shifts the compass to 288 degrees (north east east), when it clearly should be much closer to 360 degrees and north north east. Something is probably wrong with my math leading up to the ArcTan, anyone see the problem?
EDIT: Tested some more and it seems being directly south and directly east to the tile also don't work