0

So I have this code inside my GameScene class (child of SKScene):

physicsWorld.contactDelegate = self
physicsWorld.gravity = CGVector(dx: 0, dy: -9.8)
addChild(balloon)
addChild(monkey)
monkey.physicsBody = SKPhysicsBody(rectangleOf: monkey.frame.size)
monkey.physicsBody?.isDynamic = false
monkey.physicsBody?.categoryBitMask = 0
monkey.physicsBody?.contactTestBitMask = 1//Balloon.categoryBitMask

balloon.physicsBody = SKPhysicsBody(rectangleOf: balloon.frame.size)
balloon.physicsBody?.isDynamic = false
balloon.physicsBody?.categoryBitMask = 1
balloon.physicsBody?.contactTestBitMask = 0
balloon.start()

I can see that the balloon and the monkey node have touched each other in the simulator, however, nothing happens. I have also conformed to the SKPhysicsContactDelegate protocol, like so:

extension GameScene: SKPhysicsContactDelegate {
    func didBegin(_ contact: SKPhysicsContact) {
        print("CONTACT!!!")
    }
}

Edit: I set isDynamic = true and it printed "CONTACT!!" as expected, however I dont want the objects to be affecting each other's position

James P
  • 4,786
  • 2
  • 35
  • 52
Arjun
  • 358
  • 5
  • 14
  • So what do you want then? Only the balloon to move, and then it hits the monkey (without moving the monkey)? Or the monkey getting the balloon? Please explain more. – George Mar 05 '19 at 23:37
  • @George_E i want the didBegin function to be called on contact, without setting any to dynamic – Arjun Mar 05 '19 at 23:39
  • But _why_ do you not want to set the objects to dynamic? What's the problem if they are `dynamic`? – George Mar 05 '19 at 23:40
  • @George_E i don’t want my objects moving on collision, right now once they collide the move other ways automatically – Arjun Mar 06 '19 at 01:16

0 Answers0