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 problem with my XNA Game, I have a function where I need my sprite to face towards an enemy, using this code:

        Vector2 currentPosition = Position;
        Vector2 nearestEnemy = gameObjectManager.GetNearestEnemy(Position, GameObjectTypes.Zombie);

        Orientation = (float)Math.Atan2(nearestEnemy.Y - currentPosition.Y, nearestEnemy.X - currentPosition.X)

As found on an XNA forum results in my character looking 90 degrees away from the enemy.

Adding "MathHelper.ToRadians(90);" to the end of my Orientation assignment fixes this bug, why is this happening?


share|improve this question
up vote 7 down vote accepted

It seems to me that your sprite may be incorrectly oriented in the source file. Atan2, I believe, returns the angle of the given vector, where zero indicates a vector pointing "to the right" (+X, Y=0). If your sprite file does not point "to the right", you will have to make angle corrections.

share|improve this answer
Ah ok, I have pointed my sprite upwards! Haha! Many thanks! – JuniorDeveloper1208 Jan 19 '11 at 19:53

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.