I have this rotate platform function provided by christian peeters, however it doesn’t seem to be working, could anyone shed some light?
First I have the function to move the platform which works correctly, but when the rotation is added in corona just crashes.
local function movePlatform(event) platformTouched = event.target if (event.phase == "began") then display.getCurrentStage():setFocus( platformTouched ) display.remove( rotationalert ) rotationalert = nil -- here the first position is stored in x and y platformTouched.startMoveX = platformTouched.x platformTouched.startMoveY = platformTouched.y platformTouched.x1 = event.x platformTouched.y1 = event.y elseif (event.phase == "moved") then -- here the distance is calculated between the start of the movement and its current position of the drag platformTouched.x = (event.x - event.xStart) + platformTouched.startMoveX platformTouched.y = (event.y - event.yStart) + platformTouched.startMoveY elseif event.phase == "ended" or event.phase == "cancelled" then rotationalert = display.newImage ("images/rotation.png") rotationalert.x = platformTouched.x rotationalert.y = platformTouched.y rotationalert.alpha = 0.5 rotationalert:addEventListener ("touch", rotatePlatform) group:insert(rotationalert) display.getCurrentStage():setFocus( nil ) end return true end platform:addEventListener("touch", movePlatform) ------------------------------------------------------------------ local function rotatePlatform(event) alerttouched = event.target if (event.phase == "began") then display.getCurrentStage():setFocus( alerttouched ) elseif (event.phase == "moved") then platformTouched.x2 = event.x platformTouched.y2 = event.y angle1 = 180/math.pi \* math.atan2(platformTouched.y1 - platformTouched.y , platformTouched.x1 - platformTouched.x) angle2= 180/math.pi \* math.atan2(platformTouched.y2 - platformTouched.y , platformTouched.x2 - platformTouched.x) differencebetweenangles = angle1 - angle2 --rotate it platformTouched.rotation = platformTouched.rotation - differencebetweenangles platformTouched.x1 = platformTouched.x2 platformTouched.y1 = platformTouched.y2 elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus( nil ) display.remove( rotationalert ) rotationalert = nil end end