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.
In the editor, click GameObjects → UIJoystick. A joystick will appear, and you can move, scale, and customize it from the inspector panel.
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.
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;
}