user5127227
user5127227

Reputation:

detect contact when both physics bodies are dynamic sprite kit objective c

is it possible to detect a contact and let the object pass the other ? Because I want to increase a variable when they pass each other.

I made both phyisicsbodies dynamic, then they pass but didBeginContact is not working anymore then.

Thanks

EDIT:

Okay , so everything is working when I don't have the bodies dynamic. I have a BottomEdgeBody which I use to detect when the raining stones passed my player and then it increases the Score. So, if nothing is dynamic, my stones stay on top of the bottomEdge but I want them to fall through it.

Some Code:

in didBeginContact

if(contact.bodyA.categoryBitMask == bottomEdgeCategory)
{
    self.scoring = self.scoring +1;
    [self.scoreLabel setText:[NSString stringWithFormat:@"Score: %ld", (long)self.scoring]];
}
if(contact.bodyB.categoryBitMask == bottomEdgeCategory)
{
    self.scoring = self.scoring +1;
    [self.scoreLabel setText:[NSString stringWithFormat:@"Score: %ld", (long)self.scoring]];

}

If i make stone.physicsBody.dynamic = NO; and same for the bottomEdge, they pass themselves but the score is not increased anymore.

Upvotes: 0

Views: 133

Answers (1)

user5127227
user5127227

Reputation:

Okay thank you, I just settled the collision Bit mask of the Stone and the BottomEdge to 0, then it is working properly

Upvotes: 1

Related Questions