You need to implement the contact delegate correctly and set bitmasks on bodies for the contact notifications to fire up. To do that, put this beneath your imports:
typedef NS_OPTIONS(uint32_t, CNPhysicsCategory) {
CNPhysicsCategoryWheel = 1 << 0, // 0001 = 1
CNPhysicsCategoryGround = 1 << 1, // 0010 = 2
};
@interface YourSceneNameHere() <SKPhysicsContactDelegate>
@end
Then, as you initialize, add the scene as the contact delegate:
self.physicsWorld.contactDelegate = self;
Now, to apply those masks to your bodies - the category they are in, and what category of bodies they will be sending contact notifications for:
wheel.physicsBody.categoryBitMask = CNPhysicsCategoryWheel;
wheel.physicsBody.contactTestBitMask = CNPhysicsCategoryGround;
ground.physicsBody.categoryBitMask = CNPhysicsCategoryGround;
ground.physicsBody.contactTestBitMask = CNPhysicsCategoryWheel;
In the contact method, you have no control over which body is bodyA, and which bodyB:
- (void) didBeginContact:(SKPhysicsContact *)contact {
uint32_t contactTest = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask);
if (contactTest == (CNPhysicsCategoryWheel | CNPhysicsCategoryGround)) {
isWheelOnGround = YES;
}
}
Similarly for didEndContact
. Good luck!
For another example of this and a thorough explanation, refer to the 'Working with collisions and contacts' section of the SK Programming Guide.