April 2021
Beginner to intermediate
506 pages
11h 57m
English
Switch back to the Player.swift file, and in the attack() method, above the line that reads var throwDirection = CGVector(dx: 0, dy: 0), add the following code:
| | // Set up physics for projectile |
| | let physicsBody = SKPhysicsBody(rectangleOf: projectile.size) |
| | |
| | physicsBody.affectedByGravity = false |
| | physicsBody.allowsRotation = true |
| | physicsBody.isDynamic = true |
| | |
| | physicsBody.categoryBitMask = PhysicsBody.projectile.categoryBitMask |
| | physicsBody.contactTestBitMask = PhysicsBody.projectile.contactTestBitMask |
| | physicsBody.collisionBitMask = PhysicsBody.projectile.collisionBitMask |
| | |
| | projectile.physicsBody = physicsBody |
This sets the projectile’s physics body to use the projectile category.
Next, ...
Read now
Unlock full access