I am trying to make a 2D shooter using C++ and SFML 2.1. A machine gun is positioned somewhere and it turns towards the mouse pointer. Now I need to implement shooting. I am stuck. How do I calculate the bullet trajectory?
I think for just showing a bullet I need to just make a bool variable which stores true or false depending on should the bullet be shown on the screen. But for moving the bullet, I have no clue what am I supposed to do? I think that this has something to do with trigonometry, just like rotating the gun towards the mouse pointer, or it is something else?
Now the gun shoots with different rates of fire (does this has to do something with not including time in bx=ux*v*t+tx and the same with y) and it goes crazy when I point the gun in a different direction.
What am I doing wrong?
> Now the gun...
> What am I doing wrong?
In order to know what you are doing wrong, we need to know what you are doing.
> does this has to do something with not including time
if you haven't included time, then the bullet would not move
> it goes crazy when I point the gun in a different direction.
I guess that your mouse coordinates refer to the window, not to the model.
There may be differences between scale (e.g., 640x480), origin (upper left corner) and axis orientation (y grows down).
Also the formula was incorrect, it should be ux = Mx-Tx
uy = My-Ty so it points towards the mouse.