Skip to main content
1 of 2
Martin Sand
  • 123
  • 1
  • 1
  • 7

Here it is how I did it. I store the angle of my enemy in a variable m_Angle. Then you update every tick (elapsedTime) the target angle towards your opponent. Please keep in mind that you need to switch direction at +/- 180, so turn right or left (I assume your opponent moves as well). The general approach is to turn the angle of the sprite only partly based on your m_Turnspeed instead of directly letting your sprite facing your opponent. As long as the target angle is not the actual angle you add a fraction to the angle towards your opponent.

m_Angle += m_Turnspeed * elapsedTime;

My enemies are tanks. So I consider their speed in the calcualtion. I do not know if this is helpful to you as well, but take this is a hint. The faster the enemy moves the slower it turns.

m_Angle += m_Turnspeed * (1 - 0.5f * (m_Speed/m_Maxspeed)) * elapsedTime;
Martin Sand
  • 123
  • 1
  • 1
  • 7