February 2017
Beginner to intermediate
258 pages
5h 31m
English
You may have noticed that we positioned bee2 and bee3 at the same height in the game world. We only need to push one of them horizontally to create a collision-perfect crash test dummies! We can use an impulse to create velocity for the outside bee.
Locate the didMove function in GameScene.swift. At the bottom, preceding all of our spawn code, add this line:
bee2.physicsBody?.applyImpulse(CGVector(dx: -3, dy: 0))
Run the project. You will see the outermost bee fly toward the middle and crash into the inner bee. This pushes the inner bee to the left and slows the first bee from the contact.
Attempt the same experiment with a variable: Increased mass. Before the impulse line, add this code to adjust the mass of bee2:
bee2.physicsBody?.mass ...
Read now
Unlock full access