Dynamic objects floating through static ones
Posted: Sat Apr 16, 2011 11:19 am
Hi -
I'm having an issue getting collisions to work correctly. I'm just getting started with chipmunk, and after successfully implementing a tutorial: http://www.alexandre-gomes.com/articles/chipmunk/ I'm trying to create my own simple program from scratch.
Basically all I do is:
1. initialize chipmunk with gravity
2. create a rectangular static object (floor)
3. create a dynamic square above the floor
4. call spaceStep and hashEach on a timer to let the square drop.
What I was expecting was for the square to land on the platform, maybe bounce and come to a stop. Instead, when the square lands, it slows down and drifts slowly through the platform, almost like it's under water.
Here's how I set up my objects:
the platform:
The falling block:
If anyone knows why it would be acting this way the assist would be much appreciated!
I'm having an issue getting collisions to work correctly. I'm just getting started with chipmunk, and after successfully implementing a tutorial: http://www.alexandre-gomes.com/articles/chipmunk/ I'm trying to create my own simple program from scratch.
Basically all I do is:
1. initialize chipmunk with gravity
2. create a rectangular static object (floor)
3. create a dynamic square above the floor
4. call spaceStep and hashEach on a timer to let the square drop.
What I was expecting was for the square to land on the platform, maybe bounce and come to a stop. Instead, when the square lands, it slows down and drifts slowly through the platform, almost like it's under water.
Here's how I set up my objects:
the platform:
Code: Select all
cpBody *body = cpBodyNew(INFINITY, INFINITY);
body->p = cpv(0, -5);
cpSpaceAddBody(space, body);
cpVect verts[] = {
cpv(-10, 2.5),
cpv(10, 2.5),
cpv(10, -2.5),
cpv(-10, -2.5)
};
cpShape* rep = cpPolyShapeNew(body, 4, verts, cpvzero);
rep->data = body;
rep->e = 1.0;
rep->u = 2.5;
rep->collision_type = 0;
cpSpaceAddStaticShape(space, rep);
The falling block:
Code: Select all
cpBody *body = cpBodyNew(100, INFINITY);
body->p = cpv(0, -0);
cpSpaceAddBody(space, body);
cpVect verts[] = {
cpv(-.5, .5),
cpv(.5, .5),
cpv(.5, -.5),
cpv(-.5, -.5)
};
cpShape* rep = cpPolyShapeNew(body, 4, verts, cpvzero);
rep->data = body;
rep->e = 1.0;
rep->u = 2.5;
rep->collision_type = 1;
cpSpaceAddShape(space, rep);