【发布时间】:2017-01-11 02:06:20
【问题描述】:
我有一个持续旋转的物体,它会发射子弹。我希望子弹按照它们的方向前进。
physics.setGravity( 0, 0 )
fireBullets = function ( )
local bullet = display.newRect( sceneGroup,0,0, 40, 40 )
bullet:setFillColor( 0, 1, 0 )
local h = player.height
local posX = h * math.sin( math.rad( player.rotation ))
local posY = h * math.cos( math.rad(player.rotation ))
bullet.x = player.x + posX
bullet.y = player.y - posY
bullet.rotation = player.rotation
到目前为止一切都很好,子弹会随着玩家的精确旋转而出现。
local angle = math.rad( bullet.rotation )
local xDir = math.cos( angle )
local yDir = math.sin( angle )
physics.addBody( bullet, "dynamic" )
bullet:setLinearVelocity( xDir * 100, yDir * 100)
end
他们没有按照自己的方向前进,他们似乎在向右移动。我的计算出了什么问题?
【问题讨论】: