Hello, beginner here.
I’ve managed to use tilt gravity (on y-axis) to move the character up and down but i’m trying to figure out a way to keep it still (in place) when i hold and press a button (stopBtn) on the screen. Anyone have suggestions on how to achieve this?
When I let go of the button, I want it to re-enable tilt gravity.
Thanks in advance.
local stopBtn = display.newImageRect( "\_images/stop\_btn.png", 300, 200 ) stopBtn.x, stopBtn.y = 800, 300 local char01 = display.newImageRect( "\_images/character.png", 52, 57 ) char01.x, char01.y = 200, 320 local tiltSpeed = 60; local motionx = 0; local motiony = 0; local rotation = 0; local delta = -21/90\*math.pi local cos\_delta, sin\_delta = math.cos(delta), math.sin(delta) local function onTilt(event) motiony = tiltSpeed \* (cos\_delta\*event.xGravity + sin\_delta\*event.zGravity) end local function moveCharacter(event) char01.y = char01.y - motiony; if (char01.y \< 28 ) then char01.y = 28 end if (char01.y \> 569) then char01.y = 569 end end