Creating a motor
A great feature of joints is that they can be turned into a motor. A joint can be given a rate of rotation that can be used to propel objects through the scene. This can be used to add objects that behave like vehicles in your game.
To demonstrate this, you will modify your catapult to drive into your structure instead of throwing objects at it. This can all be done within SpriteBuilder. Following are the steps:
Open up your project in SpriteBuilder and drag out a
CCColorNode
onto the scene.Make sure it is a child of the physics node. This will be the wheel for your catapult, so resize it appropriately.
Enable physics on the node. Change the physics shape to be a Circle, the density to
10.00
, and the friction to1.00
.Position your wheel node in roughly the position of the back wheel.
Drag out a Physics Pin Joint and pin the catapult to the back wheel. Your scene should now look like the following screenshot:
To turn the pivot joint into a motor is as simple as clicking a tick...