Need help with math function
Posted: April 6th, 2007, 6:48 pm
Hi,
I need some help with a math function to calculate the angle to a point (x,y)
Here is my function from EQ2 but it does not seem to work in VG. Any help will be appreciated.
If I call CalcTargetAngle(x, y) I get an angle but its not right.
Thanks.
==============================
Function CalculateAngle(dx, dy, dis)
Dim tmpFloat
'objDebug.Print "In CalculateAngle(" & dx & ", " & dy & ", " & dis & ")", 2
if dis=0 then
'objDebug.Print "***WARNING: dis=0 - can't calculate angle", 0
CalculateAngle=0
exit Function
end if
tmpFloat = ArcSin(Abs(dx) / Abs(dis))
if (dx >= 0) and (dy >= 0) then
' Do nothing to tmpFloat
end if
if (dx >= 0) and (dy < 0) then
tmpFloat = PI - tmpFloat
end if
if (dx < 0) and (dy < 0) then
tmpFloat = PI + tmpFloat
end if
if (dx <0>= 0) then
tmpFloat = (2 * PI) - tmpFloat
end if
CalculateAngle = Round(tmpFloat * (180 / PI))
end Function
===============================
Function CalcTargetAngle(x, y)
Dim dx, dy, dis
dx = (-x) - (-getPlayerX())
dy = (-y) - (-getPlayerY())
dis = Sqr(dx*dx + dy*dy)
'dis = Round(Sqr(dx*dx + dy*dy))
' Return Angle
CalcTargetAngle=CalculateAngle(dx, dy, dis)
end Function
I need some help with a math function to calculate the angle to a point (x,y)
Here is my function from EQ2 but it does not seem to work in VG. Any help will be appreciated.
If I call CalcTargetAngle(x, y) I get an angle but its not right.
Thanks.
==============================
Function CalculateAngle(dx, dy, dis)
Dim tmpFloat
'objDebug.Print "In CalculateAngle(" & dx & ", " & dy & ", " & dis & ")", 2
if dis=0 then
'objDebug.Print "***WARNING: dis=0 - can't calculate angle", 0
CalculateAngle=0
exit Function
end if
tmpFloat = ArcSin(Abs(dx) / Abs(dis))
if (dx >= 0) and (dy >= 0) then
' Do nothing to tmpFloat
end if
if (dx >= 0) and (dy < 0) then
tmpFloat = PI - tmpFloat
end if
if (dx < 0) and (dy < 0) then
tmpFloat = PI + tmpFloat
end if
if (dx <0>= 0) then
tmpFloat = (2 * PI) - tmpFloat
end if
CalculateAngle = Round(tmpFloat * (180 / PI))
end Function
===============================
Function CalcTargetAngle(x, y)
Dim dx, dy, dis
dx = (-x) - (-getPlayerX())
dy = (-y) - (-getPlayerY())
dis = Sqr(dx*dx + dy*dy)
'dis = Round(Sqr(dx*dx + dy*dy))
' Return Angle
CalcTargetAngle=CalculateAngle(dx, dy, dis)
end Function