help with angels

Previous topic - Next topic

djtoon

hi
im making a game from a top down view and i had a small probelm:

around the play there are 4 points
i need to get the angel reletive to the player angel

here is what i use for the angel:
LOCAL angle

   angle=ATAN(myy-startY,mxx-startX)
   IF angle<0.0
      angle=180.0+(180.0+angle)
   ENDIF
   
   RETURN (angle)

i add'd this:
LOCAL angle

   angle=ATAN(myy-startY,mxx-startX)
   IF angle<0.0
      angle=180.0+(180.0+angle)
   ENDIF
   
   RETURN (angle-curAngle)


"curAngle" is the players angel (" he moves in 90 degress, 0,90,180,270 and back to 0

im getting weird results
can anyone help

10x

MrTAToad

You should just need to use :

Code (glbasic) Select
RETURN angle

Slydog

#2
Not sure if I'm picturing what you are asking.
The first calculation, using ATAN, gives you the angle between the player and object.
Then if the player is rotated 90 degrees you want that reflected in the angle also.
Would simply adding them (not subtracting) work, like:

Code (glbasic) Select
RETURN (angle  + curAngle)
You may need to bounds check the angle again, not sure (IF combinedAngle < 0 THEN INC combinedAngle, 360.0).

[Edit]
More likely need to check the other bounds:
Code (glbasic) Select
IF combinedAngle >= 360.0 THEN DEC combinedAngle, 360.0
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Hemlos

#3
Here ya go, this angle return is the angle pointing back to the origin(0,0).
You input the distance to the object in X and Y factors.
Assuming 0 degrees is the right.
This is NOT a vector input, it is a range input, relative from one object to another, the assumtion is, the origin is a 0,0 position.
If you need to get the angle to the object in question, you add 180 degrees to the output.
Do not alter the function, it will give you mixed results, something wierd with atan.


Code (glbasic) Select

FUNCTION GLM_Sys_FltOriginAngle: X,Y
// OriginAngle assumes Angle=0 is Right Handed, starts pointed to the Right.
// OriginAngle assumes X,Y are relative to origin of 0,0
// Return = The angle[0..359] pointing to the origin.
OriAng = -1.0 * ATAN( X , Y ) + 270.0
IF OriAng >= 360.0 THEN OriAng = OriAng - 360.0 //range 0-359
RETURN OriAng
ENDFUNCTION
Bing ChatGpt is pretty smart :O