iosswiftsprite-kitgame-physicsskphysicsbody

Spritekit: Applying Angular Impulse to all surrounding node of exploding node


I am making a simple game in spritekit where the screen is full of balls with physics bodies. when the player taps a ball the ball explodes. I want to apply an angular impulse at the point of touch which will push all the surrounding balls away like a real world explosion. I tried fields but they are not really good as all the physics field nodes are forces not impulses. I checked all the impulse methods but they are only to apply force to the node itself. I also tried this:

self.physicsBody?.applyAngularImpulse(100)

and

self.physicsBody?.applyImpulse(impulse: CGVector, at: CGPoint)

thinking it would apply impulse to all child nodes in the scene (all the balls are child of the scene) but had no effect.

I thought this would be very simple but I am out of ideas.

appreciate your time. cheers


Solution

  • This approach is not a real-world explosion simulation but can help you as an idea.

    enter image description here

    I'm making actions like this on each touched node:

    node.run(SKAction.sequence([
        SKAction.fadeOut(withDuration: 0.0),
        SKAction.scale(to: 10, duration: 0.1),
        SKAction.removeFromParent()
    ]))
    

    You can get this example here: https://github.com/Maetschl/SpriteKitExamples/blob/master/BoxWithBalls/BoxWithBalls/GameScene.swift