电晕lua代码-为什么不';这个物体不旋转吗?(即质量中心相关测试代码)
有人能解释为什么矩形在这里不旋转吗?这是Lua代码,我正在使用Corona SDK电晕lua代码-为什么不';这个物体不旋转吗?(即质量中心相关测试代码),lua,coronasdk,Lua,Coronasdk,有人能解释为什么矩形在这里不旋转吗?这是Lua代码,我正在使用Corona SDK 这是,我试图建立一个矩形,它的质心偏离中心,然后在中间施加一个力,期望它在质心偏离时旋转。 display.setStatusBar( display.HiddenStatusBar ) -- Setup local screenCenterX, screenCenterY = display.contentWidth/2, display.contentHeight/2 -- Create Object
这是,我试图建立一个矩形,它的质心偏离中心,然后在中间施加一个力,期望它在质心偏离时旋转。
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
)
变量xOrigin和yOrigin仅用于移动对象,这些变量根本不会影响物理,并且它们不是真正的“原点”(它们是对象相对于父“x/yOrigin”变量的x/y位置) 要创建不平衡的物理对象,需要使用形状,因此必须创建两个形状(因此不能使用自动形状,必须使用多边形),其中一个比另一个重,以模拟偏心质量 例如,一个长度为100个单位的矩形,将50个单位的权重设为1,将其他50个单位的权重设为2,结果将是中心或多或少位于x75(我的数学计算可能有误)