need help with some physics

Hi guys,

I have been racking my brain on this issue.. and can't seem to fix it... it might be something small that I am just missing..

basically what I need is a thin rectangle that is suspended from the celling to be able to move when the user touches the screen (I have done this.. easy) but what I also need is a square to be attached to the bottom of the rectangle. When the physics kicks in they move differently.. I need the square to be attached to the rectangle so that it just moved with the rectangle..

I tried using the weld join but no good.. I think its to do with my reference point in the rectangle. but if I change that then the two items are stuck together but I can't swing properly from the celling...

code below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 )
views:1655 update:2011/12/29 9:44:01
corona forums © 2003-2011