0

I have a SpriteKit animation where two bodies enter in contact at high speed. Unfortunatly if I use the didBeginContact Method, the two bodies are already overlapping a little when I stop the animation. I would like to stop the animation before the contact occurs, something like a willBeginContact method. Is there a way ? Thanks.

Lostania
  • 145
  • 8
  • Unfortunately, there is no `willBeginContact` method available. Your question is a bit unclear to me, but if you are talking about moving animation, you can make a physics body of a node, a bit bigger (so you will have a contact detected, but the sprites will not overlap). – Whirlwind Apr 06 '16 at 14:58
  • Also, `usesPreciseCollisionDetection = true` might be helpful when dealing with fast moving objects. – Whirlwind Apr 06 '16 at 15:04
  • didBeginContact happens before the drawing occurs, so you can move your sprites in this stage so that they are not overlapping – Knight0fDragon Apr 06 '16 at 18:38
  • @Whirlwind, not sure if making the physics body larger will help with fast moving objects, if a sprite moves 8 points a frame, but the padding of the body is only 3, an overlap will happen. Not sure if `usesPreciseCollisionDetection` will provide the data for the exact colision point – Knight0fDragon Apr 06 '16 at 18:42
  • @Knight0fDragon Correct. It will not help with insanely fast moving objects. I assumed that OP keeps speed at normal level (means, all contacts end up detected) and that overlapping is minimal. So in that case, I proposed using `usesPreciseCollisionDetection` as a last resort. – Whirlwind Apr 06 '16 at 18:51
  • Another thing is you can enable collision, this should not allow overlapping – Knight0fDragon Apr 06 '16 at 19:22
  • @KnightOfDragon I'm not sur enabling collision would change something. From one frame to the other the engine would assume a contact or a collision only when the two bodies overlap at least a little. The difference should be that the collision detection would move one of the bodies so that the overlapping is no more. I would like to prevent the overlap and stop the animation just before it occurs. Thanks again. – Lostania Apr 06 '16 at 20:43
  • @Whirlwind thank you for your comments and your help. – Lostania Apr 06 '16 at 20:44

0 Answers0