AtanD troubles

Kamac

Active Member
Licensed User
Longtime User
Hi.

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


B4X:
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:
 

thedesolatesoul

Expert
Licensed User
Longtime User
Firstly, I think it is (y/x) not (x/y) as in your code.
i.e.
B4X:
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,
B4X:
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

Kamac

Active Member
Licensed User
Longtime User
I've switched X with Y so it is (y)/(x) now, but now it can rotate only left or right :BangHead:.

Your code doesn't works :p.


EDIT@

I've added:

B4X:
rot3 = rot3 + 180

So now it's rotated properly, but if i would have dynamic objects, it would be harder :|
 
Last edited:
Upvote 0
Top