I'm trying to animate a bullet going from one place to another. First I get the angle from the source to the destination by doing
local angle = atan2(startx - endx, starty - endy) |
then I move the bullet from the source to the destination by using that angle and incrementing the distance from the source
bulletx = startx + dist * cos(angle) bullety = starty + dist * sin(angle) |
but the angle is all messed up - the bullet goes in completely the wrong direction.
As far as I can tell the units of atan2, sin and cos are the same so I don't think converting between radians and degrees is the problem. I googled getting the angle between two points and getting a position from an angle but every example I found in other languages seemed consistent with what I'm doing...
Can anyone point out what I'm doing wrong?
I think you intended:
local angle = atan2(endx - startx, endy - starty) |
More information on Pico-8 trig: http://pico-8.wikia.com/wiki/Atan2
That plus fixing an operator precedence mistake I made (a + b c instead of (a + b) c) fixed it, thanks!
[Please log in to post a comment]