有人可以解释为什么矩形在这里不旋转吗?这是 Lua 代码,我正在使用 Corona SDK。
也就是说,我试图建立一个质心偏离中心的矩形,然后在中间对它施加一个力,期望它在质心偏离时旋转......
display.setStatusBar( display.HiddenStatusBar )
-- Setup
local screenCenterX, screenCenterY = display.contentWidth/2, display.contentHeight/2
-- Create Object
local myRect = display.newRect(0, 0, 30, 90)
myRect.strokeWidth = 2
myRect:setFillColor(140, 140, 140, 0)
myRect:setStrokeColor(180, 180, 180)
myRect:setReferencePoint(display.CenterReferencePoint)
myRect.x, myRect.y = screenCenterX, screenCenterY
-- Apply Physics
local physics = require("physics")
physics.start()
physics.setGravity(0,0)
physics.addBody( myRect, "kinimatic", { friction=0.5, bounce=0.1, radius = 45 } )
-- Redefine Centre of Mass (what I'm trying to get right)
myRect.xOrigin, myRect.yOrigin = screenCenterX, screenCenterY - 100
-- Replace myRect to the center as setting the xOrigin/yOrigin seems to have moved it
myRect.x, myRect.y = screenCenterX, screenCenterY
-- Apply Force
timer.performWithDelay(3000,
function(event)
myRect:applyForce(5,0, screenCenterX, screenCenterY)
-- WHY DOES THIS NOT SPIN THE OBJECT???
-- Centre of gravity has been change so shouldn't it rotate now?
-- That is, trying to simulate applying a force to an object who's centre of mass is NOT in
-- the center, and then see it spin.
end
)