I’d like to know how I can make a ball bounce with reduced height over time no matter where the ball is initially positioned (y = 100, or y = 200, or y = 250 etc).
From the code below which you can simply put into main.lua and run, you’ll notice the ball starts in the air (y = 300), falls down and bounces until it stops bouncing (bouncing reduces over time)
This issue I’m facing is after the first bounce, the ball doesn’t realistically bounce high enough.
I’m not using any physics on purpose. I’d like to achieve the bounce effect using “enterFrame” for the purpose of my game.
Any help would be greatly appreciated.
local W = display.contentWidth local H = display.contentHeight local gravity = 0.55 local myCircle = display.newCircle(W\*0.5,H-25,20) myCircle.groundLevel = H - 60 local function bounceTheBall(e) myCircle.jumpSpeed = myCircle.jumpSpeed - gravity print(myCircle.jumpSpeed) myCircle.y = myCircle.y - myCircle.jumpSpeed if (myCircle.y \>= myCircle.groundLevel) then numberOfBounces = numberOfBounces + 1 myCircle.jumpSpeed = 20 + (numberOfBounces \* -2) -- issue probably here myCircle.y = myCircle.groundLevel end end numberOfBounces = 0 myCircle.jumpSpeed = 0 myCircle.y = 300 -- this can be anything Runtime:addEventListener("enterFrame", bounceTheBall)


