Can someone explain why the rectangle doesn’t spin here?
That is, I’ve tried to set up a rectangle with it’s centre of mass off-center, and then apply a force to it in the middle, expecting it to spin as it’s center of mass is off…
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
)
PS relates to my question here too (but this is a specific coding question) https://developer.coronalabs.com/forum/2012/08/20/center-mass-physics-question-eg-balloon-weight-bottom [import]uid: 140210 topic_id: 30073 reply_id: 330073[/import]
[import]uid: 52491 topic_id: 30073 reply_id: 120546[/import]