I want to add two things to davisdudes answer:
1) Instead of using the cycle function, you could also define an angle-difference function, that takes care of the wrapping:
Code: Select all
function angleDiff(angle1,angle2)
return (angle1-angle2+math.pi)%(2*math.pi) - math.pi
end
This function will always return an angle between -pi and pi (-180° and 180°) and gives you the difference between angle1 and angle2.
You could do this then:
Code: Select all
local change = angleDiff(self.tRot,self.rot)
self.rot = self.rot + 0.2 * change
(Using dt is advisble).
And for stability reasons you should do this from time to time:
It makes sure the rotation angle is between 0 and 2pi.
2) If you want to go for davisdudes solution, then the last line has to be changed (I believe. I couldn't test it, because the .love does not run on my machine)
Code: Select all
self.rot = rotateAngle( self.rot, self.tRot, math.abs(cycle(self.tRot-self.rot,-math.pi,math.pi))/5 )