Ready to try out the catapult on the penguins?

You already know how to dynamically add a new penguin to the scene, this time when you add a new penguin you're going to pin joint it to the catapult arm and then release it when the player lets go of the catapult arm and watch physics in action. Let's add a new penguinJoint for this purpose.

Pinning the penguin

Add this property to your GameScene class:

var penguinJoint: SKPhysicsJointPin?

When the player touch begins, you want to spawn a penguin and pin it to the bucket area of the catapult arm.

Add this code to the touchesBegan(...) method immediately after the touchJoint code:

/* Add a new penguin to the scene */
let resourcePath = NSBundle.mainBundle().pathForResource("Penguin", ofType: "sks")
let penguin = MSReferenceNode(URL: NSURL (fileURLWithPath: resourcePath!))

/* Position penguin in the catapult bucket area */
penguin.avatar.position = catapultArm.position + CGPoint(x: 32, y: 50)

/* Improves physics collision handling of fast moving objects */
penguin.avatar.physicsBody?.usesPreciseCollisionDetection = true

/* Setup pin joint between penguin and catapult arm */
penguinJoint = SKPhysicsJointPin.jointWithBodyA(catapultArm.physicsBody!, bodyB: penguin.avatar.physicsBody!, anchor: penguin.avatar.position)

/* Set camera to follow penguin */
cameraTarget = penguin.avatar

Most of this should be fairly easy to understand for you by now. The code is very similar to the original beta launcher. The manual impulse has been removed and replaced with create a pin joint between the penguin and the catapult arm.

Let it go

Next you need to remove the penguinJoint once the player removes their touch.

[challenge] Can you remove the penguinJoint?

Add the following to thetouchesEnded(...) method:

if let penguinJoint = penguinJoint {

Run the game... You should be able to launch some penguins, good job!

Fine Tuning

It's very important that everything feels right for the player.

Tuning your physics simulation is very important, what might be realistic in the real world. May not be much fun in a game. You're aiming to get the balance just right and hit the sweet spot.

SpriteKit makes it very easy to change different physics properties, such as mass, friction, etc:

Have a play with your physics objects, sometimes the best results come from accidental changes.


Well done! You have the first fully playable prototype build.

You've learnt how to:

  • Launch a physics body indirectly using your catapult
  • Tweaking physics to improve the simulation

In the next chapter you will be working with physics contacts and collisions.


If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more

Cookies on Make School's website

We have placed cookies on your device to ensure that we give you the best experience on our website.

This site uses cookies to deliver our services. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Make School’s Products and Services is subject to these policies and terms.

Please note that Make School no longer supports Internet Explorer

We recommend upgrading to a modern web browser. Learn more