title: Rotation between 2 points facing away when standing at back while facing towards while standing infront (pics)
body: <p>With this little piece of code I've made it possible to rotate the 'monster' towards the avatar but if the avatar is behind the 'monster', the 'monster' is facing away from the avatar. (Pic's below)</p>
  
  <p>Note: the white numbers are the value of <code>m_RotationAngle</code></p>
  
  <pre><code>DOUBLE2 mousePos = GAME_ENGINE-&gt;GetMousePosition();
  
  double xDiff = m_ActPtr-&gt;GetPosition().x - mousePos.x;
  double yDiff = m_ActPtr-&gt;GetPosition().y - mousePos.y;
  m_RotationAngle = atan(yDiff, xDiff);
  m_ActPtr-&gt;SetAngle(m_RotationAngle);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7aHKR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7aHKR.jpg" alt="Avatar standing behind monsters"></a><a href="https://i.stack.imgur.com/wBh2B.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wBh2B.jpg" alt="Avatar standing infront of monsters"></a></p>
  
  <p>I've tried to fix it with:</p>
  
  <pre><code>if (diff.x &lt; 0)
  {
      m_RotationAngle = -atan(diff.y / diff.x);
      //also tried following but gave and error:
      //m_RotationAngle = tan(diff.y / diff.x);
  }
  else
  {
      m_RotationAngle = atan(diff.y / diff.x);
  }
  </code></pre>
  
  <p>But this gave the following output:</p>
  
  <p><a href="https://i.stack.imgur.com/HuPVW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HuPVW.jpg" alt="enter image description here"></a></p>