Skip to content

VirtualJoystick

Inherits: Control < CanvasItem < Entity < Object

A virtual joystick control for touchscreen devices.

A customizable on-screen joystick control designed for touchscreen devices. It allows users to provide directional input by dragging a virtual tip within a defined circular area.

This control can simulate directional actions (see action_up, action_down, action_left, and action_right), which are triggered when the joystick is moved in the corresponding directions.

Type Name Default
StringName action_down &"ui_down"
StringName action_left &"ui_left"
StringName action_right &"ui_right"
StringName action_up &"ui_up"
float clampzone_ratio 1.0
float deadzone_ratio 0.0
Vector2 initial_offset_ratio Vector2(0.5, 0.5)
JoystickMode joystick_mode 0
float joystick_size 100.0
float tip_size 50.0
VisibilityMode visibility_mode 0

flick_canceled

flick_canceled()

Emitted when the tip enters the deadzone after being outside of it.

flicked

flicked(input_vector: Vector2)

Emitted when the tip moved outside the deadzone and the joystick is released. The input_vector contains the last input direction and strength before release. Its length is between 0.0 and 1.0.

pressed

pressed()

Emitted when the joystick is pressed.

released

released(input_vector: Vector2)

Emitted when the joystick is released. The input_vector is the final input direction and strength, with a length between 0.0 and 1.0.

tapped

tapped()

Emitted when the joystick is released without moving the tip.

JoystickMode

enum JoystickMode

JOYSTICK_FIXED = 0

The joystick doesn’t move.

JOYSTICK_DYNAMIC = 1

The joystick is moved to the initial touch position as long as it’s within the joystick’s bounds. It moves back to its original position when released.

JOYSTICK_FOLLOWING = 2

The joystick is moved to the initial touch position as long as it’s within the joystick’s bounds. It will follow the touch input if it goes outside the joystick’s range. It moves back to its original position when released.

VisibilityMode

enum VisibilityMode

VISIBILITY_ALWAYS = 0

The joystick is always visible.

VISIBILITY_WHEN_TOUCHED = 1

The joystick is only visible when being touched.

normal_joystick

StyleBox normal_joystick (style)

normal_tip

StyleBox normal_tip (style)

pressed_joystick

StyleBox pressed_joystick (style)

pressed_tip

StyleBox pressed_tip (style)

action_down

StringName action_down = &"ui_down"

The action to trigger when the joystick is moved down.

action_left

StringName action_left = &"ui_left"

The action to trigger when the joystick is moved left.

action_right

StringName action_right = &"ui_right"

The action to trigger when the joystick is moved right.

action_up

StringName action_up = &"ui_up"

The action to trigger when the joystick is moved up.

clampzone_ratio

float clampzone_ratio = 1.0

The multiplier applied to the joystick’s radius that defines the clamp zone.

This zone limits how far the joystick tip can move from its center before being clamped.

A value of 1.0 means the tip can move up to the edge of the joystick’s visual size.

In JOYSTICK_FOLLOWING mode, this radius also determines how far the finger can move before the joystick base starts following the touch input.

deadzone_ratio

float deadzone_ratio = 0.0

The ratio of the joystick size that defines the joystick deadzone. The joystick tip must move beyond this ratio before being considered active.

This deadzone is applied before triggering input actions and affects the joystick’s input vector and all related signals.

Note that input actions may also define their own deadzones in the InputMap. If both are set, the joystick deadzone is applied first, followed by the action’s deadzone.

By default, this value is 0.0, meaning the joystick does not apply its own deadzone and relies entirely on the InputMap action deadzones.

initial_offset_ratio

Vector2 initial_offset_ratio = Vector2(0.5, 0.5)

The initial position of the joystick as a ratio of the control’s size. (0, 0) is top-left and (1, 1) is bottom-right.

joystick_mode

JoystickMode joystick_mode = 0

The joystick mode to use.

joystick_size

float joystick_size = 100.0

The size of the joystick in pixels.

tip_size

float tip_size = 50.0

The size of the joystick tip in pixels.

visibility_mode

VisibilityMode visibility_mode = 0

The visibility mode to use.