Page 1 of 1

Compound Shapes?

Posted: Sun Jul 08, 2018 11:17 pm
by Withered-Flame
Does anyone know if i can make compound collision shapes? Like a ball and a rectangle combined to make a mace or something?
I heard you can have multiple shapes inside a single body. When i did this, they are separate objects. The handle moves independently of the spike ball.(also, the rectangle is always at the same center point as the circle, i would like to position it relative to the circle)

I have toyed with joints, and the rect always stays locked in a rotation, even when i setFixedRotation(false).


Edit:

I want this:
Image

Not this:
Image


I don't know how bodies, shapes, or fixtures relate to each other very well, so if anyone knows any good resources to learn (other than the wiki, I've tried that.)

Re: Compound Shapes?

Posted: Tue Jul 10, 2018 2:34 pm
by DarkShroom
looks correct to me, you're adding the shape to the body the same way i do

you can use the Fixture:setUserData( value ) to attach some thing to the fixture like a table, you then look for this thing and react appropriately in the physics callback

Re: Compound Shapes?

Posted: Wed Jul 11, 2018 2:57 pm
by Withered-Flame
What about positioning the rectangle relative to the circle?

Re: Compound Shapes?

Posted: Wed Jul 11, 2018 4:00 pm
by pgimeno
Both love.physics.newCircleShape and love.physics.newRectangleShape allow specifying a position.

Re: Compound Shapes?

Posted: Wed Jul 11, 2018 4:46 pm
by Withered-Flame
Thank you!

I have one last question about excluding shapes from other shapes hit boxes, like a cookie cutter.

Is it possible to do that and draw it as well?

Re: Compound Shapes?

Posted: Wed Jul 11, 2018 9:07 pm
by pgimeno
Not to my knowledge.

Re: Compound Shapes?

Posted: Thu Jul 12, 2018 9:19 am
by DarkShroom
Withered-Flame wrote: Wed Jul 11, 2018 4:46 pm Thank you!

I have one last question about excluding shapes from other shapes hit boxes, like a cookie cutter.

Is it possible to do that and draw it as well?
you're seriously asking for it now, it's likely not gonna be practical for you (vs simply drawing a concave polygon or maybe two if you want a "donut" (new word))... however scouting for this sort of thing i did find this library:

https://github.com/AlexarJING/polygon/

you would use the boolean "not" operation... i am still myself trying to combine this with my polygon reduction code. Note that you can cut out shapes sure... however, cutting a hole in the circle could not possibly give a valid polygon shape... an advanced 3D or vector program no doubt (i dunno if you recall quake 2 editors), it has to shove like a line leading to the hole (this code this guy wrote doesn't seem to do that bit)

dunno if i explained that well, will draw a picture if you didn't get me

edit: the guy also has an interesting box 2d physics helper library

Re: Compound Shapes?

Posted: Thu Jul 12, 2018 2:00 pm
by ivan
I have one last question about excluding shapes from other shapes hit boxes, like a cookie cutter.
No, Box2D works with convex polygons up to 8 vertices max.
Box2D has several other limitations too like minimum edge length and vertex angle.
In short, you want to avoid long, thin triangles which is not simple.
Most geometry libraries will NOT work well with Box2d.
If the output is for rendering only then yes, you could probably get away with it.
Briefly going over AlexarJING's code - it doesn't look very impressive and I also have doubts about its robustness.
The most popular libs are Clipper (for polygon operations) and Poly2Tri (for triangulation) but you need to use those through FFI. And like I said, their output is not designed for Box2D.
The most sensible approach with Box2D is to use simple, overlapping shapes.
Good luck!