I have a jump button which makes a ball jump, and it works fine except when the ball is on the corner of an object, just about to roll if it. When I press the jump button then, the ball goes sideways and sometimes downwards. How can I fix this? the code for the jump is:
local ballIsGrounded = true
x, y = ball:getLinearVelocity()
local hold = false
local function pressjump (event)
if event.phase == "began" and ballIsGrounded == true then
ball:applyForce ( 0, 1000, ball.x, ball.y)
jumptimer = timer.performWithDelay(45,function() ball:applyForce(0,y -30,ball.x,ball.y)end,3)
ballIsGrounded = false
hold = true
elseif event.phase == "ended" then
timer.cancel(jumptimer)
hold = false
end
return true
end
jumpbutton:addEventListener ("touch", pressjump)
local function on\_hit (event)
if event.phase == "began" and hold == false then
ballIsGrounded = true
ball.angularDamping = 0
elseif event.phase == "began" and hold == true then
ballIsGrounded = false
ball:applyForce (0, 2000, ball.x, ball.y)
end
return true
end
[import]uid: 116264 topic_id: 20922 reply_id: 320922[/import]
[import]uid: 52491 topic_id: 20922 reply_id: 82650[/import]