Hi Everyone,
I have been working on an app where the player controls a plane using buttons that appear on the screen. When you press one of the buttons, it slightly rotates the plane.
What I am trying to do now is to make the plane always move in the direction it’s facing, so that it looks like it is constantly flying forwards. Any ideas?
Thanks in advance!
Here is my code:
--MISC/VARIABLES-- display.setStatusBar(display.HiddenStatusBar) system.activate("multitouch") physics = require("physics") local motion = 0 local turnspeed = 5 \_W = display.contentWidth \_H = display.contentHeight physics.start() --BACKGROUND-- sky = display.newImage("Assets/Sky.png") sky.x = \_W/2 sky.y = \_H/2 --PLANE-- local plane = display.newImage("Assets/Plane.png") plane.x = \_W/2 plane.y = \_H/2 function planerotate (event) plane.rotation = plane.rotation + motion; end Runtime:addEventListener("enterFrame",planerotate) function stoprotate (event) if event.phase == "ended" then motion = 0; end end Runtime:addEventListener("touch", stoprotate) --ARROWS-- arrow\_left = display.newImage("Assets/Arrow.png") arrow\_left.x = 85 arrow\_left.y = \_H - 85 arrow\_left.rotation = 270 function arrow\_left:touch() motion = -turnspeed; end arrow\_left:addEventListener("touch", arrow\_left) local arrow\_right = display.newImage("Assets/Arrow.png") arrow\_right.x = \_W - 85 arrow\_right.y = \_H - 85 arrow\_right.rotation = 90 function arrow\_right:touch() motion = turnspeed; end arrow\_right:addEventListener("touch", arrow\_right)