Code: Select all
local mousePos = vector( love.mouse.getX(), love.mouse.getY() )
local dir = self.pos - mousePos
local targetAngle = -math.atan2( dir.x, dir.y ) / (math.pi / 180)
local curAngle = self.top_angle
if curAngle < 0 then
curAngle = curAngle + 360
end
if targetAngle < 0 then
targetAngle = targetAngle + 360
end
local a = curAngle - targetAngle
if a > 180 then
a = a - 360
elseif a < -180 then
a = a + 360
end
local s = dt * 70
if a >= -s - 0.5 and a <= s + 0.5 then
self.top_angle = targetAngle
elseif a > s + 0.5 then
self.top_angle = self.top_angle - s
elseif a < -s - 0.5 then
self.top_angle = self.top_angle + s
end
Code: Select all
local s = dt * 70