In this project there are two players and both can shoot. When the opposite players bullets hits a ship, it lowers their health and disappears, this works fine. The problem is I don't want either the ships or the bullets to react to colliding into each other.
Here is the code for making the first player:
player = [SKSpriteNode spriteNodeWithImageNamed:filePath];
player.size = CGSizeMake(100, 100);
player.position = CGPointMake(150, 250);
player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:player.size];
player.physicsBody.categoryBitMask = playerCategory;
player.physicsBody.collisionBitMask = wallCategory;
player.physicsBody.friction = 1.0f;
player.physicsBody.restitution = 1.0f;
player.physicsBody.linearDamping = 1.0f;
player.physicsBody.allowsRotation = NO;
[self addChild:player];
And second player:
playerTwo = [SKSpriteNode spriteNodeWithImageNamed:filePath];
playerTwo.size = CGSizeMake(100, 100);
playerTwo.position = CGPointMake((384*2)-150, (512*2)-250);
playerTwo.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:playerTwo.size];
playerTwo.physicsBody.categoryBitMask = playerTwoCategory;
playerTwo.physicsBody.collisionBitMask = wallCategory;
playerTwo.physicsBody.friction = 1.0f;
playerTwo.physicsBody.restitution = 1.0f;
playerTwo.physicsBody.linearDamping = 1.0f;
playerTwo.physicsBody.allowsRotation = NO;
[self addChild:playerTwo];
the initializing of the categories:
static const uint32_t playerCategory = 2;
static const uint32_t playerTwoCategory = 5;
static const uint32_t wallCategory = 1;
static const uint32_t bulletCategory = 4;
static const uint32_t bulletTwoCategory = 7;
The bullet making for player one:
SKSpriteNode * bullet = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(5, 5)];
bullet.position = [gunOne convertPoint:CGPointMake(0,0) toNode:self];
[self addChild:bullet];
bullet.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:bullet.frame.size];
bullet.physicsBody.categoryBitMask = bulletCategory;
bullet.physicsBody.dynamic = YES;
bullet.physicsBody.contactTestBitMask = playerTwoCategory | wallCategory;
bullet.physicsBody.collisionBitMask = wallCategory;
bullet.physicsBody.usesPreciseCollisionDetection = YES;
The bullet making for player two:
SKSpriteNode * bulletTwo = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(5, 5)];
bulletTwo.position = [gunOneTwo convertPoint:CGPointMake(0,0) toNode:self];
[self addChild:bulletTwo];
bulletTwo.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:bulletTwo.frame.size];
bulletTwo.physicsBody.categoryBitMask = bulletTwoCategory;
bulletTwo.physicsBody.dynamic = YES;
bulletTwo.physicsBody.contactTestBitMask = playerCategory | wallCategory;
bulletTwo.physicsBody.collisionBitMask = wallCategory;
bulletTwo.physicsBody.usesPreciseCollisionDetection = YES;
Is there any visible problem with the way this is done that would cause JUST the first player and the bullets react to collisions? Thanks in advance for the help, and sorry for the long read.