Provides an advanced virtual joystick compatible with Unity Input System/uGUI.
Enhanced On-Screen Stick is a library that provides a highly functional virtual stick compatible with Unity's Input System. It simulates joystick input on touch devices such as mobile using Unity's Input System On-screen Controls. It also allows advanced customization such as touch position tracking, dead zones, and adjustable operational areas.
- Unity 2020.1 or later
- Input System 1.0.0 or later
- Open the Package Manager from Window > Package Manager.
- Click the "+" button > Add package from git URL.
- Enter the following URL:
https://github.com/AnnulusGames/EnhancedOnScreenStick.git?path=Assets/EnhancedOnScreenStick
Alternatively, open Packages/manifest.json and add the following to the dependencies block:
{
"dependencies": {
"com.annulusgames.enhanced-on-screen-stick": "https://github.com/AnnulusGames/EnhancedOnScreenStick.git?path=Assets/EnhancedOnScreenStick"
}
}
By integrating Enhanced On-Screen Stick, you can create a virtual stick from Create > Enhanced On-Screen Controls > On-Screen Stick
.
Once created, place it on the Canvas and adjust its size and appearance. The RectTransform range of the object with the attached components will become the operable area.
Next, set the Control Path from the Inspector. This allows you to simulate input from any device.
Setup is now complete. You can process input using the Input System as usual. Below is a sample of using Enhanced On-Screen Stick and InputAction for movement processing.
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
[SerializeField] InputAction inputAction;
[SerializeField] float movementSpeed = 5f;
void Start()
{
inputAction.Enable();
}
void Update()
{
transform.position += movementSpeed * Time.deltaTime * (Vector3)inputAction.ReadValue<Vector2>();
}
}
Enhanced On-Screen Stick
consists of the following objects:
- Enhanced On-Screen Stick
- Background
- Handle
Attach the Enhanced On-Screen Stick
component to the top-level object and attach some kind of Graphic component (such as Image) so that touch events can be detected. The RectTransform of this object will become the operable area for the stick.
Background and Handle are objects for visually representing the position of the stick. You can freely change their size and appearance, but Handle must be a child of Background.
StickType allows you to change the behavior when the stick is manipulated.
StickType | Description |
---|---|
Fixed | The stick is always fixed to its initial position. |
Floating | The stick moves to the touched position and remains fixed there until the drag ends. |
Dynamic | The stick moves to the touched position and follows the drag movement. |
Property | Description |
---|---|
Movement Range | Specifies the distance from the center of the Handle for movement. |
Dead Zone | Sets the threshold for input from 0 to 1. Input values below the Dead Zone are corrected to 0. |
Show Only When Pressed | If true, Background and Handle are inactive when not touched. |