Original Post
I'm rewriting my game I made back at uni. I'm changing the control system somewhat so that it uses both the mouse and keys. i.e. Mouse for looking direction and keys for accelleration/strafing. This is happening from a top-down view with a helicopter. Now, as to where I'm currently at. I take the middle point of the sprite and the mouse coordinates. Now I calculate the angle the helicopter wants to point at (toward the mouse) using an atan function. The atan function in question returns a value from -128 to 128 (it's a 256 degree circle, not your usual 360 degree one). I now kind of lerp the current angle of the helicopter and the angle the helicopter wants to point to (the mouse pointer). Normally this would work fine, but when the new heading would change from -128 to 128 or the other way around, the helicopter would spin the long way around. This was my old code: angle is the angle the helicopter is currenltly at. newHeading is the angle the helicopter wants to be. //translating the newHeading to the new angle if (angle >> 2 == newHeading >> 2) angle = newHeading; else if (angle - newHeading > 128) angle += HELIANGLECHANGE; else if (newHeading - angle > 128) angle -= HELIANGLECHANGE; else if (angle < newHeading) angle += HELIANGLECHANGE; else angle -= HELIANGLECHANGE; Is there an easier way to write this? It's quite confusing I know, but being the eccentric programmer I am, I find it hard to explain the code I wrote almost 6 months ago :S Thanks guys in advance. :) If you need me to explain anything clearer, just ask.