Basically I need to have three bodies,
- Celling (static)
- long thin rectangle (dynamic)
- Square (dynamic)
The rectangle is attached to the celling, so that it can swing backwards and forwards. The square needs to be attached to the bottom of the rectangle.
The issue I am facing is when the rectangle swings, the square moves differently to the rectangle. I need both of them to move together. ie the square should be fixed to the rectangle at the bottom, so if I apply any impulse both of them should move together…
hope that makes sense
[code]
local physics = require “physics”
physics.start( true )
physics.setDrawMode(“normal”) – set to “debug” or “hybrid” to see collision boundaries
physics.setDrawMode(“hybrid”)
physics.setGravity( 0, 9.8 ) --> 0, 9.8 = Earth-like gravity
local cel = display.newRect(0, 0, display.contentWidth, 100)
physics.addBody(cel, “static” )
local line = display.newRect(200, 100, 10, 600)
local square = display.newRect(line.x - 50 , line.y+200 , 100, 100)
function movement(event)
line:applyLinearImpulse( 1, 0, line.x, line.y )
end
physics.addBody(line, “dynamic”, {shape=unit} )
physics.addBody(square, “dynamic” )
line:setReferencePoint( display.TopCenterReferencePoint )
local joint = physics.newJoint( “pivot”, cel, line, line.x, line.y - 20 )
local joint1 = physics.newJoint( “weld”, square, line, 200, 600 )
Runtime:addEventListener( “touch”, movement )
[/code] [import]uid: 67619 topic_id: 20135 reply_id: 320135[/import]