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()