We have two circle bodies c1 and c2 of radius r1 and r2 (love.physics made)
we place these circles such that r1 is above r2 and they are in contact with no overlap.
I wish to loosely weld c1 to c2 such that c2 always is attached to the point it is in contact with from creation.
Or specifically, assume p1 is the point r1 distance from c1 towards c2;
IF c1 rotates, c2 will move as if it is attached to the point p1, BUT I want this attachment to be springy aswell,
That is I wish for c2 to be able to move asif attached by a spring to point p1.
Lastly the circles will shrink or grow constantly based on outside influences
Solution I Use : (not working)
Let the two circles be named A and B respectively
Create two bodies of size s ( s = 6 ) :
p1 is placed r1 distance away from c1 at angle towards c2
p2 is placed r2 distance away from c2 at angle towards c1
--Essentially now both points are next to one another too.
--These points are welded at their position on their respective circles and will never collide with anything, ie:
Code: Select all
p1_weld = love.physics.newWeldJoint(p1,c1,p1.position.x,p1.position.y,false)
p2_weld = love.physics.newWeldJoint(p2,c2,p2.position.x,p2.position.y,false)
Code: Select all
distanceJoint = love.physics.newDistanceJoint(p1,p2,0,0,0,0,false)
To ensure the points are always on the edge of their circle we use setPosition every love.update() :
Code: Select all
angle = the angle c1 to p1
r = the radius of c1
p1x = math.cos(angle)*r
p1y = math.sin(angle)*r
p1:setPosition(p1x,p1y)
--
angle = the angle c2 to p2
r = the radius of c2
p2x = math.cos(angle)*r
p2y = math.sin(angle)*r
p2:setPosition(p2x,p2y)
Notes
In theory this works, yet i experience constantly weird results.
I need the circles to be free to pull apart and grow/shrink and since I can not move anchor points of any joint its impossible to make a single Distance joint between c1 and c2 at the edges and then update the anchors to respective radii on growth and shrinkage.
I have to use separate bodies that i can move which would move the anchors (my theory)
Does anyone have any idea how i can solve my above problem ?