如何在Corona/Lua中基于旋转使用applyLinearImpulse [英] How do I use applyLinearImpulse based on rotation in Corona / Lua

查看:105
本文介绍了如何在Corona/Lua中基于旋转使用applyLinearImpulse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Corona游戏附加SDK来构建iphone/andorid游戏.我在屏幕上有一艘太空飞船,我将允许用户将飞船旋转360度.然后,我想调用applyLinearImpulse方法,以允许用户将船向前推向船面对的方向.

I am using the Corona Gaming Addition SDK to build an iphone / andorid game. I have a space ship on the screen and I will allow the user to rotate the ship 360 degrees. I would like to then call the applyLinearImpulse method to allow the user to thrust the ship forward in the direction the ship is facing.

该方法接受以下参数,将这些参数应用于X和Y船以便将船移至新目的地.诀窍是根据船指向的旋转方向确定新的X和Y.

The method accepts these arguments witch are applied to the ships X and Y in order to move the ship to the new destination. The trick is to figure out what the new X and Y needs to be based on rotation / direction the ship is pointing.

ship:applyLinearImpulse(newX, newY, player.x, player.y)

有人这样做或对数学有什么建议可以解决这个问题吗?

Anyone done this or have a suggestion on the math that would figure this out?

谢谢 -m

推荐答案

确定....在发布此消息大约5分钟后,我就知道了.这是答案

Ok .... about 5 min after I posted this I figured it out. Here is the answer

speedX = 0.5 * (math.sin(ship.rotation*(math.pi/180)))
speedY = -0.5 * (math.cos(ship.rotation*(math.pi/180)))

if(event.phase =="began") then
  ship:applyLinearImpulse(speedX, speedY, player.x, player.y)
end

这篇关于如何在Corona/Lua中基于旋转使用applyLinearImpulse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆