Compound Shapes?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Withered-Flame
Prole
Posts: 10
Joined: Sun Jul 08, 2018 10:56 pm

Compound Shapes?

Post 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.)
Last edited by Withered-Flame on Tue Jul 31, 2018 1:52 pm, edited 5 times in total.
DarkShroom
Citizen
Posts: 86
Joined: Mon Jul 17, 2017 2:07 pm

Re: Compound Shapes?

Post 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
Withered-Flame
Prole
Posts: 10
Joined: Sun Jul 08, 2018 10:56 pm

Re: Compound Shapes?

Post by Withered-Flame »

What about positioning the rectangle relative to the circle?
Withered-Flame
Prole
Posts: 10
Joined: Sun Jul 08, 2018 10:56 pm

Re: Compound Shapes?

Post 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?
User avatar
pgimeno
Party member
Posts: 2575
Joined: Sun Oct 18, 2015 2:58 pm

Re: Compound Shapes?

Post by pgimeno »

Not to my knowledge.
DarkShroom
Citizen
Posts: 86
Joined: Mon Jul 17, 2017 2:07 pm

Re: Compound Shapes?

Post 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
User avatar
ivan
Party member
Posts: 1719
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Compound Shapes?

Post 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!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests