1
votes

I am trying to make a game about balls and using sprite kit with physics body for IOS 7. My problem is about resting objects when contact / collide. Here is my code in didBeginContact:

[contact.bodyA setVelocity:CGVectorMake(0, 0)];
[contact.bodyB setVelocity:CGVectorMake(0, 0)];
contact.bodyA.resting = YES;
contact.bodyB.resting = YES;

Actually contact.bodyA is already resting but I just set it to make sure both objects are set to resting. The problem is, balls are not touching to each other even if I set contact.bodyA(or B).resting = YES.

This is what I want:

http://i.stack.imgur.com/p8JTk.png

This is what happening sometimes:

http://i.stack.imgur.com/LWORO.png

As you can see in second picture, the blue ball is a bit far from other balls. Is there any other way to magnet the ball at contact point always?

1

1 Answers

0
votes

This could potentially be a problem with the physics body. I'm assuming you're using [SKPhysicsBody bodyWithCircleOfRadius:spriteWidth/2]. Are you certain your sprite image is the correct size and matches w/ the radius you're feeding the physics body constructor?

Perhaps you could store the position of the object in a property prevPosition, and when a collision is detected, return the position of the sprite node to prevPosition and set the body to resting?
`