物体移动制造一定的角度

时间:2012-06-06 07:16:47

标签: lua collision-detection corona

我有一个物理团体(气球),我正在施加碰撞冲动。

我想要的是当“玩家”与气球碰撞然后它应该向上移动(这是非常好的),但是当击中时气球的形状应该采取一些角度。它不应该总是垂直向上移动。

只有在气球的最顶部被击中时才应该直线向上移动。在其他情况下,它应该以某种角度向上移动。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

从我的想法来看,这是一种方法:

您可以从两个物体(您的玩家和气球)的位置找到冲击角度。所以你有balloon.x,balloon.y,player.x,player.y。

-- Two sides of a triangle opp and adj to the angle
sideO = balloon.y-player.y  -- the opposite side
sideA = balloon.x-player.x  -- the adjacent side

-- To get the angle
angle = math.atan(sideO/sideA)

这可能是你想要的倒退。如果只是尝试使用player.x-balloon.x(和y相同)。

Here's where I got the math. 另外,the lua math library