I have a problem with the way SpriteKit resolves collisions between two bodies. I am developing a game in which sprite nodes are dynamically added to the screen at random positions. All of those sprites have physics bodies that collides with each other. On higher game levels there are a lot of those sprites and sometimes new sprite it added on top of another one (which is correct behavior as long as collision is resolved smoothly). In Cocos2d + Box2d in this situation collision is resolved smoothly. Both sprites are gently moved in opposite directions until they don't collide anymore. It looks pretty well, even if there is a lot of such collisions, the movement animations is smooth and FTP is high. However, on SpireKit things looks a little bit different. When new body is added on top of another one, from user point of view it's not moved to resolve collision - it's "teleported" instead. There is no smooth movement of spires, they just being re-positioned in the way that they won't collide anymore. It looks pretty bad for the player, even the game runs 60 frames per second. I read in Apple documentation:
A collision is used to prevent two objects from interpenetrating each other. When one body strikes another body, Sprite Kit automatically computes the results of the collision and applies impulse to the bodies in the collision.
But it doesn't look like it happens as described. Apple tells me that when collision occurs there will be an impulse applied to the bodies that collides with each other, but in real life it looks like the bodies are "teleported" (instantly moved in the place that doesn't trigger collision anymore). Maybe the force applied to the bodies is so strong, that you can't see objects movement. I wonder if there is a way to improve such behavior in SpriteKit, so it looks more like in Cocos2d + Box2d. The Apple's SpriteKit is based on Box2d after all.
Actually overlapping bodies is not a behavior physics engines try to model or have incorporated into their design as a feature - the observed behavior is merely a side-effect, and possibly heavily influenced by the body's parameters (definitely by "bullet" or "continuous" collision detection,
usesPreciseCollisionDetection
in Sprite Kit terms).In a rigid body physics engines such as Box2D, two overlapping bodies is something the physics engine strives to avoid. The speed at which it does so - iteratively over several frames or (near) instantaneous - could be specific property of the physics engine respetively the settings with which it is initialized internally.
The "soft" way you describe can actually be very problematic for regular collision resolve. Especially if bodies are designed to be rigid, ie a player body must not penetrate a wall or the floor even just a little bit. It makes sense for Sprite Kit to try and avoid that behavior altogether, it's usually more problematic than helpful or desirable.
So the answer is: try different variations of parameters to see if you can get the desired behavior. But I wouldn't be surprised if two overlapping bodies that slowly move apart isn't actually possible in Sprite Kit. That is unless the bodies simply don't have enough room to move completely apart.