1
votes

I wrote few simple SpriteKit games and always had problems with strong collisions behaviour. Even now with my latest game in development the same issue appears quite randomly.

  • Game-play area is inside edgeLoopFromRect physics body
  • There are some objects (with circle physics body) bouncing around

But sometimes (this happens very rarely) when a strong collision (edge <- body1 <- body2) happens directly near the edgeLoopFromRect physics body, sometimes colliding-object (body1) jumps out. I am totally confused how to debug this kind of behaviour.

EDIT: I have recorded a video of what exactly happens:

Physics engine collapses

For the demo I have made impulse strength (the biggest blue ball) on purpose 10-times stronger, so the effect can be seen sooner. Look what happens after 10-15 seconds. Physics totally collapses. This can be seen by background totally going off and balls fly into the unknown.

Note: everything I do in this demo is applying impulse on the blue ball.

1

1 Answers

0
votes

You need to enable usesPreciseCollisionDetection. This will force SpriteKit to calculate the physics positions of the entire movement, which will now prevent it from popping out. Code for this would look like this in Objective-C:

self.body1.physicsBody.usesPreciseCollisionDetection = YES;

And in Swift:

body1.physicsBody?.usesPreciseCollisionDetection = true

This will have a performance impact, but will prevent your glitch from happening. You will probably have to do this for all of the circular physics bodies that you have moving around.