Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
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

share|improve this answer

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.