API

Virtual Joysticks

VirtualJoystick

Create virtual joysticks for the left and right sides of the screen.

import { VirtualJoystick } from "@babylonjs/core/Misc/virtualJoystick";
const leftJoystick = new VirtualJoystick(true);
const rightJoystick = new VirtualJoystick(false);

Get the joystick value.

leftJoystick.deltaPosition.x;
leftJoystick.deltaPosition.y;
VirtualJoystick Example

Note: This will create an overlay canvas on top of the scene canvas. This disables interaction with Babylon GUI elements and scene pointer events. To avoid this, the overlay joystick canvas's z-index can be modified to toggle between scene interaction and joystick input, as shown in the playground above. Another option is to create a custom joystick using Babylon GUI, as described below.

Custom joystick

To create a custom virtual joystick and modify it to suit specific use cases, the Babylon GUI can be used.

Custom Joystick Example

As seen in this example, no overlay canvas is used, so other GUI elements will continue to function and the visuals can be modified/positioned if needed.

You can also create custom input for a camera. For example, here is a combined input suitable for FPS games, with a movement joystick on the left and a swipe-rotation area on the right:

Custom Joystick Input Example