🎮 UIJoystick

What is it?

UIJoystick is a touch-based control designed for mobile games created with GameCrom. It allows the player to move a character or object using a virtual joystick composed of a base circle and a draggable knob. It works on Android, iOS, and also with mouse on PC for testing purposes.

📍 How to Add It

In the editor, click GameObjects → UIJoystick. A joystick will appear, and you can move, scale, and customize it from the inspector panel.

📖 Properties

🎯 Universal Event

Whenever the player moves the joystick, GameCrom automatically triggers the event:

function OnJoystickEvent(obj, vec)

This event is universal: any object with a script can implement it, just like OnTriggerEnter or OnCollisionEnter.

📦 Parameters

🧭 Basic Example: Moving a Top-Down Player

function Start(obj) {
    obj.speed = 150;
    obj.joyX = 0;
    obj.joyY = 0;

    // Dead zone (20%)
    obj.deadZone = 0.2;
}

function OnJoystickEvent(obj, vec) {
    obj.joyX = vec.x;
    obj.joyY = vec.y;
}

function Update(obj, dt) {
    const s = obj.speed;
    
    // Apply dead zone
    if (Math.abs(obj.joyX) < obj.deadZone) obj.joyX = 0;
    if (Math.abs(obj.joyY) < obj.deadZone) obj.joyY = 0;

    obj.x += obj.joyX * s * dt;
    obj.y += obj.joyY * s * dt;
}

📌 Notes

- Supports multitouch: joystick + UI buttons simultaneously.
- On PC, you can test it using the mouse as if it were a finger.
- The dead zone prevents unwanted micro-movements when the joystick returns to the center.
- Ideal for top-down games, 2D shooters, mobile platformers, RPGs, racing/vehicle controls, and more.