why doesn't this object spin in this sample code attached? (i.e. center of mass related test code)

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]

Just FYI - your body is dynamic because you wrote “kinimatic” rather than “kinematic” - so your testing will be thrown off based on this. [import]uid: 52491 topic_id: 30073 reply_id: 120435[/import]

In the doc for physics AddBody it says:

Note
When you turn a display object into a physics object, the Physics engine owns the object and has its own rules about the object. Physics assumes the reference point of the object is the center of the object so object:setReferencePoint() may change the reference point from Corona’s Display Object point of view but not for the Physics engine. This affects collisions and how other physics bodies interact…

As the doc suggests, doing physics.setDrawMode(“debug”) usually clears up the confusion. [import]uid: 160496 topic_id: 30073 reply_id: 120437[/import]

@peach - thanks (doh) - changed it to “dynamic” in fact and same issue

@mike / @peach - thanks - but how would one then model an object that is elongated with more mass at one end then? Can the physics engine assist here? Actually this question here is really related to my non-code post question here: https://developer.coronalabs.com/forum/2012/08/20/center-mass-physics-question-eg-balloon-weight-bottom

You would have to have two (or more) objects joined together, one heavy, one light. For a hot air baloon, for example, you would have (just like in real life) the balloon itself that would have negative weight and the heavy basket. Of course, in order for the balloon to go up, the absolute weight of the balloon should be higher than the weight of the basket. [import]uid: 160496 topic_id: 30073 reply_id: 120450[/import]

I meant it was defaulting to dynamic, not to change it necessarily but just pointing it out so you knew.

Mike’s advice above is certainly the way to go, well explained @Mike :slight_smile: [import]uid: 52491 topic_id: 30073 reply_id: 120546[/import]

ok thanks - so I think overall sometimes (perhaps in posts) if you see the mention of the term “center of gravity” associated with an object (no joins) in use with physics, then this is really a misnomer, as the center can not be changed for a physics enabled object (i.e. it is always right in the center). [import]uid: 140210 topic_id: 30073 reply_id: 120548[/import]

Just FYI - your body is dynamic because you wrote “kinimatic” rather than “kinematic” - so your testing will be thrown off based on this. [import]uid: 52491 topic_id: 30073 reply_id: 120435[/import]

In the doc for physics AddBody it says:

Note
When you turn a display object into a physics object, the Physics engine owns the object and has its own rules about the object. Physics assumes the reference point of the object is the center of the object so object:setReferencePoint() may change the reference point from Corona’s Display Object point of view but not for the Physics engine. This affects collisions and how other physics bodies interact…

As the doc suggests, doing physics.setDrawMode(“debug”) usually clears up the confusion. [import]uid: 160496 topic_id: 30073 reply_id: 120437[/import]

@peach - thanks (doh) - changed it to “dynamic” in fact and same issue

@mike / @peach - thanks - but how would one then model an object that is elongated with more mass at one end then? Can the physics engine assist here? Actually this question here is really related to my non-code post question here: https://developer.coronalabs.com/forum/2012/08/20/center-mass-physics-question-eg-balloon-weight-bottom

You would have to have two (or more) objects joined together, one heavy, one light. For a hot air baloon, for example, you would have (just like in real life) the balloon itself that would have negative weight and the heavy basket. Of course, in order for the balloon to go up, the absolute weight of the balloon should be higher than the weight of the basket. [import]uid: 160496 topic_id: 30073 reply_id: 120450[/import]

I meant it was defaulting to dynamic, not to change it necessarily but just pointing it out so you knew.

Mike’s advice above is certainly the way to go, well explained @Mike :slight_smile: [import]uid: 52491 topic_id: 30073 reply_id: 120546[/import]

ok thanks - so I think overall sometimes (perhaps in posts) if you see the mention of the term “center of gravity” associated with an object (no joins) in use with physics, then this is really a misnomer, as the center can not be changed for a physics enabled object (i.e. it is always right in the center). [import]uid: 140210 topic_id: 30073 reply_id: 120548[/import]