Code: Select all
function update(dt)
world:update(dt)
mPosX, mPosY = love.mouse.getX(), love.mouse.getY()
mPosY = mPosY - 768
bPosX, bPosY = LBarrelBody:getX(), LBarrelBody:getY()
bPosY = bPosY - 768
LBarrelBody:setAngle(math.deg(angleBetween(bPosX, bPosY,mPosX,mPosY)))
end
function angleBetween(ax, ay, bx, by)
local dotproduct, lengtha, lengthb, result;
dotproduct = (ax * bx) + (ay * by);
lengtha = length(ax,ay);
lengthb = length(bx,by);
result = math.acos( dotproduct / (lengtha * lengthb) );
if dotproduct < 0 then
if result > 0 then
result = result + 3.14159;
else
result = result - 3.14159;
end
end
return result;
end
function length(x,y)
return math.sqrt(x*x+y*y)
end
I'm trying to do this without any outside libraries if I can help it.