如何反转这个等式?

时间:2014-03-20 21:22:08

标签: lua physics physics-engine

我正在制作一个简单的动画,其中一个球反复弹跳。反弹的等式是h = rt / 16t ^ 2,其中h是高度,t是以秒为单位的时间,r是初始速度。问题是球在上下反弹。我一直在玩这个等式,但我无法做到这一点。任何人都可以看到这有什么问题吗?

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

2 个答案:

答案 0 :(得分:1)

也许你需要这样的东西:

ball.y = height - (h / scale)

进行测试以确保ball.y不会消极。

答案 1 :(得分:0)

你的等式是h = r t - 16 t ^ 2,假设正h向上并且重力下降(我认为4不是16但是这与你的问题无关)。你的代码似乎是对的。然而,可能是屏幕坐标正下降。在计算h后立即尝试否定h:h = -h,并检查h&gt; 0而不是。

相关问题