0

This is my code for drawing the tower:

SpriteBatch.Draw(
    GetTowerImage(m.SquareTower), 
    new Rectangle(m.X * TILE_SIZE, m.Y * TILE_SIZE, TILE_SIZE, TILE_SIZE), 
    null, 
    Color.White, 
    m.SquareTower.Rotation, 
    new Vector2(TILE_SIZE - 35, TILE_SIZE - 35), 
    SpriteEffects.None, 
    (float)0.0);

My code that gets the position of a tower and places it in a position, however when my rotation method takes place and rotates the image

public void FaceTarget(Vector2 center, Vector2 enemyCenter)
        {
            Vector2 direction = center - enemyCenter;
            direction.Normalize();

            this.Rotation = (float)Math.Atan2(-direction.X, direction.Y);
        }

I did this based on:

The rotation is being really weird, here is how it looks normally:

enter image description here

But when it rotates it goes like this:

enter image description here

Finally when it looks down, it goes complete off path, it's not rotating by its center, but the entire image is moving why is it doing that?

enter image description here

Only the first image is actually the tower in the correct position

(I don't have enough reputation to post images)

venerik
  • 5,766
  • 2
  • 33
  • 43
  • 2
    Are you sure the origin of rotation is correct? That should be the center of your tower (e.g. `new Vector2(TILE_SIZE - TILE_SIZE/2, TILE_SIZE - TILE_SIZE/2)`) – venerik Sep 03 '14 at 22:45

1 Answers1

0

I would comment but my reputation is too low... sorry. By the looks of it I'm pretty positive that your origin is your tower's X and Y position, it really should be something like this:

// AKA the centre of your tower relative to it's Vector2 position
Vector2 origin = new Vector2(towerWidth / 2, towerHeight / 2);
georgeous
  • 45
  • 8