【问题标题】:object move making certain angle物体移动一定角度
【发布时间】:2012-06-06 07:16:47
【问题描述】:

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

我想要的是,当“玩家”与气球碰撞时,它应该向上移动(效果很好),但它应该根据气球的形状在被击中时采取一些角度。它不应该总是垂直向上移动。

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

【问题讨论】:

    标签: lua collision-detection coronasdk


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多