I am trying to make it so that whenever my ball which is effected by gravity hits the floor it will bounce back up. I currently am using the following code which allows the ball to bounce once but then after the first bounce it stops. I believe the problem is gravity and that once the first linear impulse is applied, the second cannot be because gravity from the ball falling back down prevents the second linear impulse. I think a timer that delays the linear impulse might help this but I do not know how to make one. Here is my code so far. Any help would be great thanks.
local physics = require( “physics” )
physics.start()
local rect = display.newRect(0, 300, 480, 4)
physics.addBody(rect, “static”, {density = 1.0, friction = 0, bounce = 0, isSensor = false})
local circle = display.newCircle(50, 250, 10)
physics.addBody(circle, “dynamic”, {density = 1.0, friction = 0, bounce = 0, radius = 10, isSensor = false})
rect.myName = “rect”
circle.myName = “circle”
circle:addEventListener(“collision”, circle)
function circle:collision (event)
if event.other.myName == “rect” then
circle:applyLinearImpulse(0, -1.998, circle.x, circle.y)
end
end
[import]uid: 126017 topic_id: 22996 reply_id: 322996[/import]

