Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity + Playmaker - EASY Pinball Game - Setting up Flipper

Mar 2, 2022
About this tutorial

In this mini Unity + Playmaker tutorial series, we will be taking a look at creating an EASY Pinball Game. In this second tutorial of the series, I will show the steps to setting up flipper and 3 different input types: mouse, keyboard, and mobile. ► Download the board graphics here: https://bit.ly

Written Guide

This pinball tutorial builds a reusable flipper you can drop into a board as a prefab, complete with a hinge that swings on input from three different sources: mouse, keyboard, and an on-screen button for mobile. The trick is using a hinge joint with limits and a motor, then driving it with torque through Playmaker so one prefab works everywhere you place it.

Assemble the flipper graphic

Inside the pinball board, add an empty named flipper left. Add the flipper sprite, set its sorting order to one, and scale it to about 0.5. Duplicate it slightly smaller and inset for a layered, colored look, then add a circle gradient at order three to mark the pivot. On the main flipper graphic, add a 2D polygon collider and edit its points to hug the shape.

Add the hinge and constrain its swing

Add a Hinge Joint 2D, which also adds a Rigidbody 2D. By default the hinge sits at the object's center, so enable Use Limits and set the upper angle to 0 and lower angle to negative 50 to bound the swing. Use Edit Anchor to drag the pivot onto the circle you placed, then rotate the flipper down slightly into its resting angle. With the lower limit holding it at the bottom, it stays put until forced.

Flip with torque in Playmaker

Add a Playmaker FSM that waits for input. In a Wait For Input state, add Get Mouse Button Down on the left button sending a flip event to a Flip Up state. The hinge already carries a motor with a max force of 10,000, so in Flip Up use Add Torque 2D on the flipper graphic with a value of 10,000 to drive it upward. Position the flipper so the ball drops onto it, and freeze the ball prefab's Z rotation so its radial-gradient graphic does not spin.

Support three input methods

Alongside the mouse, add Get Key Down on the left arrow firing the same flip transition. For mobile, add a UI canvas set to Scale With Screen Size at a 1920x1080 reference with Expand match mode, drop in a button using a bumper-triangle sprite, and wire its On Click Event to send flip. Now mouse, keyboard, and touch all work. Drag the flipper into the prefabs folder so you can stamp out as many as you like, each responding to all three inputs.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →