Reputation: 11
I am making a game where I have a ball created as an SKSpriteNode that is colliding with some PhysicsBodies I do not want to. Here is my ball:
orangeBall = OrangeBall(path: ballTrajectory, color: UIColor.orange, borderColor: UIColor.black)
orangeBall.physicsBody = SKPhysicsBody(circleOfRadius: Physics.PhysicsNumbers.ballRadius)
orangeBall.position = Physics.PhysicsNumbers.ballRestPos
orangeBall.physicsBody?.categoryBitMask = CollisionsChecker.Ball
orangeBall.physicsBody?.collisionBitMask = CollisionsChecker.Frame | CollisionsChecker.Box | CollisionsChecker.Score
orangeBall.physicsBody?.contactTestBitMask = CollisionsChecker.Frame | CollisionsChecker.Box | CollisionsChecker.Score
orangeBall.physicsBody?.isDynamic = false
orangeBall.physicsBody?.affectedByGravity = false
addChild(orangeBall)
and I want it to detect that it has been in contact with this score physics body but not actually collide:
score = NetBoxes(path: scoreStationary, color: UIColor.red, borderColor: UIColor.red)
score.position = Physics.PhysicsNumbers.scoreRest
score.physicsBody = SKPhysicsBody(circleOfRadius: 50)
score.physicsBody?.categoryBitMask = CollisionsChecker.Score
score.physicsBody?.contactTestBitMask = 0
score.physicsBody?.collisionBitMask = CollisionsChecker.Ball
score.physicsBody?.affectedByGravity = false
score.physicsBody?.isDynamic = false
addChild(score)
(circleOfRadius is only for testing purposes) Every time I try to check my collisions it seems to not output what I want it to do:
func didBegin(_ contact: SKPhysicsContact){
let firstBody = contact.bodyA
let secondBody = contact.bodyB
if firstBody.categoryBitMask == CollisionsChecker.Ball && secondBody.categoryBitMask == CollisionsChecker.Score || firstBody.categoryBitMask == CollisionsChecker.Score && secondBody.categoryBitMask == CollisionsChecker.Ball{
print("Ball in hoop")
}
Essentially, my orangeBall which is a SKSphapeNode always collide with my Score PhysicsBody. It might also be that both physics bodies around my ball and score get into contact. I am at a loss, any help would be appreciated!
Upvotes: 0
Views: 37
Reputation: 11
I have figured it out. I was recreating a physicsBody for my orangeBall later in the code. Forming another physicsBody around it making it collide with my other nodes!
Upvotes: 1