Hi guys,
I’m currently working on top down plane shooter. Unfortunately, I can’t seem to get the controls to work right. Below are my codes, modified from a Drag and Move tutorial (can’t remember where I took them from)
function touchScreen(event) if (event.phase == "began") then mainCharacter.isFocus = true mainCharacter.x0 = event.x - mainCharacter.x mainCharacter.y0 = event.y - mainCharacter.y elseif mainCharacter.isFocus then local speed = 10 -- just putting it here temporary if "moved" == event.phase then -- mainCharacter.x = event.x -- mainCharacter.y = event.y mainCharacter:setLinearVelocity((event.x - mainCharacter.x) \* speed, (event.y - mainCharacter.y) \* speed) elseif "ended" == phase or "cancelled" == phase then mainCharacter.isFocus = false mainCharacter:setLinearVelocity(0, 0) end end return true end
The controls i’m looking for is something similar to the game Sky Force, where the plane will move to the position of the player’s finger base on its own speed, which makes it feel more natural when you move your fingers along the screen.
The problem with my code is, the plane will continue to move despite not moving my finger. Same goes when my finger is lifted from the screen. I tried using transition.to but it makes the plane ‘hiccup’ during movement.
Any help is appreciated 