Joints increasing object mass

Hi,

I was making a game and wanted to use joints, but adding joints causes increase in the mass of the main object and the main object tilts to its side coz of the added mass.

My usecase goes like this,

i have a horizontal wooden plank in a free fall, i have added a spike using weld joint to its left, when i add a spike the wooden plank is falling sidewards because of increase in the mass, i tried making the spike density to zero with no luck, is there a way to make the plank fall uniformly with joints to other objects.

my code:

main.lua

display.setStatusBar( display.HiddenStatusBar ) local physics = require( "physics" ) physics.start() -- physics.setDrawMode( "hybrid" ) display.setDefault( "background", 0, 0, 0) ------------------------------------------------------------ local plank = display.newRect( 0,0,display.contentWidth,40 ) plank.x = display.contentCenterX plank.y = 0 plank:setFillColor( 219/255, 112/255, 147/255 ) physics.addBody( plank, "dynamic", {isSensor = true} ) plank.gravityScale = 0.7 ----------------------------------------------------------------------------- local spikeVertices = {100,25,50,25,75,100} local SpikeGrp = display.newGroup() local numVertices = plank.width/10 for i=0,2 do local spike = display.newPolygon(numVertices\*i,30,spikeVertices) spike:setFillColor(219/255, 112/255, 147/255 ) physics.addBody( spike, "dynamic", {isSensor = true, density = 0 } ) local weldJoint = physics.newJoint( "weld", plank, spike,numVertices\*i, 0 ) weldJoint.dampingRatio = 1 spike.joint = weldJoint SpikeGrp:insert(spike) end

attached screenshot for reference

TIA,

Nischal Y

Nope: The joint doesn’t modify mass.  By attaching objects to the plank you’re effectively modifying the moment of inertia (and increasing the mass) of the whole body (combined objects).

No: All physics objects have mass.  They must or the physics calculations will crash.  Mass is a fundamental property in physics calculations.

If you want the body to be balanced, you need to counter-balance and mount an equal mass on the other side of the plank.

No matter what you do, you’ve fundamentally changed the center-of-mass.

See diagrams below ( x is center of mass ):

Plank With No Bodies (density == 1)

= = = = = X = = = = =

Plank with Bodies mounted on left:

A A = X = = = = = = =

If we treat the plank and the bodies ‘A’ as a single unit (for simplicity), we can easily see that the center of mass moves left towards the mounted bodies.

To even this out we need to do mount bodies on the right too:

A A = = = X = = = A A

Note: Setting ‘gravityScale’ to zero for the mounted bodies will not help.  It will reduce the effect of gravity on those bodies, but not remove their inertia.

Ok my usecase is i have a wodden plank and i want to place spikes below the plank like this

========================

VVVVVVVVVVVVVVVVVVVVV

and in the game at some point i want some of my spikes to fall

=========================

V  VVVVVVVV  vVVVVVVVVVVV

  V                    V

and one more catch is the plank is freefalling as well :slight_smile: can i achieve this in any possible way(im ok even if we wont use joints)?

I should have thought of this before, but if you want the ‘plank’ to fall and never rotate, you can set this attribute:

http://docs.coronalabs.com/daily/api/type/Body/isFixedRotation.html

Yep this didn’t strike me as well, this worked, thanks a lot :slight_smile:

you get rotation because gravity scale on spikes (1.0) is stronger than plank (0.7).  make them all the same and rotation will vanish since all are acted upon by same force.  might still have other problems tho:  vertices should be clockwise, zero-centered, used as shape in addBody, etc

ps: would likely more stable overall as a multi-fixtured single body rather than many bodies/joints

Nope: The joint doesn’t modify mass.  By attaching objects to the plank you’re effectively modifying the moment of inertia (and increasing the mass) of the whole body (combined objects).

No: All physics objects have mass.  They must or the physics calculations will crash.  Mass is a fundamental property in physics calculations.

If you want the body to be balanced, you need to counter-balance and mount an equal mass on the other side of the plank.

No matter what you do, you’ve fundamentally changed the center-of-mass.

See diagrams below ( x is center of mass ):

Plank With No Bodies (density == 1)

= = = = = X = = = = =

Plank with Bodies mounted on left:

A A = X = = = = = = =

If we treat the plank and the bodies ‘A’ as a single unit (for simplicity), we can easily see that the center of mass moves left towards the mounted bodies.

To even this out we need to do mount bodies on the right too:

A A = = = X = = = A A

Note: Setting ‘gravityScale’ to zero for the mounted bodies will not help.  It will reduce the effect of gravity on those bodies, but not remove their inertia.

Ok my usecase is i have a wodden plank and i want to place spikes below the plank like this

========================

VVVVVVVVVVVVVVVVVVVVV

and in the game at some point i want some of my spikes to fall

=========================

V  VVVVVVVV  vVVVVVVVVVVV

  V                    V

and one more catch is the plank is freefalling as well :slight_smile: can i achieve this in any possible way(im ok even if we wont use joints)?

I should have thought of this before, but if you want the ‘plank’ to fall and never rotate, you can set this attribute:

http://docs.coronalabs.com/daily/api/type/Body/isFixedRotation.html

Yep this didn’t strike me as well, this worked, thanks a lot :slight_smile:

you get rotation because gravity scale on spikes (1.0) is stronger than plank (0.7).  make them all the same and rotation will vanish since all are acted upon by same force.  might still have other problems tho:  vertices should be clockwise, zero-centered, used as shape in addBody, etc

ps: would likely more stable overall as a multi-fixtured single body rather than many bodies/joints