# How do I shoot bullets towards the mouse in a top down shooter?

I have a formula for pointing my main character of the game towards the mouse, and it gets the angle he needs to be turned to point towards the mouse. But how do I get the bullets from the gun to use the angle produced and shoot a bullet towards the mouse.

-

All you need to know is the relative angle between the player and the point where you are aiming at. It seems to me that you already have the angle, lets call that angle a.

Now for the bullet to point in the right direction you just rotate the bullet sprite with angle a. Now for the movement/direction. You need to convert the angle to a 2D Vector, you can do that by creating a new Vector with X = cos(a) and Y = sin(a). You now have a (normalized) vector pointing from the player to the target. Now all you need to do now is move the bullet every frame with an equal fraction of the X and Y in the vector.

-
and if you multiply by bullet speed, you have the magnitude of the vector as well! – PlayDeezGames Feb 27 '12 at 2:05
True the update loop would be bullet.position += vector * speed * elapsedSecondsSinceLastFrame; – Roy T. Feb 27 '12 at 6:58

Vec2 delta = MousePos - ObjPos Float angle = atan2(delta.y, delta.x) Then use cos/sin to make a line if you want

-

If your character has a forward vector, you can just use that to set the rotation of the bullet vector as well as the velocity (by multiplying forward * speed).

-