Problem with bigger polygon (more verts)

Official forum for the Chipmunk2D Physics Library.
Post Reply
mbue
Posts: 7
Joined: Tue Sep 30, 2008 8:45 am
Contact:

Problem with bigger polygon (more verts)

Post 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
ker
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am
Contact:

Re: Problem with bigger polygon (more verts)

Post 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.
mbue
Posts: 7
Joined: Tue Sep 30, 2008 8:45 am
Contact:

Re: Problem with bigger polygon (more verts)

Post 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
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Problem with bigger polygon (more verts)

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mbue
Posts: 7
Joined: Tue Sep 30, 2008 8:45 am
Contact:

Re: Problem with bigger polygon (more verts)

Post 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.
mbue
Posts: 7
Joined: Tue Sep 30, 2008 8:45 am
Contact:

Re: Problem with bigger polygon (more verts)

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

Who is online

Users browsing this forum: No registered users and 9 guests