c++ - shooting bullet based on an angle from a point -
what doing scanning area sprite of straight line rotate 20 degrees , forth
when tap action button want shoot bullet in direction of rotation of sprite
i angle doing a
sprite->getrotation();
and have point of unit available, lets (0,0)
i'm guessing need find point on line, don't know math behind it.
is possible?
given know velocity of bullet (pixels/second), let me assume call v
. takes s
seconds transverse screen. , x
represents position of bullet @ axis x
(same y
variable), can actualize both variables using simple trigonometry:
x = 0; // initial position. start @ (0,0) y = 0; (int = 0; < s; i++) { sleep(1); // in unistd.h x += v*cos(angle); // include math.h y += v*sin(angle); // angle in radian, of course // draw sprite here, @ (x, y) }
Comments
Post a Comment