你的大炮当前的旋转速度是每帧 5 度(假设你调用 charge() 作为 enterFrame 处理程序的一部分)因为你有这个:
cannon.rotation = cannon.rotation - 5
因此,如果您希望它旋转得更慢,请尝试以下任一方法:
local degreesPerFrame = 1 -- or 0.1 or whatever, try several
cannon.rotation = cannon.rotation - degreesPerFrame
如果你想要一个特定的速度,那么你可以通过event.time - appStartTime 获取自上次enterFrame 以来的时间。然后你会使用
function enterFrame(event)
if appStartTime == nil then
appStartTime = event.time
else
deltaTime = event.time - appStartTime
charge(deltaTime)
end
end
function charge(deltaTime)
local degreesPerSec = 1 -- or 0.1 or whatever, try several
cannon.rotation = cannon.rotation - degreesPerSec * deltaTime
...
end
或者,您可以使您的对象成为运动物理体(注意:不是动态的):
physics.addBody(cannon, "kinematic", {isSensor = false})
cannon.angularVelocity = 1 -- deg/s
但是,您的代码中似乎有动态。如果您的对象是“动态”物理对象(使用“动态”而不是“运动学”创建),则必须施加扭矩才能使其转动。恒定扭矩将导致非零角加速度,即只要施加扭矩就会导致角速度增加,除非存在与速度相关的阻尼,否则通常会有一个最大值,阻尼正好抵消扭矩并且物体达到稳定的角速度。
使用动态对象会给你带来更平滑、更逼真的变化,但在使用大炮的情况下可能会过大。我会坚持运动学或根本没有物理学,只是改变旋转值。