2D tower defense - A bullet to an enemy

Posted by Tashu on Game Development See other posts from Game Development or by Tashu
Published on 2011-07-04T12:34:18Z Indexed on 2012/11/20 17:22 UTC
Read the original article Hit count: 398

I'm trying to find a good solution for a bullet to hit the enemy. The game is 2D tower defense, the tower is supposed to shoot a bullet and hit the enemy guaranteed.

I tried this solution - http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1/

The link mentioned to subtract the bullet's origin and the enemy as well (vector subtraction). I tried that but a bullet just follows around the enemy.

float diffX = enemy.position.x - position.x;
float diffY = enemy.position.y - position.y;

velocity.x = diffX;
velocity.y = diffY;

position.add(velocity.x * deltaTime, velocity.y * deltaTime);

I'm familiar with vectors but not sure what steps (vector math operations) to be done to get this solution working.

© Game Development or respective owner

Related posts about projectile-physics

Related posts about tower-defense