(C++) shoot at the mouse

Started by
0 comments, last by Driv3MeFar 16 years, 4 months ago
I want to make a program that fires a projectile sprite wherever the mouse points. The problem is its math side; if the shooter-sprites is at (x1,y1) and the mouse is at (x2,y2), how can one determine the projectile's position (x,y)? I encountered a formula for this, without sin or cos, but I forgot it.
Advertisement
If this is 2D, then the vector from shooter to target is:
vec2 v = target position - shooter position.

If you normalize this vector the projectile's position is:
position = position + v * speed * elapsed time.

This topic is closed to new replies.

Advertisement