Is there a way to pause a character from moving?

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

Have you tried setting the tiltGravity and motiony to 0 when you press the stopBtn, and reset them to the previous values when the button is let go?

Hi! I’ve tried motiony the other day without much success but not together with tiltGravity as you’ve suggested. I’ll give that a try this week. Thanks for your help!

Have you tried setting the tiltGravity and motiony to 0 when you press the stopBtn, and reset them to the previous values when the button is let go?

Hi! I’ve tried motiony the other day without much success but not together with tiltGravity as you’ve suggested. I’ll give that a try this week. Thanks for your help!