âš¡Getting Started

Let's take a look at the Ultimate Joystick and see how to get it working in your project as quick as possible!

Please take just a moment to view the introduction video for the Ultimate Joystick if you have not done so already.

INTRODUCTION VIDEO COMING SOON!

The Ultimate Joystick is designed to be as simple and easy to use as possible. You will only need a few lines of code in order to get the Ultimate Joystick working inside your project.

To begin we'll look at how to simply create an Ultimate Joystick in your scene. After that we will go over how to reference the Ultimate Joystick in your custom scripts. Let's begin!

How to Create

To create an Ultimate Joystick in your scene, simply find the Ultimate Joystick prefab that you would like to add and drag the prefab into your scene. It should automatically set itself as a child of a UI Canvas, or create one if necessary.

Prefabs can be found at: Assets/Tank & Healer Studio/Ultimate Joystick/Prefabs

How to Reference

One of the great things about the Ultimate Joystick is how easy it is to reference to other scripts. The first thing that you will want to make sure to do is to name the joystick in the Script Reference section. After this is complete, you will be able to reference that particular joystick by the name that you have assigned to it.

After the joystick has been given a name in the Script Reference section, we can get that joystick's position by catching the Horizontal and Vertical values at run time and storing the results from the static functions: GetHorizontalAxis and GetVerticalAxis. These functions will return the joystick's position, and will be float values between -1, and 1, with 0 being at the center. For more information about these functions, and others that are available to the Ultimate Joystick class, please see the Documentation section of this window.

New Input System: In order to reference the Ultimate Joystick with the new Input System from Unity, simply go to the Script Reference section of the Ultimate Joystick in your scene and set the Control Path variable to the desired path.

For a full list of the functions available, please see the Documention section.

Simple Example

Let's assume that we want to use a joystick for a characters movement. The first thing to do is to assign the name "Movement" in the Joystick Name variable located in the Script Reference section of the Ultimate Joystick.

After that, we need to create two float variables to store the result of the joystick's position. In order to get the "Movement" joystick's position, we need to pass in the name "Movement" as the argument.

float h = UltimateJoystick.GetHorizontalAxis( \"Movement\" );
float v = UltimateJoystick.GetVerticalAxis( \"Movement\" );

The h and v variables now contain the values of the Movement joystick's position. Now we can use this information in any way that is desired. For example, if you are wanting to put the joystick's position into a character movement script, you would create a Vector3 variable for movement direction, and put in the appropriate values of this joystick's position.

Vector3 movementDirection = new Vector3( h, 0, v );

In the above example, the h variable is used to in the X slot of the Vector3, and the v variable is in the Z slot. This is because you generally don't want your character to move in the Y direction unless the user jumps. That is why we put the v variable into the Z value of the movementDirection variable.

Understanding how to use the values from any input is important when creating character controllers, so experiment with the values and try to understand how user input can be used in different ways.

Last updated