花栗鼠碰撞太软了

时间:2012-05-04 16:34:18

标签: c++ cocos2d-iphone physics chipmunk cocos2d-x

我是cocos2d的物理新手。我正在使用花栗鼠,当两个物体碰撞时,它只是“柔软”,就像它们用海绵或橡胶制成的那样。

我的代码:

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);

所以这些物体碰撞,太软了。我能以某种方式让它看起来像两块石头相互撞击吗?

2 个答案:

答案 0 :(得分:2)

您必须使用Chipmunk 5.您需要直接设置字段,例如shape-> e = 1.0。

getter / setter函数是Chipmunk 6的一部分。您仍然可以直接设置字段,但建议不要因为setter函数在更改值时会自动唤醒对象。

答案 1 :(得分:1)

来自文档:

void cpShapeSetElasticity(cpShape *shape, cpFloat value)

  

形状的弹性。值0.0不给出反弹,而是值   1.0将给出一个“完美”的反弹。但由于不准确   但是,不推荐使用1.0或更高版本的模拟。该   通过乘以弹性来找到碰撞的弹性   个人塑造在一起。

这有帮助吗?