Possible Duplicate:
Shoot a bullet towards cursor - top down 2d

I'm creating a 2D top down shooter, and I want to get the bullets to go in the direction of the mouse. Not sure of the logic that goes into it.

  • 1
    \$\begingroup\$ This is a very common question. I can't imagine you searched the site first. Please do so in the future before asking a question. \$\endgroup\$
    – House
    Oct 20, 2012 at 15:14

1 Answer 1


You could use trigonometry like here: 2D Magnet-like repelling behavior

But the very simplest approach is:


//every frame:
dx = mouse.x - bullet.x;
dy = mouse.y - bullet.y;

bullet.vx = dx * CONSTANT_FACTOR;
bullet.vy = dy * CONSTANT_FACTOR;

bullet.x += bullet.vx;
bullet.y += bullet.vy;

Not the answer you're looking for? Browse other questions tagged .