## No collision

Discuss any Chipmunk bugs here.
swemaniac
Posts: 2
Joined: Tue Sep 04, 2007 6:31 am
Contact:

### No collision

I don't know if this is the right place for this, maybe there should be a 'Help' forum?

Anyway I've just started implementing Chipmunk in my OGL engine but I'm having problems with objects not colliding. Springs and joints work fine! It's the simplest setup, a box and a static segment plane (ground), and the box is falling right through the plane.

Chipmunk detects the collision between the shapes and goes into the seg2poly function, but it rejects the collision right about here:

Code: Select all

``````        for(int i=0; i<poly->numVerts; i++){
cpFloat dist = segValueOnAxis(seg, axes[i].n, axes[i].d);
if(dist > 0.0f){ // here one of the distances go over zero....
return 0;
} else if(dist > poly_min){
poly_min = dist;
mini = i;
}
}
``````
This also happens with a box-to-box collision, so it's not just the seg2poly function. Can it have something to do with coordination systems? I'm setup like so: 0,0,640,480 (left,bottom,right,top).

Here's basically what I got going:

Code: Select all

``````        cpInitChipmunk();

space = cpSpaceNew();
space->gravity = cpv(0.0f, -100.0f);
cpSpaceResizeStaticHash(space, 20.0f, 999);
cpSpaceResizeActiveHash(space, 20.0f, 100);

// the box body
cpVect verts[] = { cpv(-20.0f, 20.0f), cpv(-20.0f, -20.0f), cpv(20.0f, -20.0f), cpv(20.0f, 20.0f) };
float mass = 5.0f;
float moment = cpMomentForPoly(mass, 4, verts, cpvzero);
box = cpBodyNew(mass, moment);
box->p = cpv(320.0f, 340.0f);

// the box shape
cpShape *shape = cpPolyShapeNew(box, 4, verts, cpvzero);
shape->u = 0.5f;
shape->e = 1.0f;

// the static plane (ground)
plane = cpBodyNew(INFINITY, INFINITY);
plane->p.x = 320.0f;
cpShape *planeShape = cpSegmentShapeNew(plane, cpv(-320.0f, 10.0f), cpv(320.0f, 10.0f), 1.0f);
``````
And then I reset forces and do cpSpaceStep (in substeps) every frame. Any ideas what I'm doing wrong?

Thanks,
Johan
swemaniac
Posts: 2
Joined: Tue Sep 04, 2007 6:31 am
Contact:

### Re: No collision

With some ideas from Scott I managed to solve it - the winding of the polys was just wrong, how about that.

### Who is online

Users browsing this forum: No registered users and 1 guest