I'm new to physics in cocos2d. I'm using chipmunk, and when two object collide, its just to "soft", like they where made of sponge or rubber.
My code:
cpInitChipmunk();
space = cpSpaceNew();
space->gravity = cpv(0, 0);
schedule(schedule_selector(HelloWorld::step), 1.0f/60.f);
astroBody = cpBodyNew(100, INFINITY);
astroBody->p = cpv(512,384);
cpSpaceAddBody(space, astroBody);
int num2 = 8;
cpVect vertsAstro[] = {
cpv(-17.0f, -44.9f),
cpv(-29.5f, -33.2f),
cpv(-32.9f, -13.1f),
cpv(-24.0f, 11.7f),
cpv(24.6f, 11.5f),
cpv(32.9f, -12.9f),
cpv(29.3f, -33.1f),
cpv(17.0f, -44.7f)
};
astroShape = cpPolyShapeNew(astroBody, num2, vertsAstro, cpv(0,0));
astroShape->e = 0.0f;
astroShape->u = 0.0f;
astroShape->collision_type = 0;
astroShape->data = player;
cpSpaceAddShape(space, astroShape);
cpBody *box = cpBodyNew(INFINITY, INFINITY);
box->p = cpv(z->getPosition().x+32, z->getPosition().y+32);
int num = 5;
cpVect verts[] = {
cpv(-32, -32),
cpv(-32, 32),
cpv(32, 32),
cpv(32, -32),
cpv(-32, -32)
};
cpShape *boxShape = cpPolyShapeNew(box, num, verts, cpv(0,0));
boxShape->e = 0.0f;
boxShape->u = 0.0f;
boxShape->collision_type = 1;
boxShape->data = z;
cpSpaceAddStaticShape(space, boxShape);
So these objects are colliding, and it is too soft. Can I make it somehow to look like two stones hit each other?
From the docs:
void cpShapeSetElasticity(cpShape *shape, cpFloat value)
Does this help?
You must be using Chipmunk 5. You need to set the fields directly such as shape->e = 1.0.
The getter/setter functions are part of Chipmunk 6. You can still set the fields directly, but it's recommended not to as the setter functions will automatically wake up objects when changing values.