body's falling through static bodies

Official forum for the Chipmunk2D Physics Library.
Post Reply
BobbyGilbert
Posts: 13
Joined: Fri Oct 07, 2011 6:36 am
Contact:

body's falling through static bodies

Post by BobbyGilbert »

Hi,

I have problems where my dynamic bodies (mice) sometimes fall through a static body (a cat) and sometimes bounce off it (which is what I want to happen). Sometimes bodies seem to get stuck to each other or to the static boundary I've put in place.

I've tried pushing up space->iterations = 100 but that doesn't help.

I'm importing the bodies from a PhysicsEditor plist so the inertias should hopefully be correct as I'm using the Andreas Loew example code to do this, GCpShapeCache.m.

Any ideas?

It is possible I'm using an old version of chipmunk. I don't think so, but how do I check? Is there a version file? I've stripped out everything except the 'include' and 'src' directories.

Regards

Bobby
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: body's falling through static bodies

Post by slembcke »

How small are the shapes that physics editor produces? In my experience, it creates a ton of tiny tiny shapes which really kills the performance once you have a half dozen objects on the screen created by it. Because the shapes are so small they can easily become "tangled" on static line segments or other shapes.

Is there anything you can adjust so that it doesn't spit out small shapes?

I have some code for a Cocos2D node that will draw all the shapes in a space. It was made for Objective-Chipmunk, but should be trivial to modify for regular Chipmunk. That should help you visualize the problem.
http://files.slembcke.net/temp/ChipmunkDebugNode.tgz
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
BobbyGilbert
Posts: 13
Joined: Fri Oct 07, 2011 6:36 am
Contact:

Re: body's falling through static bodies

Post by BobbyGilbert »

Thanks. I'm looking into this. Have simplified all of the shapes into circles or rectangles but still getting problems.

How do I check what version of chipmunk I'm using? I notice that the hash function and elastic iterations are needed in earlier versions?

Bobby
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: body's falling through static bodies

Post by slembcke »

If you are using 6.x (which it sounds like), chipmunk.h will have something like this in it:

Code: Select all

#define CP_VERSION_MAJOR 6
#define CP_VERSION_MINOR 0
#define CP_VERSION_RELEASE 2

extern const char *cpVersionString;
Chipmunk 5.x only has cpVersionString which is defined in chipmunk.c.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
BobbyGilbert
Posts: 13
Joined: Fri Oct 07, 2011 6:36 am
Contact:

Re: body's falling through static bodies

Post by BobbyGilbert »

Just checked and I appear to be on version 5. Thought I should up date so I've replaced the version 5 src and include files with the 6.0.2 ones. Now get loads of compile errors in xcode 4 compiler. E.g. no member named 'node' in 'struct cpBody' and lots of other stuff suggesting it can't find stuff.

I've not changed the library search paths so I would have thought everything would still be found.

Do you have any notes on upgrade issues?

Does it matter if I use LLVM compiler 3.0 or LLVM compiler 4.2?

Any other ideas? I am assuming that it is best that I work with 6.0.2 rather than 5 even if it doesn't sort out my current issue (which I have a few ideas about anyway).

Bobby
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: body's falling through static bodies

Post by slembcke »

Depends on if you were using the private API in places. (cpBody.node was private for instance) In Chipmunk 6, the private stuff must be accessed with the CP_PRIVATE macro instead of just being documented as private.

Also, I wouldn't really recommend putting the source into your project. You should really consider using the iphonestatic.command script to build a static library instead. That way you know all the correct compiler flags for performance have been set correctly.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
BobbyGilbert
Posts: 13
Joined: Fri Oct 07, 2011 6:36 am
Contact:

Re: body's falling through static bodies

Post by BobbyGilbert »

OK. Just noticed all the errors were in drawspace.c which I was using to debug shapes etc. I'm guessing this has been overtaken by the example code you mentioned in the earlier post? I'll investigate. Thanks.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: body's falling through static bodies

Post by slembcke »

Also, the version history should help point you in the right direction for public APIs to use to replace the private ones people were using in older versions. https://raw.github.com/slembcke/Chipmun ... ERSION.txt
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
BobbyGilbert
Posts: 13
Joined: Fri Oct 07, 2011 6:36 am
Contact:

Re: body's falling through static bodies

Post by BobbyGilbert »

Updating on the original post, I've improved things no end by moving the origin in Physics Editor to be approximately the centre of the physics object. I didn't realise that this is not only used as an anchor point, but also as the centre of mass if you use the Andreaas Lowe code for reading the physics editor plist. I was getting some huge moments of inertia about the point 0,0 in my image giving some odd effects.

So, good tip for anyone using this program: move the centre point from 0,0 to the centre of the object!
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests