VirtualJoystick
Touchscreen joystick driving Input actions.
VirtualJoystick receives ScreenTouch/ScreenDrag within its Control area and owns one touch index. Configure four Input Map actions before use and read them in movement logic. Not a physical-gamepad driver; a mouse needs conversion to touch events.
Control size defines the touch activation area; JoystickSize defines the base size. Use positive JoystickSize and ClampzoneRatio, with DeadzoneRatio at least zero and strictly below one. Released/Flicked carry the last processed vector before reset.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
VirtualJoystickConstructor
public VirtualJoystick();Creates a touch joystick. Add to UI and configure its Control area/actions before touches. Construction does not create Input Map actions.
Properties11
ActionDownProperty
public StringName ActionDown { get; set; }Input Map action for the positive Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
ActionLeftProperty
public StringName ActionLeft { get; set; }Input Map action for the negative X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
ActionRightProperty
public StringName ActionRight { get; set; }Input Map action for the positive X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
ActionUpProperty
public StringName ActionUp { get; set; }Input Map action for the negative Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
ClampzoneRatioProperty
public float ClampzoneRatio { get; set; }Multiplier of the JoystickSize / 2 radius where output reaches full amplitude. Must be > zero: zero causes division by zero during input processing. The setter does not clamp programmatic values; configure before holding.
DeadzoneRatioProperty
public float DeadzoneRatio { get; set; }Fraction of clamp radius producing no movement. Use zero <= ratio < one. Beyond it, amplitude is remapped from zero to one; not a screen-width fraction. The setter does not clamp programmatic values.
InitialOffsetRatioProperty
public Vector2 InitialOffsetRatio { get; set; }Initial center as Control Size × ratio on each axis; (0.5, 0.5) is the center. Not a pixel offset. Changing it resets touch/actions; resizing the Control also resets the joystick.
JoystickModeProperty
public VirtualJoystick.JoystickModeEnum JoystickMode { get; set; }Fixed uses the original center and accepts touch starts within the base rectangle. Dynamic centers at touch start inside the Control. Following also moves the center when the finger exceeds the clamp radius while inside the Control. Does not set visibility.
JoystickSizeProperty
public float JoystickSize { get; set; }Base size in pixels, with control radius based on Size / 2. Use a positive value. Changing it resets the current touch/actions; not the full Control activation area.
TipSizeProperty
public float TipSize { get; set; }Knob size in pixels rather than output amplitude. Changing it resets the current touch/actions. Use a positive value.
VisibilityModeProperty
public VirtualJoystick.VisibilityModeEnum VisibilityMode { get; set; }Always draws the joystick continuously; WhenTouched skips drawing without an active touch during play. A drawing mode rather than Visible false: the input area remains. It stays visible in the editor for configuration.
Methods22
GetActionDownStringName
public StringName GetActionDown();Input Map action for the positive Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
StringNameInput Map action for the positive Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
GetActionLeftStringName
public StringName GetActionLeft();Input Map action for the negative X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
StringNameInput Map action for the negative X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
GetActionRightStringName
public StringName GetActionRight();Input Map action for the positive X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
StringNameInput Map action for the positive X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
GetActionUpStringName
public StringName GetActionUp();Input Map action for the negative Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
StringNameInput Map action for the negative Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
GetClampzoneRatiofloat
public float GetClampzoneRatio();Multiplier of the JoystickSize / 2 radius where output reaches full amplitude. Must be > zero: zero causes division by zero during input processing. The setter does not clamp programmatic values; configure before holding.
floatMultiplier of the JoystickSize / 2 radius where output reaches full amplitude. Must be > zero: zero causes division by zero during input processing. The setter does not clamp programmatic values; configure before holding.
GetDeadzoneRatiofloat
public float GetDeadzoneRatio();Fraction of clamp radius producing no movement. Use zero <= ratio < one. Beyond it, amplitude is remapped from zero to one; not a screen-width fraction. The setter does not clamp programmatic values.
floatFraction of clamp radius producing no movement. Use zero <= ratio < one. Beyond it, amplitude is remapped from zero to one; not a screen-width fraction. The setter does not clamp programmatic values.
GetInitialOffsetRatioVector2
public Vector2 GetInitialOffsetRatio();Initial center as Control Size × ratio on each axis; (0.5, 0.5) is the center. Not a pixel offset. Changing it resets touch/actions; resizing the Control also resets the joystick.
Vector2Initial center as Control Size × ratio on each axis; (0.5, 0.5) is the center. Not a pixel offset. Changing it resets touch/actions; resizing the Control also resets the joystick.
GetJoystickModeVirtualJoystick.JoystickModeEnum
public VirtualJoystick.JoystickModeEnum GetJoystickMode();Fixed uses the original center and accepts touch starts within the base rectangle. Dynamic centers at touch start inside the Control. Following also moves the center when the finger exceeds the clamp radius while inside the Control. Does not set visibility.
VirtualJoystick.JoystickModeEnumFixed uses the original center and accepts touch starts within the base rectangle. Dynamic centers at touch start inside the Control. Following also moves the center when the finger exceeds the clamp radius while inside the Control. Does not set visibility.
GetJoystickSizefloat
public float GetJoystickSize();Base size in pixels, with control radius based on Size / 2. Use a positive value. Changing it resets the current touch/actions; not the full Control activation area.
floatBase size in pixels, with control radius based on Size / 2. Use a positive value. Changing it resets the current touch/actions; not the full Control activation area.
GetTipSizefloat
public float GetTipSize();Knob size in pixels rather than output amplitude. Changing it resets the current touch/actions. Use a positive value.
floatKnob size in pixels rather than output amplitude. Changing it resets the current touch/actions. Use a positive value.
GetVisibilityModeVirtualJoystick.VisibilityModeEnum
public VirtualJoystick.VisibilityModeEnum GetVisibilityMode();Always draws the joystick continuously; WhenTouched skips drawing without an active touch during play. A drawing mode rather than Visible false: the input area remains. It stays visible in the editor for configuration.
VirtualJoystick.VisibilityModeEnumAlways draws the joystick continuously; WhenTouched skips drawing without an active touch during play. A drawing mode rather than Visible false: the input area remains. It stays visible in the editor for configuration.
SetActionDownvoid
public void SetActionDown(StringName action);Input Map action for the positive Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
| Name | Type | Default |
|---|---|---|
action | StringName | — |
actionName of a previously defined Input Map action.
SetActionLeftvoid
public void SetActionLeft(StringName action);Input Map action for the negative X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
| Name | Type | Default |
|---|---|---|
action | StringName | — |
actionName of a previously defined Input Map action.
SetActionRightvoid
public void SetActionRight(StringName action);Input Map action for the positive X component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
| Name | Type | Default |
|---|---|---|
action | StringName | — |
actionName of a previously defined Input Map action.
SetActionUpvoid
public void SetActionUp(StringName action);Input Map action for the negative Y component, with strength from processed output. Define it before input. Configure before holding: changing the name does not automatically release the old action. Coordinate virtual sources sharing actions because the joystick calls action_press/action_release.
| Name | Type | Default |
|---|---|---|
action | StringName | — |
actionName of a previously defined Input Map action.
SetClampzoneRatiovoid
public void SetClampzoneRatio(float ratio);Multiplier of the JoystickSize / 2 radius where output reaches full amplitude. Must be > zero: zero causes division by zero during input processing. The setter does not clamp programmatic values; configure before holding.
| Name | Type | Default |
|---|---|---|
ratio | float | — |
ratioRatio for the corresponding zone; see the setting’s valid conditions.
SetDeadzoneRatiovoid
public void SetDeadzoneRatio(float ratio);Fraction of clamp radius producing no movement. Use zero <= ratio < one. Beyond it, amplitude is remapped from zero to one; not a screen-width fraction. The setter does not clamp programmatic values.
| Name | Type | Default |
|---|---|---|
ratio | float | — |
ratioRatio for the corresponding zone; see the setting’s valid conditions.
SetInitialOffsetRatiovoid
public void SetInitialOffsetRatio(Vector2 ratio);Initial center as Control Size × ratio on each axis; (0.5, 0.5) is the center. Not a pixel offset. Changing it resets touch/actions; resizing the Control also resets the joystick.
| Name | Type | Default |
|---|---|---|
ratio | Vector2 | — |
ratioRatio for the corresponding zone; see the setting’s valid conditions.
SetJoystickModevoid
public void SetJoystickMode(VirtualJoystick.JoystickModeEnum mode);Fixed uses the original center and accepts touch starts within the base rectangle. Dynamic centers at touch start inside the Control. Following also moves the center when the finger exceeds the clamp radius while inside the Control. Does not set visibility.
| Name | Type | Default |
|---|---|---|
mode | VirtualJoystick.JoystickModeEnum | — |
modeJoystick positioning or visibility mode according to the argument type.
SetJoystickSizevoid
public void SetJoystickSize(float size);Base size in pixels, with control radius based on Size / 2. Use a positive value. Changing it resets the current touch/actions; not the full Control activation area.
| Name | Type | Default |
|---|---|---|
size | float | — |
sizePositive base/knob size in pixels.
SetTipSizevoid
public void SetTipSize(float size);Knob size in pixels rather than output amplitude. Changing it resets the current touch/actions. Use a positive value.
| Name | Type | Default |
|---|---|---|
size | float | — |
sizePositive base/knob size in pixels.
SetVisibilityModevoid
public void SetVisibilityMode(VirtualJoystick.VisibilityModeEnum mode);Always draws the joystick continuously; WhenTouched skips drawing without an active touch during play. A drawing mode rather than Visible false: the input area remains. It stays visible in the editor for configuration.
| Name | Type | Default |
|---|---|---|
mode | VirtualJoystick.VisibilityModeEnum | — |
modeJoystick positioning or visibility mode according to the argument type.
Signals and events5
FlickCanceledEvent
public event Action FlickCanceled;Moving from nonzero input back into the deadzone marks the flick canceled. Not an OS touch-cancellation event. Leaving the deadzone again can re-enable a flick.
FlickedEvent
public event VirtualJoystick.FlickedEventHandler Flicked;On release after dragging with nonzero output, emits the last processed vector. Does not calculate gesture velocity or throw impulse; calculate those separately if needed.
| Name | Type | Default |
|---|---|---|
inputVector | Vector2 | — |
inputVectorLast processed vector: X rightward, Y downward; length up to one with valid settings.
PressedEvent
public event Action Pressed;An accepted touch starts. The control handles one touch index; extra touches do not become another independent stick in the same control.
ReleasedEvent
public event VirtualJoystick.ReleasedEventHandler Released;Emits the last deadzone-processed vector on release, before resetting to zero. Final touch output rather than a continuous movement event. Tapped or Flicked may follow immediately.
| Name | Type | Default |
|---|---|---|
inputVector | Vector2 | — |
inputVectorLast processed vector: X rightward, Y downward; length up to one with valid settings.
TappedEvent
public event Action Tapped;Emitted on release without ScreenDrag and without a canceled flick state. Hold duration is not limited; not restricted to a short tap.
VirtualJoystick.JoystickModeEnum
| Value | Description |
|---|---|
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. |
Fixed = 0 | The joystick doesn't move. |
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. |
VirtualJoystick.VisibilityModeEnum
| Value | Description |
|---|---|
Always = 0 | The joystick is always visible. |
WhenTouched = 1 | The joystick is only visible when being touched. |
Theme properties
These are Theme resource keys, not C# properties. Use the matching Control GetTheme…() and AddTheme…Override() methods for each value type.
| Key and type | Description |
|---|---|
normal_joystickStyleBox | Base joystick |
normal_tipStyleBox | Tip joystick |
pressed_joystickStyleBox | Base joystick |
pressed_tipStyleBox | Tip joystick |