Original Post
Hi guys, I'm having problems picking the direction (positive/negative) to rotate so I take the shortest way around. I am using atan2() to convert a 2D vector (desired orientation) to an angle, and it's the way it jumps from Pi to -Pi that's mixing me up. Ideally I'd like something like this: targetAngle=atan2(dir.x,dir.z); // desired direction with 0.0 down the z-axis if(targetAngle > currentAngle) currentAngle+=(rotationRate*timespan); // clamp if(currentAngle > targetAngle) currentAngle=targetAngle; } else if(targetAngle < currentAngle){ currentAngle-=(rotationRate*timespan); // clamp if(currentAngle < targetAngle) currentAngle=targetAngle; } That method work alright but sometimes it ends up "taking the long way around". I can't figure out a nice way fix it. Thanks.