Bounce Help

I currently have a ball and a jump button, and I have made it so that if you hold down the jump button, the ball bounces. However, the ball bounces perfectly when it first hits the ground, but after that it takes about a second for the ball to bounce again. Any suggestions as to why this is happening and how to fix it? Here is the code:

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
end

ball:addEventListener("collision", on\_hit)

[import]uid: 116264 topic_id: 20878 reply_id: 320878[/import]

maybe put

this at the end of the function

[code]
return true [import]uid: 84637 topic_id: 20878 reply_id: 82351[/import]

after the ends? [import]uid: 116264 topic_id: 20878 reply_id: 82465[/import]

I’ve put it in but there is still a delay for the bounce. The code now is :

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: 20878 reply_id: 82495[/import]

Sorry for the delay, that is correct.

Hmm, still a delay…

Can i see where your setting hold to true/false please? [import]uid: 84637 topic_id: 20878 reply_id: 82496[/import]

Ok, this is the code for the whole jump button:

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
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: 20878 reply_id: 82503[/import]

You would want to add

return true  

To your on_hit function also.

Let me know if that fixes it (even if it doesn’t you should be doing that :slight_smile: ) [import]uid: 84637 topic_id: 20878 reply_id: 82504[/import]

I’m assuming you meant the jump function as the on hit function already has a “return true” ? Ive added it to both functions and there is still a delay for the bounce after the first one [import]uid: 116264 topic_id: 20878 reply_id: 82506[/import]

Sorry yeah, thats what i meant. Give me a bit to think on this.

You can try this in the meantime

[code]
local function pressjump (event)
if event.phase == “began” and ballIsGrounded == true then
ball:setLinearVelocity(0, 0)
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
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:setLinearVelocity(0, 0)
ball:applyForce (0, 2000, ball.x, ball.y)
end
return true
end [import]uid: 84637 topic_id: 20878 reply_id: 82508[/import]

I’ve tried that code but now the ball doesn’t bounce at all after the first bounce. [import]uid: 116264 topic_id: 20878 reply_id: 82511[/import]

Have you had any other thoughts as to how to fix this?
[import]uid: 116264 topic_id: 20878 reply_id: 82742[/import]

Hello. I think this issue is somewhere else …

If you want you can email me the project at : danny [at] anscamobile [dot] com

and i will work out the problem and post the solution here [import]uid: 84637 topic_id: 20878 reply_id: 82813[/import]

Thanks, I’ve sent you an email
[import]uid: 116264 topic_id: 20878 reply_id: 82962[/import]

I don’t mean to be rude but are you still helping with this problem? [import]uid: 116264 topic_id: 20878 reply_id: 83306[/import]

Hey willjhoward.

My appologies for the delay. I did get your email just had a very busy few days here. I have spare time today (despite being my birthday) il be taking a look at it for you. :slight_smile:

EDIT : I tested your sample project and don’t see an issue? What version of Corona are you running? [import]uid: 84637 topic_id: 20878 reply_id: 83314[/import]

Hey @Danny - H.a.p.p.y B.i.r.t.h.d.a.y to YOU! Health & Peace!

PS: close to my birthday (coming in 15 days exactly). :wink:

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 20878 reply_id: 83372[/import]

No worries, have a great day! [import]uid: 116264 topic_id: 20878 reply_id: 83408[/import]

Erm 2.0.0 I think. [import]uid: 116264 topic_id: 20878 reply_id: 83824[/import]