title: rotation and radians in XNA, Enemy Ai corrections
body: <p>ive been having trouble with my mob AI </p>
  
  <p>it works to a point, except it does the opposite of what i want, meaning it turns 180Degrees in the wrong direction </p>
  
  <pre><code>        Target = playerST.Posistion;
          Vector2 trivial;
          trivial.X = Posistion.X - Target.X;
          trivial.Y = Posistion.Y - Target.Y;
          instant = ((float)Math.Atan2(trivial.Y, trivial.X)) + 3.141592f; 
  </code></pre>
  
  <p>this tells me where my target is  and calculates the numbers i need to rotate to </p>
  
  <p>its in radians the plus 3.1etc is  like 180 degrees,  as calculating it this way gives me either a minumum of -3.141 or a maximum of 
  3.141 but the rotations of the enemy is done in 0 to 6.28 adding the 3.141 makes instant =  in the range of the enemies rotation  instead of under it by 3.141  </p>
  
  <p>anyway this is the part i get stuck at... the actual rotation </p>
  
  <pre><code>        // irrelevant
                  if (attack == true)
              {
  
                  Vector2 modelVelocityAdd = Vector2.Zero;
  
                  modelVelocityAdd.Y = -(float)Math.Sin(rotation);
                  modelVelocityAdd.X = -(float)Math.Cos(rotation);
  
                  modelVelocityAdd *= (0.00002f * speed);
                  if ((((rotation) + 0.2f)) &lt; instant &amp;&amp; (rotation - 0.2f) &gt; instant)
                  {
                      modelVelocity += modelVelocityAdd;
                  }
          // not so irrelvant and needs fixing!
                  if (instant &lt; rotation )
                      {
                           rotation -= rotationspeed / 2000;
                      }
                  else if (rotation &lt; instant)
                      {
                           rotation += rotationspeed / 2000;
                      }
  </code></pre>
  
  <p>so my problem is how  do i stop it from rotating 180 degrees in the wrong direction and actually get it to face the player instead of facing the exact opposite</p>
  
  <p>i cant simply,do what is below because the ship gets trapped and goes back and forth  between say 5 degrees and minus 5 degrees</p>
  
  <pre><code>            if (instant &lt; rotation )
                      {
                           rotation += rotationspeed / 2000;
                      }
                  else if (rotation &lt; instant)
                      {
                           rotation -= rotationspeed / 2000;
                      }
  </code></pre>
  
  <p>thanks for any help</p>