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'm developing a game where enemy can shoot bullets towards the player. I'm using 2 vector that is normalized later to determine where the bullets will go.

Here is the code where enemy shoots:

private void UpdateCommonBullet(GameTime gt)
            foreach (CommonEnemyBullet ceb in bulletList)
                ceb.pos += ceb.direction * 1.5f * (float)gt.ElapsedGameTime.TotalSeconds;
                if (ceb.pos.Y >= 600) ceb.hasFired = false;

            for (int i = 0; i < bulletList.Count; i++)
                if (!bulletList[i].hasFired)

And here is where i get the direction (in the constructor of the bullet):

direction = Global.currentPos - this.pos;

Global.currentPos is a Vector2 where currently player is located, and is updated eveytime the player moves.

This all works fine except that the bullet won't go to player's location. Instead, it tends goes to the "far right" of the player's position.

I think it might be the problem where the bullet (this.pos in the direction) is created (at the position of the enemy). But I found no solution of it, please help me.

share|improve this question
could you post a "how it´s supposed to be" picture and one "what is now"? would help alot! – Tordin Jul 12 '13 at 9:28
can't post picture due to my reputation. But let's say my screen is (800, 800), my player is now at (100, 100), enemy come from (100, 100), but the bullet they sprayed is as if my player is at (900, 100) so the bullet go to (900, 100) – user2002495 Jul 12 '13 at 9:31
you can link them, and post it on some specific image site. – Tordin Jul 12 '13 at 9:45
I "quite" solved the problem already. But not satisfied. Here you go. Expected : Reality: – user2002495 Jul 12 '13 at 10:04
i think your problem is that you are using the texture position and not actualy the center cordinates. to fix this, adjust it with using Width / 2 & height / 2. – Tordin Jul 12 '13 at 10:16

If you are using spritebatch.draw(texture, vector2, color) vector2 value is the top left of the sprite, there are two ways you could fix it. The first is that you could add width/2 and height/2 to global.currentposition. The second, which is probably a better solution is to modify the draw code so that the vector2 for the draw position is playerPosition minus width/2 and height/2 this means that that the player position is the center of the sprite.

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.