【问题标题】:Corona: How to detect the direction of an object with physics电晕:如何用物理学检测物体的方向
【发布时间】:2013-04-21 01:32:00
【问题描述】:

我想知道如何用物理学检测物体的方向,我的意思是什么时候掉下来。可以通过事件监听器吗?知道怎么做吗?

我需要它以了解我可以更改 spriteSheet。

谢谢。

【问题讨论】:

  • 为什么需要检测?你到底想做什么?
  • 我有一架物理喷气式飞机,它似乎从左到右,触摸屏幕我给它向上的动力(它就像典型的样本)所以我想检测何时进入(Y) 增加和减少以改变 SpriteSheet 并模拟喷气机转动。这就是我想做的。你认为一个好方法或有更好的方法来做到这一点,如何?谢谢@Mr-D
  • 知道@Mr D.
  • 很抱歉,自从我玩电晕以来已经很久了,所以我不太记得了...我希望其他人会回答,但从外观上看,电晕专家并不多.明天我会读一些我的旧代码和一些文档,看看能不能帮到你

标签: lua physics coronasdk game-physics


【解决方案1】:

要根据您调用的对象速度找到准确的角度:

 local angle = atan2(xVelocity, yVelocity)

这会返回以弧度为单位的角度,然后您可以将其转换为度数。这允许对对象进行更精确的控制。 Daniel Shiffman 在http://natureofcode.com/book/ 写了一本很棒的书,涉及物理模拟的许多方面。

【讨论】:

    【解决方案2】:

    试试这个:

    local xVelocity, yVelocity
    local upDown, leftRight         -- upDown = 1 for up, leftRight = 1 for left
    ....
    -- Get speed of physics object here ( Assume normal orientation ---
        xVelocity, yVelocity = physicsObject:getLinearVelocity()
        if xVelocity > 0 then
            print( "Object goes right" )
            leftRight = 0
        end
        if xVelocity < 0 then
            print( "Object goes left" )
            leftRight = 1
        end
        if yVelocity > 0 then
            print( "Object goes down" )
            upDown = 0
        end
        if yVelocity < 0 then
            print( "Object goes up" )
            upDown = 1
        end
    -----------------------------------
    

    【讨论】:

      猜你喜欢
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-16
      • 1970-01-01
      相关资源
      最近更新 更多