将一枚火箭在二维空间内旋转并让它沿着面向方向移动,使用Lua和Corona。

我对 Lua 和 Corona 都不熟悉,一直在努力让我的游戏起飞(顺便一提)

我想要旋转我的火箭,顺时针和逆时针旋转,并调整它的 x 和 y 值,以便在按下推力按钮时以其面朝的方向移动

我尝试了很多种方法,却被方程式和如何实现它们所困扰,看看我的代码(如果偏离轨道请随意笑话)

    local rocket = display.newSprite( rocketsheet, rocketsequencedata)
    physics.addBody(rocket, { bounce = 0.5} )
    rocket.x = display.contentWidth/3
    rocket.y = display.contentHeight/1.5
    rocket.rotation = angle
    rocket:setSequence("idle")
    rocket:play()

    local inverseRotation = rocket.rotation  + math.pi
    local speedX = 0.000
    local speedY = 0.005

    speedX =  speedX * math.cos(inverseRotation) + speedY * math.sin(inverseRotation)
    speedY =  -speedX * math.sin(inverseRotation) + speedY * math.cos(inverseRotation)

    function thrust(event)

    rocket:applyLinearImpulse(speedX, speedY, rocket.x, rocket.y)
    rocket:setSequence("afterburn")
    rocket:play()

    end

    function rotateleft(event)

    speedX = speedX - 0.0005

    rocket.rotation = rocket.rotation - 2

    end

    function rotateright(event)

    speedX = speedX + 0.0005
    rocket.rotation = rocket.rotation + 2

    end

    controlthrust:addEventListener( "touch", thrust)
    controlleft:addEventListener( "touch", rotateleft)
    controlright:addEventListener( "touch", rotateright)
点赞
用户269870
用户269870

你正在重新定义 speedX 和 speedY...

这意味着方程的第一行运行良好。 第二行使用了第一行的结果,因此完全打破了原来的结构。

:)

2012-11-19 19:36:24