0
votes

I simply have put a square shape node onto a scene, and made the physicsBody for the scene be the edge of the screen. I turned on the physics view so you can see all of the physics stuff. The square has a physics body around it, as does the border of the scene. However, when the square runs into the border, nothing happens. The square just passes straight through. Here is how I initialize the square:

let rect1 = CGRect(x: 100, y: 100, width: 50, height: 50)
        let square = Square(rect: rect1)
        square.fillColor = UIColor.blackColor()
        square.zPosition = 200
        square.physicsBody = SKPhysicsBody(edgeLoopFromRect: rect1)
        square.physicsBody?.allowsRotation = false
        square.physicsBody?.affectedByGravity = false
        square.physicsBody?.restitution = 0.4
        self.addChild(square)

Here is how I initialize the physics body for the scene:

let physicsBody = SKPhysicsBody(edgeLoopFromRect: view.bounds)
self.physicsBody = physicsBody

Very similar code has worked for me on other games, so I am not sure why no collisions happen. Any help is greatly appreciated thanks!

1
Check that the collisionBitMask for each of the bodies is the same (and not 0). When you assign the scene's physicsBody try doing self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)user4233369
Thanks for the suggestions. However, neither worked. I printed the two collisionBitMask values and here is what they are: Optional(2) Optional(4294967295)Kendel
Are you moving the square with physics or SKActions or manually?user4233369
Oh thank you so much that is the issue! I was using a joystick and just setting it's position rather than using an impulse. I have changed it to an impulse and it now works fine. Thank you!Kendel

1 Answers

0
votes

The movement of the balls must be caused by physics rather than just setting the position. The issue was fixed through using impulses to move the balls which then made them collide with the various objects.