花栗鼠碰撞太软了 [英] chipmunk collision too soft

查看:27
本文介绍了花栗鼠碰撞太软了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我的代码:

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?

推荐答案

你一定是使用Chipmunk 5,需要直接设置shape->e = 1.0等字段.

You must be using Chipmunk 5. You need to set the fields directly such as shape->e = 1.0.

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

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.

这篇关于花栗鼠碰撞太软了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆