I am trying to use the “REVOLUTE” joint type but the bodies that I am trying to attach just spring apart. I think the issue is that codea thinks the bodies have collided and pushed them apart Here is my code so far:
--# Main
--Main
function setup()
FPS=0
parameter.watch("FPS")
ground = PhysicsEdge(vec2(0,50),vec2(WIDTH,50))
box = PhyiscsPolygon(WIDTH/2,HEIGHT/2,
{
vec2(-50,-50/2),
vec2(50,-50/2),
vec2(50,50/2),
vec2(-50,50/2)
})
wheel = PhysicsCircle(box.object.x,box.object.y,30)
axle=physics.joint(REVOLUTE,box,wheel,vec2(wheel.object.x,wheel.object.y))
end
function draw()
FPS=1/DeltaTime
background(0)
box:draw()
ground:draw()
wheel:draw()
end
--# PhyiscsPolygon
PhyiscsPolygon = class()
function PhyiscsPolygon:init(x,y,v)
self.vertices = v
self.object = physics.body(POLYGON,unpack(self.vertices))
self.object.x = x
self.object.y = y
self.object.angle = 0
end
function PhyiscsPolygon:draw()
pushMatrix()
translate(self.object.x,self.object.y)
rotate(self.object.angle)
pushStyle()
stroke(255)
strokeWidth(5)
local i= 1
while i < #self.vertices do
line(self.vertices[i].x,self.vertices[i].y,self.vertices[i+1].x,self.vertices[i+1].y)
i = i + 1
end
line(self.vertices[i].x,self.vertices[i].y,self.vertices[1].x,self.vertices[1].y)
popStyle()
popMatrix()
end
--# PhysicsCircle
PhysicsCircle = class()
function PhysicsCircle:init(x,y,r)
self.radius = r
self.object = physics.body(CIRCLE,self.radius)
self.object.x = x
self.object.y = y
self.object.angle = 0
end
function PhysicsCircle:draw()
pushStyle()
pushMatrix()
translate(self.object.x,self.object.y)
rotate(self.object.angle)
noFill()
stroke(255)
strokeWidth(5)
ellipseMode(RADIUS)
ellipse(0,0,self.radius)
line(0,0,self.radius -5,0)
popMatrix()
popStyle()
end
--# PhysicsEdge
PhysicsEdge = class()
function PhysicsEdge:init(p1,p2)
self.object = physics.body(EDGE,p1,p2)
self.p1 = p1
self.p2 = p2
end
function PhysicsEdge:draw()
pushStyle()
stroke(255)
strokeWidth(5)
line(self.p1.x,self.p1.y,self.p2.x,self.p2.y)
popStyle()
end
function PhysicsEdge:touched(touch)
end