# How do I use physics.joint?

I was playing with balls (http://codea.io/talk/discussion/6714/playing-with-balls) using physics and wanted to use joints on them like the one on physics lab. I tried to look up on how they work but I understood none so far. I also tried playing around with them but it doesn’t work.

Here’s a simple example of 2 joints.

supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
speed=470
c1 = physics.body(CIRCLE,0)
c1.x = 400
c1.y = 900
c1.restitution = 1
c1.type = STATIC
c2 = physics.body(CIRCLE,25)
c2.x = 400
c2.y = 600
c2.restitution = 1
c3 = physics.body(CIRCLE, 25)
c3.x = 400
c3.y = 800
c3.linearVelocity=vec2(speed,0)
c3.restitution = 1
joint1 = physics.joint(REVOLUTE,c1,c2,c1.position)
joint2 = physics.joint(REVOLUTE, c2, c3,c2.position)
end

function draw()
background(40, 40, 50)
fill(255)
noFill()
stroke(255)
strokeWidth(2)
line(c1.x,c1.y,c2.x,c2.y)
line(c2.x,c2.y,c3.x,c3.y)
ellipse(c1.x,c1.y,2)
ellipse(c2.x,c2.y,c2.radius*2)
ellipse(c3.x,c3.y,c3.radius*2)
end

@xvine Here’s a stripped down version of the above code. I removed all the code that wasn’t needed. This should be easier to understand joints.

supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
c1 = physics.body(CIRCLE,0)
c1.x = 400
c1.y = 1000
c1.type = STATIC
c2 = physics.body(CIRCLE,25)
c2.x = 700
c2.y = 700
c3 = physics.body(CIRCLE, 25)
c3.x = 600
c3.y = 900
joint1 = physics.joint(REVOLUTE,c1,c2,c1.position)
joint2 = physics.joint(REVOLUTE, c2, c3,c2.position)
end

function draw()
background(40, 40, 50)
noFill()
stroke(255)
strokeWidth(2)
line(c1.x,c1.y,c2.x,c2.y)
line(c2.x,c2.y,c3.x,c3.y)
ellipse(c2.x,c2.y,c2.radius*2)
ellipse(c3.x,c3.y,c3.radius*2)
end

Thanks @dave1707, it helped me a lot