I am struggling with this in JavaScript, but this problem applies to many other languages/environments as well.
I want to have one object rotating towards the position o
If your result is between 0 and Pi, then the result is pretty straight-forward. If your result is between -Pi and 0, then add 2*Pi to your result, this way you will have your result in the interval of 0, 2*Pi.
Of course, it would be nice if you would implement a separate function for this type of conversion, to not duplicate your code every now and then.