That is unless the bodies simply don't have enough room to move completely apart. But I wouldn't be surprised if two overlapping bodies that slowly move apart isn't actually possible in Sprite Kit. So the answer is: try different variations of parameters to see if you can get the desired behavior. It makes sense for Sprite Kit to try and avoid that behavior altogether, it's usually more problematic than helpful or desirable. 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. The "soft" way you describe can actually be very problematic for regular collision resolve. 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. In a rigid body physics engines such as Box2D, two overlapping bodies is something the physics engine strives to avoid. The Apple's SpriteKit is based on Box2d after all.Īctually 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). I wonder if there is a way to improve such behavior in SpriteKit, so it looks more like in Cocos2d + Box2d. Maybe the force applied to the bodies is so strong, that you can't see objects movement. 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). When one body strikes another body, Sprite Kit automatically computes the results of the collision and applies impulse to the bodies in the collision.īut it doesn't look like it happens as described. I read in Apple documentation:Ī collision is used to prevent two objects from interpenetrating each other. It looks pretty bad for the player, even the game runs 60 frames per second. There is no smooth movement of spires, they just being re-positioned in the way that they won't collide anymore. 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. However, on SpireKit things looks a little bit different. It looks pretty well, even if there is a lot of such collisions, the movement animations is smooth and FTP is high. Both sprites are gently moved in opposite directions until they don't collide anymore. In Cocos2d + Box2d in this situation collision is resolved smoothly. 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). All of those sprites have physics bodies that collides with each other. I am developing a game in which sprite nodes are dynamically added to the screen at random positions. I have a problem with the way SpriteKit resolves collisions between two bodies.
0 Comments
Leave a Reply. |