I was wondering if anyone would be able to offer me some help with using 3 nodes, I understand if I just have 2 nodes E.g. body A and body B but I'm struggling with adding a third body, I hoped it was as simple as body C but that wasn't the case. This is the related code below:
struct CollisionCategoryBitmask {
static let Player: UInt32 = 0x00
static let Enemy1: UInt32 = 0x01
static let Enemy2: UInt32 = 0x02
}
func didBeginContact(contact: SKPhysicsContact) {
var updateHud = false
_ = (contact.bodyA.node != player) ? contact.bodyA.node : contact.bodyB.node
updateHud = slowDown(player)
}
This function below is intended to slow the player down when contacting Enemy1
func slowDown (player: SKNode) -> Bool {
player.physicsBody?.velocity = CGVector(dx: 0, dy: -50.0)
return true
}
and this below is intended to get the game to end when contacting Enemy2
func endGame (player: SKNode) -> Bool {
endOfGame()
return true
}
At the moment both functions work, but only one at a time, so when the player contacts either Enemy 1 or 2. I can currently either get the player to slow down or get the game to end by just changing the updateHud = slowDown(player) line. So how can I adjust the code to have the two different outcomes happen when the player touches either Enemy 1 or 2.
Thanks
static let Player: UInt32 = 0x00
is not valid, you are saying player collides with nobody. The way bit mask works is you have 32 "Switches" (or flags) and you turn each switch on or off. If player has switch 1 turned on, then the enemy should look for all players that have switch 1 turned on, and if the enemy finds it, they say they have a collision – Knight0fDragon