我是新來的物理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);
所以這些對象碰撞,它是太軟了。我能不能讓它看起來像兩塊石頭撞在一起?
我認爲我應該更新到V6然後。謝謝。 – McDermott
我通過設置玩家的速度('astroBody-> v = vector;')來碰撞玩家和物體。我認爲這可能是問題所在。 – McDermott
好的,我明白了。我現在使用cpBodyApplyForce(),現在它完美地工作。目標很難碰撞,就像我想要的一樣。直接設置速度太快了。 – McDermott