I've got a problem. I have a circle that faces my mouse, and since I want a soft rotation and need the impulse later, I used love.physics fot this task.
I have two vectors, one from the circle to the mouse and one "normed" vector. Then I calculate the angle between the two points, check the difference of the circle's angle and my newly calculated angle and this times an arbitrary factor is set as the circle's angular velocity.
This is all fine and works, BUT: the small gap between 1° and 359°, respectively 0.0..somethingsomethingsmall and 2*pi messes it up.
Code: Select all
function love.update(dt)
world:update(dt)
mousex = love.mouse.getX()
mousey = love.mouse.getY()
vectora[1] = mousex - posx
vectora[2] = mousey - posy
vectorb[1] = 50
vectorb[2] = 0
cosphi = (vectora[1]*vectorb[1]+vectora[2]*vectorb[2])/((math.sqrt(vectora[1]*vectora[1] + vectora[2]*vectora[2]))* (math.sqrt(vectorb[1]*vectorb[1]+vectorb[2]*vectorb[2])))
phi = math.acos(cosphi)
omega = (phi-objects.ball.body:getAngle())*10
objects.ball.body:setAngularVelocity(omega)
end
I'll attach the love-file so you can try it out.