Using a Fixed Joint to Stick the Ball to the Plunger

Physics bodies don’t just have to drift around on their own. They can also be joined together in a variety of ways. Here, we’re going to change our RCWPlungerNode so that it joins the ball to the top of the plunger when the touch begins. That joint will hold the ball in place no matter how fast the plunger moves. When the action runs to snap the plunger back in place, we will break the joint and then launch the ball by manually applying a force to it, depending on how far the player pulled down the plunger.

First, we need to change our method declarations in RCWPlungerNode.h. The plunger needs to know more details to do its new job. We have to pass it the ball and the physics world.

06-Physics/step11/PhysicsBall/RCWPlungerNode.h ...

Get Build iOS Games with Sprite Kit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.