Hi,
I'm currently working on my first game with both cocos2d and chipmunk, i've found cocos2d to be brilliant, great community too!
I'm just having some trouble with chipmunk and making shapes which aren't effected by forces of other objects, including gravity, but can have a velocity ect. (in my mind static objects), and also normal objects which are effected by everything.
Here is my method for setting up the physics for a sprite:
-(void)setUpCharacterPhysics:(Sprite *)character staticObject:(BOOL)staticObject{
cpBody * body = NULL;
if(staticObject){
body = cpBodyNew(INFINITY, INFINITY);
}else{
body = cpBodyNew(200.0f, INFINITY);
}
body->p = cpv(100, 100);
body->v = cpv(0, 0);
cpShape * shape = cpPolyShapeNew(body, 4, [character getVerts], cpvzero);
shape->e = 1.0f; shape->u = 1.0f;
shape->data = character;
shape->collision_type = 0; //COLLISION DATA
cpSpaceAddBody(space, body);
if(staticObject){
cpSpaceAddStaticShape(space, shape);
}else{
cpSpaceAddShape(space, shape);
}
}
Basically, when gravity is present, and I tell the method i want my sprite to be static, the object is effected by gravity, and so are the segments preventing objects from floating off the screen, whereas when there is not gravity, every object is what i would call static.
Can someone please show me where i'm going wrong, or tell me the proper way to initiate static/normal sprites!
Thanks so much!