Page 1 of 1

Problem with bigger polygon (more verts)

Posted: Tue Sep 30, 2008 12:18 pm
by mbue
Hi everybody,

I recently started to integrate chipmunk into my WIP game [1] and encountered a few problems with polygon collisions.
I sorted out some of them (polygons were initially winding the wrong way (they need to be clockwise instead of counter clock wise in my case ... my y axis points up).

Now collisions work perfectly ... at least until I add more than 4 vertices to the polygon(s).
Then there are only random cases left when it works.

Is there a limitation on the maximum number of verts per poly? .. or on the shape (e.g. concave polys)?
What things do I need to look closely at (except vertex order - as mentioned above)?

Cheers,
Martin

[1] Some more details

Re: Problem with bigger polygon (more verts)

Posted: Tue Sep 30, 2008 2:31 pm
by ker
Hey Martin

Polygons HAVE to be convex.
I easily have collisions working with polygons that have up to 15 vertices (never tried more).
to create concave polygons you need to create multiple convex polygons. Also keep some overlap there, otherwise really thin polygons might try to get into the non-existing space between two polygons.

Re: Problem with bigger polygon (more verts)

Posted: Tue Sep 30, 2008 2:40 pm
by mbue
ker wrote:Hey Martin

Polygons HAVE to be convex.
Ah, that explains everything ... many thanks for the hint :)

EDIT: Just wanted to add that this is hell for building complex environment stuff though. Nothing that would stop me of course ;)

Martin

Re: Problem with bigger polygon (more verts)

Posted: Tue Sep 30, 2008 3:03 pm
by slembcke
If you are building complex environments, could you use line segments instead? They don't represent a volume like polygons do, but that's not really an issue unless you have fast moving objects.

Re: Problem with bigger polygon (more verts)

Posted: Tue Sep 30, 2008 3:23 pm
by mbue
slembcke wrote:If you are building complex environments, could you use line segments instead? They don't represent a volume like polygons do, but that's not really an issue unless you have fast moving objects.
I was thinking about that as well right now. (I didn't have much success getting them to work before, but that was before I fix my other collision code&data - it should be working now)
I'll see if I can get segments to work here (I have to exporting/parsing code for easy segment generation yet) and report back here.
I'm thinking about supporting both - polygon and line-segments with the same base-data, but different export settings. [1]
So you basically are modelling edge-loops and you can then export CP polygons or segments at will.

Anyway, I just changed my map to be mostly convex polygons + circles and it works beautifully now :)

EDIT: I guess one could even store segments the same way polygons are stored now to keep them grouped together inside CP (cpVect *verts). But I guess that would be better posted in the feature request forum ;)

Martin

[1] If anybody is interested in the blender exporter for collision shapes (polys + circles) just contact me. It exports lua code right now, but that is easily tweaked.

Re: Problem with bigger polygon (more verts)

Posted: Wed Oct 01, 2008 1:54 am
by mbue
Using segment shapes works perfectly for my purposes.
They can be created exactly the same way in my workflow and work as good as my previous workaround with many convex polygon shapes.

Only thing one needs to consider is that there may be a lot more seperate shape-entries to keep track of.

Martin