Let me elaborate on the duffymo answer.
Remember that the CCLayer tick method contains the following codes ?:
int32 velocityIterations = 8; int32 positionIterations = 1; world->Step(dt, velocityIterations, positionIterations);
The two int32 variables tell box2D how many iterations (i.e., passes) should be used to apply forces, detect collisions, etc. According to the box2D manual , increasing these values ββimproves simulation accuracy due to performance, and vice versa, to reduce these values. Therefore, I suggest you adjust these values, especially positionIterations, until you are satisfied with the result.
EDIT:
Here is another suggestion. Remember once again that the tick method is called at the same speed as fps, which is no more than 60 per second? This means that the b2World::Step function performs discrete modeling at 1/60 second intervals, so a rapidly moving body can go through another body if it takes less than this time. Therefore, to solve this problem, you need to increase the frequency of discrete modeling, say, up to 180 steps per second. But the question is how? Cocos2D-iPhone calls the tick method for each frame, and increasing the frame rate (if possible) reduces performance and consumes all the computing power.
Here you can do this without changing the frame rate by calling the b2World::Step function a couple of times within the same checkmark:
int32 velocityIterations = 8; int32 positionIterations = 1; uint substeps = 3; float32 subdt = dt / substeps; for (uint i = 0; i < substeps; i++) { world->Step(subdt, velocityIterations, positionIterations);
source share