Hi to Everyone,
I am planning to use Box2D in my game development on iPhone/iPod. Honestly speaking I am not a game developer and I am doing it first time and just for fun. For now in my first game all I need from physics engine is some basic collision support with absolute restitution (=1) with no elasticity and no friction. Moving objects, which are cocos2d sprites described in terms of convexes or circles for Box2D, should fly on the scene collide and bounce off each other as well as from the edges of the screen.
Following Box2D documentation and examples I have described each of the screen edges as a static body with attached polygon-edge (SetAsEdge) based fixture (and of course I set restitution to 1). I have also created a few dynamic bodies (associated with cocos2d sprites) with attached polygon-square (SetAsBox) based fixture (and again restitution set to 1). I gave each of the dynamic bodies some linear velocity and let the simulation run. As a matter of fact the first simulation runs very well. There is only one problem I noticed and it is when sometimes my objects (square cocos2d sprites) temporarily overlap during the collision, and I am not talking about barely visible (one or two pixels) overlapping - its is about very well visible deep overlapping. To hunt down the issue I left only two dynamic objects on the scene and even set first one to be motionless by giving it (0,0) linear velocity (angular velocity was always set to 0 at the beginning of simulation by b2BodyDef constructor).
My first suspect was cocos2d rendering, I thought it may render not precisely rotated square sprites. So, I’ve added ContactListener and I’ve set a breakpoint at BeginContact method. Since BeginContact provides pointer on contact object which has pointers on both colliding fixtures (with all their shape/vertex info) and each fixture in turn has a pointer on related body (with all its position and rotation info) I could manually calculate the absolute position of each vertex of both shapes. And as a matter of fact the results of my calculations showed that these two dynamic objects actually significantly overlap and that cocos2d rendering correctly reflects positional and rotational data supplied by Box2D engine.
Can anyone tell me what I did wrong?
I played with scaling coefficient from my data model to Box2D’s one, I played with b2_linearSlop and b2_angularSlop and some other settings, but with no success.
Thank you,
martsipon
I am planning to use Box2D in my game development on iPhone/iPod. Honestly speaking I am not a game developer and I am doing it first time and just for fun. For now in my first game all I need from physics engine is some basic collision support with absolute restitution (=1) with no elasticity and no friction. Moving objects, which are cocos2d sprites described in terms of convexes or circles for Box2D, should fly on the scene collide and bounce off each other as well as from the edges of the screen.
Following Box2D documentation and examples I have described each of the screen edges as a static body with attached polygon-edge (SetAsEdge) based fixture (and of course I set restitution to 1). I have also created a few dynamic bodies (associated with cocos2d sprites) with attached polygon-square (SetAsBox) based fixture (and again restitution set to 1). I gave each of the dynamic bodies some linear velocity and let the simulation run. As a matter of fact the first simulation runs very well. There is only one problem I noticed and it is when sometimes my objects (square cocos2d sprites) temporarily overlap during the collision, and I am not talking about barely visible (one or two pixels) overlapping - its is about very well visible deep overlapping. To hunt down the issue I left only two dynamic objects on the scene and even set first one to be motionless by giving it (0,0) linear velocity (angular velocity was always set to 0 at the beginning of simulation by b2BodyDef constructor).
My first suspect was cocos2d rendering, I thought it may render not precisely rotated square sprites. So, I’ve added ContactListener and I’ve set a breakpoint at BeginContact method. Since BeginContact provides pointer on contact object which has pointers on both colliding fixtures (with all their shape/vertex info) and each fixture in turn has a pointer on related body (with all its position and rotation info) I could manually calculate the absolute position of each vertex of both shapes. And as a matter of fact the results of my calculations showed that these two dynamic objects actually significantly overlap and that cocos2d rendering correctly reflects positional and rotational data supplied by Box2D engine.
Can anyone tell me what I did wrong?
I played with scaling coefficient from my data model to Box2D’s one, I played with b2_linearSlop and b2_angularSlop and some other settings, but with no success.
Thank you,
martsipon