AtanD troubles

Kamac

Active Member
Licensed User
Longtime User
Hi.

So i am having troubles with rotating by bitmap at, i am using atand.


Code: Copy
rot3 = ATanD((posx - pos2x)/(posy - pos2y)*-1)

Everything works fine when posy is bigger than pos2y, but when it is otherwise, AtanD won't return me a value in degrees, that would rotate my sprite down.


It sounds kinda weird, but it returns values only that can rotate in up. So it can be rotated:

_\|/_

in all these directions, but not opposite :confused:
 
Firstly, I think it is (y/x) not (x/y) as in your code.
i.e.
Code: Copy
rot3 = ATanD((posy - pos2y)/(posx - pos2x)*-1)


And yes sometimes it does that...i saw a workaround in klaus' code somewhere.

when posy-pos2y = 0, AtanD will return zero. Instead of either 0 or 180.

So,
Code: Copy
if posy-pos2y = 0 then
     if posx-pos2x < 0 then
           rot3 = 180
     else
           rot3 = 0
     end if
else
     rot3 = ATanD((posy - pos2y)/(posx - pos2x)*-1)
end if
I hope this works...havent tried it.
 
Last edited:
Upvote 0
Back
Top