The infinite moment of inertia allows fly through objects

Official forum for the Chipmunk2D Physics Library.
Post Reply
BratSinot
Posts: 3
Joined: Wed Mar 07, 2012 12:27 pm
Contact:

The infinite moment of inertia allows fly through objects

Post by BratSinot »

Hello there!

I have a body with infinite inertia. It falls to the ground normally, but if you throw it up, it passes through the object.

Code: Select all

struct PlayerObj *createPlayer(cpSpace *area, cpFloat mass, cpFloat x, cpFloat y, cpFloat w, cpFloat h)
{
 struct PlayerObj *obj = malloc(sizeof(struct PlayerObj));

 obj->w = w;
 obj->h = h;

 obj->body = cpSpaceAddBody(area, cpBodyNew(mass, cpMomentForBox(mass, w, h)));
 cpBodySetPos(obj->body, cpv(x, y));
 obj->shape = cpSpaceAddShape(area, cpBoxShapeNew(obj->body, w, h));

 return obj;
}

struct BoxObj *createBox(cpSpace *area, cpFloat x, cpFloat y, cpFloat w, cpFloat h)
{
 struct BoxObj *obj=malloc(sizeof(struct BoxObj));
 obj->x=x;
 obj->y=y;
 obj->w=w;
 obj->h=h;

 cpVect vect[4];
 vect[0] = cpv(x, y);
 vect[1] = cpv(x, y+h);
 vect[2] = cpv(x+w, y+h);
 vect[3] = cpv(x+w, y);

 obj->shape = cpPolyShapeNew(area->staticBody, 4, vect, cpvzero);
 cpSpaceAddStaticShape(area, obj->shape);

 return obj;
}

Code: Select all

cpBodyApplyImpulse(Player->body, cpv(0.0, -160.0), cpvzero);
BratSinot
Posts: 3
Joined: Wed Mar 07, 2012 12:27 pm
Contact:

Re: The infinite moment of inertia allows fly through object

Post by BratSinot »

I solved this problem by using cpSpaceAddCollisionHandler.
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests