I'm making a simple animation where a ball bounces repeatedly. The equation for the bounce is h = rt / 16t^2, where h is height, t is time in seconds, and r is initial speed. The problem is that the ball bounces up-side-down. I've been playing around with the equation, but I just can't get it right. Can anyone see what is wrong with this?
function move_ball()
count = count + 0.3
local h = (ints*count)-(16*(math.pow(count,2)))
if (h < 0) then
count = 0
move_ball()
collision()
else
ball.y = h / scale
end
if (ball.x - ball.rad < 0) then
ball.dir = ball.speed
collision()
elseif (ball.x + ball.rad > length) then
ball.dir = -ball.speed
collision()
end
ball.x = ball.x + ball.dir
end
Perhaps you need something like:
ball.y = height - (h / scale)
with a test to be sure that ball.y doesn't go negative.