Unity — ControlFreak2 Swipe Controls

Just putting a note here because I kept forgetting how to setup swipe controls using ControlFreak2. It’s a really good mobile (and desktop) controls library for Unity, but if you forget how to use it, it won’t exactly be a smooth ride to re-learn its over-complex looking settings.

Key bindings

To start, right click in Hierarchy and select Control Freak 2 > Total Package (Event System + Rig + Gamepad Manager).

Next, in Hierarchy, navigate to the GameObject named “CF2-Rig”, expand it and its subsequent child until you reach “CF2-Panel”.

You should a control panel like this in the Inspector:

Select “Add Touch Zone” to add a touch control, and another editor window will popup for you to adjust its settings:

In the “CF2 Touch Zone Wizard” editor, start by selecting a Region, which is an option for you choose which part of the screen will the swipe controls cover.

You can choose to give it a new name, I always put in “Swipe Controls”.

Then click “Create And Select” to create the touch control and select it in the Unity Editor.

In the Inspector, you should see a different panel titled: “Super Touch Zone”.

Expand “Touch Zone Bindings” and check “Single finger Touch Binding” to true.

Under “Swipe bindings”, check “Swipe Segment’s Direction (Normal Press)” to true.

Now, under “Swipe Segment’s Direction (Normal Press)”, you should be able to bind the swiping to keyboard controls.

As you can see in the example below, I bind “Up” swipe to UpArrow and W key, “Right” swipe to RightArrow and D key.

Using it in script

To use it in script, start by importing it using:

using ControlFreak2;

Then, in your control function, just use it like you would with Unity’s Input, except with ControlFreak2’s input:

if ( CF2Input.GetKeyDown ( KeyCode.UpArrow ) 
|| CF2Input.GetKeyDown ( KeyCode.W ) ) {
// Move up
}
if ( CF2Input.GetKeyDown ( KeyCode.DownArrow )
|| CF2Input.GetKeyDown ( KeyCode.S ) ) {
// Move down
}
if ( CF2Input.GetKeyDown ( KeyCode.LeftArrow )
|| CF2Input.GetKeyDown ( KeyCode.A ) ) {
// Move left
}
if ( CF2Input.GetKeyDown ( KeyCode.RightArrow )
|| CF2Input.GetKeyDown ( KeyCode.D ) ) {
// Move right
}

Software developer, web/mobile dev evangelist. Enthusiast of: NodeJS, React, Redux, Flutter, Unity, Golang, Django, etc.