Problem with Chain Body and Joint

Hi guys!

I have a ball attached with a pivot joint to a base. This ball is moved with a touch joint. Until here everything works well.

Now I need to attach a chain to the ball. So I create the chain body and attach with the ball. But this causes the ball no longer moves.

I tried doing the same thing with a normal rectangle and it works.

So am I doing something wrong or is there a mistake?

To make me understand better I attach a code example:

(try to invoke first test1 and then test2)

local physics = require("physics") physics.setDrawMode( "hybrid" ) physics.start() local base = display.newRect( 160, 240, 30, 30 ) physics.addBody( base, "static", {isSensor=true} ) local ball = display.newCircle( 160, 200, 20 ) ball:setFillColor( 1, 0, 0 ) physics.addBody( ball, "dynamic", {radius=20, density=100} ) local joint\_pivot = physics.newJoint( "pivot", ball, base, base.x, base.y ) function ball:touch( event ) local phase = event.phase if( phase == "began" ) then display.getCurrentStage( ):setFocus( self ) self.isFocus = true self.joint = physics.newJoint( "touch", self, self.x, self.y ) elseif(self.isFocus)then if( phase == "moved" ) then self.joint:setTarget( event.x, event.y ) elseif((phase=="ended")or(phase=="cancelled")) then display.getCurrentStage( ):setFocus( nil ) self.isFocus = false display.remove( self.joint ) end end return true end ball:addEventListener( "touch" ) local function test1() local rect = display.newRect( ball.x+30, ball.y, 100, 20 ) rect:setFillColor( 1, 0, 1 ) physics.addBody( rect, "dynamic", {isSensor=true, density=0.1} ) local joints\_weld = physics.newJoint( "weld", rect, ball, rect.x, rect.y ) end local function test2() local rect = display.newRect( ball.x, ball.y, 10, 10 ) rect:setFillColor( 1, 0, 1 ) physics.addBody( rect, "dynamic", { chain={ 0,0, 50,-0 }, isSensor = true, density=0.1 }) local joints\_weld = physics.newJoint( "weld", rect, ball, rect.x, rect.y ) end --test1() --test2()

Nobody knows something?

Is it necessary to report a bug or is it just me I’m doing wrong?

Now I need to attach a chain to the ball. So I create the chain body 

I think you’re using the word “chain” in two very different ways:

1.  you want to model a real-world “chain” (a set of connected links)

2.  you’ve created a “chain” shape (aka an “edge” shape) for your physics body

problem: the chain shape is not a suitable model for real-world chains. (just for starters: they have no area, thus no mass, so won’t respond like a “proper” dynamic body; et al)  instead see the supplied “Chains” sample for a way to model real-world chains

When @davebollinger says supplied, I think he means the bridge demo that comes with Corona.

I just watched the sample demo.

(I think we all refer to the one indicated by @roaminggamer)

However, actually I would need the 2nd point (“chain” shape (aka an “edge” shape) for your physics body), while the example is focused on point 1.

So now that I understand better, my question becomes:

Can I create chain shape and connect it to my physical body (ball) so that it behaves as if it were another dynamic physical object?

both the “Bridge” and “Chains” samples demonstrate a (the same) workable model of a real-world-chain:

(“Chains” simply looks more like a real-world-chain)

rect-pivot-rect-pivot-rect-pivot-rect (etc, however many links you need)

repeating:  forget about the chain SHAPE - it will NOT behave properly to model a real-world-chain

@davebollinger

I understand! Thank you so much for your time and your advice.

I already have another idea in mind but I’m not sure it can be done. I think it’s more right to open another tread for this.

Nobody knows something?

Is it necessary to report a bug or is it just me I’m doing wrong?

Now I need to attach a chain to the ball. So I create the chain body 

I think you’re using the word “chain” in two very different ways:

1.  you want to model a real-world “chain” (a set of connected links)

2.  you’ve created a “chain” shape (aka an “edge” shape) for your physics body

problem: the chain shape is not a suitable model for real-world chains. (just for starters: they have no area, thus no mass, so won’t respond like a “proper” dynamic body; et al)  instead see the supplied “Chains” sample for a way to model real-world chains

When @davebollinger says supplied, I think he means the bridge demo that comes with Corona.

I just watched the sample demo.

(I think we all refer to the one indicated by @roaminggamer)

However, actually I would need the 2nd point (“chain” shape (aka an “edge” shape) for your physics body), while the example is focused on point 1.

So now that I understand better, my question becomes:

Can I create chain shape and connect it to my physical body (ball) so that it behaves as if it were another dynamic physical object?

both the “Bridge” and “Chains” samples demonstrate a (the same) workable model of a real-world-chain:

(“Chains” simply looks more like a real-world-chain)

rect-pivot-rect-pivot-rect-pivot-rect (etc, however many links you need)

repeating:  forget about the chain SHAPE - it will NOT behave properly to model a real-world-chain

@davebollinger

I understand! Thank you so much for your time and your advice.

I already have another idea in mind but I’m not sure it can be done. I think it’s more right to open another tread for this.