The following function determines the angle between the bodies:
function dubrLibrary.getAngle (a,b)
return math.atan2(a.y - b.y, a.x - b.x) / math.pi * 180;
end
The following function moves the object according to the obtained direction:
function dubrLibrary.MoveAngle (a,angle)
a.dx=math.cos(math.rad(angle));
a.dy = math.sin(math.rad(angle));
a.x =a.x + a.dx/2;
a.y =a.y + a.dy/2;
end
here is the code:
local dubrLibrary = require “dubrLibrary”;
local player = display.newRect( w/2, h/2, 15, 15 )
local function Move (event)
local touch = {x = event.x,y = event.y};
if event.phase == “began” then
player.rotation = dubrLibrary.getAngle(player,touch) here is the very lack of understanding (ignorance or otherwise)
dubrLibrary.MoveAngle(player,dubrLibrary.getAngle(player,touch))
end
end
Runtime:addEventListener(“touch”,Move)
how to use the “enterFrame” in MoveAngle in Move?