New to library and having some trouble

Official forum for the Chipmunk2D Physics Library.
Post Reply
the pizza boy
Posts: 5
Joined: Thu Apr 24, 2008 9:03 pm
Contact:

New to library and having some trouble

Post by the pizza boy »

I have a small circle that falls. I want it to hit a static shape below it, but it falls right through the static shape. Here's the relevant parts of my code:

Code: Select all

    cpInitChipmunk();
    
    cpSpace* World = cpSpaceNew();
    World->gravity = cpv(0,-1);
    
    cpBody* body;
    cpShape* shape;
    cpBody* staticbody = cpBodyNew(INFINITY, INFINITY);

    body = cpBodyNew(0.1,0);
    body->p = cpv(50,-50);
    shape = cpCircleShapeNew(body, 8, cpvzero);
    cpSpaceAddBody(World, body);
    cpSpaceAddShape(World, shape);
    
    shape = cpCircleShapeNew(staticbody, 32, cpv(50,-100));
    cpSpaceAddStaticShape(World, shape);
I am just using a static circle to quickly test it.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: New to library and having some trouble

Post by slembcke »

Just a guess, but you are setting the moment of inertia to 0. That's going to cause all sorts of weird behavior.

If you don't want the object to rotate, set it to infinity. Otherwise use cpMomentForCircle(). If you really understand what the moment of inertia is for you can calculate and set it yourself, but guessing a number always leads to frustration.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
the pizza boy
Posts: 5
Joined: Thu Apr 24, 2008 9:03 pm
Contact:

Re: New to library and having some trouble

Post by the pizza boy »

Thanks, that worked fine. This library is great!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests