Lua 电晕:如何用物理探测物体的方向

Lua 电晕:如何用物理探测物体的方向,lua,physics,coronasdk,game-physics,Lua,Physics,Coronasdk,Game Physics,我想知道如何用物理学来探测物体的方向,我的意思是当物体坠落时。它可以由eventListener执行吗?知道怎么做吗 我需要它,知道我能换雪碧吗 谢谢。试试这个: local xVelocity, yVelocity local upDown, leftRight -- upDown = 1 for up, leftRight = 1 for left .... -- Get speed of physics object here ( Assume normal orienta

我想知道如何用物理学来探测物体的方向,我的意思是当物体坠落时。它可以由eventListener执行吗?知道怎么做吗

我需要它,知道我能换雪碧吗

谢谢。

试试这个:

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
-----------------------------------
local xVelocity,yVelocity
局部向上向下,leftRight--upDown=1表示向上,leftRight=1表示向左
....
--在此获取物理对象的速度(假设法线方向---
xVelocity,yVelocity=physicsObject:getLinearVelocity()
如果xVelocity>0,则
打印(“对象向右移动”)
leftRight=0
结束
如果xVelocity<0,则
打印(“对象向左移动”)
leftRight=1
结束
如果yVelocity>0,则
打印(“对象下降”)
向上向下=0
结束
如果yVelocity<0,则
打印(“对象上升”)
向上向下=1
结束
-----------------------------------
试试这个:

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
-----------------------------------
local xVelocity,yVelocity
局部向上向下,leftRight--upDown=1表示向上,leftRight=1表示向左
....
--在此获取物理对象的速度(假设法线方向---
xVelocity,yVelocity=physicsObject:getLinearVelocity()
如果xVelocity>0,则
打印(“对象向右移动”)
leftRight=0
结束
如果xVelocity<0,则
打印(“对象向左移动”)
leftRight=1
结束
如果yVelocity>0,则
打印(“对象下降”)
向上向下=0
结束
如果yVelocity<0,则
打印(“对象上升”)
向上向下=1
结束
-----------------------------------

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

 local angle = atan2(xVelocity, yVelocity)

这将返回以弧度为单位的角度,然后可以将其转换为度。这允许对对象进行更精确的控制。丹尼尔·希夫曼(Daniel Shiffman)写了一本很棒的书,涉及at上物理模拟的许多方面。

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

 local angle = atan2(xVelocity, yVelocity)

这将返回以弧度为单位的角度,然后可以将其转换为度。这允许对对象进行更精确的控制。Daniel Shiffman写了一本很棒的书,涉及at的多个物理模拟方面。

为什么需要检测到这一点?你到底想做什么?我有一个物理喷流,似乎从从左到右,触摸屏幕,我给它上电(就像典型的样本),所以我想在(Y)中检测正在增加和减少,以改变精灵表并模拟喷气机旋转。这就是我想做的。你认为是一个好方法还是有更好的方法来做,以及如何做?谢谢@Dany先生想法如何@D先生。很抱歉,我已经很久没有和corona玩过了,所以我真的不记得太多了…我是在跳别人的舞d回答,但从外观上看,电晕专家并不多。明天我会阅读一些我的旧代码和一些文档,看看我是否能帮你,为什么你需要检测它?你到底想做什么?我有一个物理喷流,似乎从左到右,触摸屏幕我给它上电(就像典型的样本)所以我想在(Y)中检测正在增加和减少,以改变精灵表并模拟喷气机旋转。这就是我想做的。你认为是一个好方法还是有更好的方法来做,以及如何做?谢谢@Dany先生想法如何@D先生。很抱歉,我已经很久没有和corona玩过了,所以我真的不记得太多了…我是在跳别人的舞我会回答,但从外表看,电晕专家并不多。明天我会阅读一些我的旧代码和一些文档,看看我是否能帮到你