I'm going through a tutorial/class making a game in Sprite Kit and I'm having issues with multiple collisions happening at the same time.
I'm implementing the didBeginContact: method for all collisions which make the ball bounce because there seems to be a known issue where objects may "stick" to a body if the velocity is too low and angle is too narrow.
By making _ball.physicsBody.collisionBitMask = 0;
and putting the below line in the didBeginContact
if(other body == firstbody && _ball == secondbody)
secondBody.velocity = (CGVectorMake(secondBody.velocity.dx * -1.0, secondBody.velocity.dy));
(or dy * -1.0 for vertical collisions)
I can make the object bounce naturally and it works.
The issue I'm having is when there multiple contacts are called on the _ball. If 1 collision makes the _ball reverse its direction and it hits another object of the same type which reverses direction again, the _ball will continue moving in it's original direction (Double Negative). The _ball just moves through these objects. I can make it bounce back if I secondBody.categoryBitMask = 0; but i then i have the issue of returning the _ball to it's original category.
Does anyone know if you an cycle through contacts or stop contacts on a body after it processes a contact once?
Any thoughts?