Single '3 untouching circles' physics body?

a body that is 3 triangles not touching spaced out can be achieved modifying the multi body ex:

local car = display.newImage( "car.png" )
local roofShape = { -20,-10, 20,-10, 20,10, -20,10 }
local hoodShape = { 0,-35, 37,30, -37,30 }
local trunkShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
 physics.addBody( car, "dynamic",
    { density=3.0, friction=0.5, bounce=0.2, shape=roofShape },
    { density=6.0, friction=0.6, bounce=0.4, shape=hoodShape },
    { density=4.0, friction=0.5, bounce=0.4, shape=trunkShape }
)

if i want 3 circles (ie the physics body is 3 big dots not touching
) how would i do so if specifying radius=number always takes the same origin for each circle and {x=} doesnt seem to work?

    { density=3.0, friction=0.5, bounce=0.2, radius=30 },
    { density=6.0, friction=0.6, bounce=0.4, radius=40, x=50 }, --x not working, makes at same spot

i can always use shape= to make 3 blocky circles, but iā€™d need a utility to generate like 80 xy sets to get smooth collision/rubbingā€¦not sure if viable resource-wise.

Youā€™re making some changes in your code that arenā€™t consistent with the Solar2D documentation. The parameter ā€˜xā€™ within the table for creating a body doesnā€™t exist, which is why it has no effect.

I think what you want to do can be achieved with joints. Check the documentation on joints, and you might find something that helps you accomplish what youā€™re aiming for.

1 Like

The current Box2D version of Solar2D does not provide x and y parameters for a circle body. You can either use a polygon shape to make it manually, or refer to the method mentioned by @aclementerodrguez.

Additionally, there is a version of Solar2Dā€™s Box2D v3 that supports the circle body.

physics.addBody(object, "dynamic", {circle = {radius = r, x = x, y = y}})

This version also includes many features and changes compared to the current Box2D version in Solar2D.

You can find it here:

Using joints the ā€œdistanceā€ type seems to come closest to the multi-body car ex.
It requires defining 3 separate bodies, and I couldnā€™t get them completely springless with the settingsā€¦I think thereā€™s overlap between the density/friction/bounce/etc properties of each body and the settings for both joints overlapping at one body but I donā€™t know. Would opt for using the car method with a single body and polygonal circles if u donā€™t need smooth collisions.

--sort of springy distance; obj1, obj2, obj1Anchor, obj2Anchor. set anchors at center of each object and use .length to change line length; otherwise just pick the point inbetwen for both for normal movement or just 0,0,0,0
	self.body=physics.newJoint("distance", self.body1,self.body2 ,0,0,0,0)
	self.bdy=physics.newJoint("distance", self.body3,self.body2 ,0,0,0,0)
		-- self.body.dampingRatio=1 --0 is alot of oscillations; 1 is no oscillations
		-- self.body.frequency=3000000 -- low value maes join soft and contract east
		-- self.body.length=20 --can increase with buttkon press etc
		-- self.bdy.dampingRatio=1 
		-- self.bdy.frequency=3000000 
		-- self.bdy.length=20 -