Based on what I am understanding, You want an object to go through an object some of the time.
The following code should work:
enum CategoryBitMasks{
case player1Collidable = 1 << 0
case player2Collidable = 1 << 1
case player1 = 1 << 2
case player2 = 1 << 3
case oneTimePass = 1 << 4
case unstoppable = 1 << 5
case player = CategoryBitMasks.player1 | CategoryBitMasks.player2
case playerCollidable = CategoryBitMasks.player1Collidable | CategoryBitMasks.player2Collidable
}
//Create an obstacle with category (.player1Collidable | .player2Collidable)
// with contact 0
// with collision 0
//Create a player with category (.player1 | .unstoppable)
// with contact .player1Collidable
// with collision .player1Collidable
func didBeginContact(contact: SKPhysicsContact) {
var obstacle = contact.bodyA.categoryBitMask >= contact.bodyB.categoryBitMask ?contact.bodyA, contact.bodyB
var player = contact.bodyB == obstacle ? contact.bodyA, contact.bodyB
//Only allows the player to pass through 1 object
if player.categoryBitMask || CategoryBitMasks.oneTimePass && obstacle.categoryBitMask || CategoryBitMasks.playerCollidable {
obstacle.categoryBitMask &= ~(player.collisionBitMask & CategoryBitMasks.playerCollidable) //turns player1Collidable off
player.categoryBitMask &= ~(player.categoryBitMask & CategoryBitMasks.oneTimePass) //turns oneTimePass off
}
//Allows player to pass through all objects
if player.categoryBitMask || CategoryBitMasks.unstoppable && obstacle.categoryBitMask || CategoryBitMasks.playerCollidable {
//This will bypass all objects providing their collision is not set to the player
player.collisionBitMask &= ~(player.collisionBitMask & CategoryBitMasks.playerCollidable) //turns player1Collidable off
//This will bypass all objects, but is dangerous because the category is now changed, meaning if a contact does happen, .player can't be used
//player.categoryBitMask &= ~(player.categoryBitMask & CategoryBitMasks.player ) //turns player1Collidable off
}
}
Remember to reset the masks when needed
This will allow player 1 to go through objects depending on category you gave it, while forcing player 2 to still be obstructed by the same object.
Hopefully these examples will help you tweak the needs of your game.