MarcoFazioRandom/Virtual-Joystick-Godot

A simple virtual joystick for touchscreens, for both 2D and 3D games, with useful options.

GDScript

989

122 commits

updated Jan 19, 2025

See the code

README

Godot Virtual Joystick

A simple yet powerful virtual joystick for touchscreens in Godot, packed with useful options to enhance your game's mobile experience.

Godot Engine GitHub

๐ŸŽฎ Features

  • Easy to integrate
  • Customizable appearance
  • Multiple joystick modes
  • Input action support
  • Visibility options

๐Ÿ“ธ Preview

๐Ÿš€ Quick Start

  1. Add the joystick to your scene
  2. Configure the options
  3. Use the following script to get started:
extends Sprite2D

@export var speed : float = 100
@export var joystick_left : VirtualJoystick
@export var joystick_right : VirtualJoystick

var move_vector := Vector2.ZERO

func _process(delta: float) -> void:
    # Movement using Input functions:
    move_vector = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
    position += move_vector * speed * delta
    
    # Rotation:
    if joystick_right and joystick_right.is_pressed:
        rotation = joystick_right.output.angle()

โš™๏ธ Options

OptionDescription
Joystick ModeFixed, Dynamic, or Following
Dead Zone SizeMinimum distance for output
Clamp Zone SizeMaximum distance for output
Visibility ModeAlways, Touchscreen Only, or When Touched
Use Input ActionsTrigger input actions defined in Project Settings

๐Ÿ›  Setup Tips

  1. Create a CanvasLayer node named "UI" for all UI elements
  2. Add the Joystick scene as a child of the UI node
  3. Enable "Editable Children" to customize joystick appearance
  4. Refer to the example scene in the "Test" folder

๐Ÿ“˜ FAQ

Multitouch Issues?

Ensure these settings in Project -> Project Settings -> General -> Input Devices:

  • "Emulate Touch from Mouse" : ON
  • "Emulate Mouse from Touch" : OFF

If other buttons don't work with this configuration, use TouchScreenButton instead of TextureButton.

Input.get_vector() Not Working?

โš ๏ธ Fixed in Godot 4.2.1

For earlier versions, use this workaround:

input_vector := Vector2.ZERO
input_vector.x = Input.get_axis("ui_left", "ui_right")
input_vector.y = Input.get_axis("ui_up", "ui_down")

Freeze/crash on Android editor

As mentioned in the Docs, the Android editor is still unstable.

๐Ÿค Contributing

Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with โค๏ธ for the Godot community

gdscript
godot
joystick
touchscreen

MarcoFazioRandom/Virtual-Joystick-Godot

A simple virtual joystick for touchscreens, for both 2D and 3D games, with useful options.

GDScript

989

122 commits

updated Jan 19, 2025

See the code

README

Godot Virtual Joystick

A simple yet powerful virtual joystick for touchscreens in Godot, packed with useful options to enhance your game's mobile experience.

Godot Engine GitHub

๐ŸŽฎ Features

  • Easy to integrate
  • Customizable appearance
  • Multiple joystick modes
  • Input action support
  • Visibility options

๐Ÿ“ธ Preview

๐Ÿš€ Quick Start

  1. Add the joystick to your scene
  2. Configure the options
  3. Use the following script to get started:
extends Sprite2D

@export var speed : float = 100
@export var joystick_left : VirtualJoystick
@export var joystick_right : VirtualJoystick

var move_vector := Vector2.ZERO

func _process(delta: float) -> void:
    # Movement using Input functions:
    move_vector = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
    position += move_vector * speed * delta
    
    # Rotation:
    if joystick_right and joystick_right.is_pressed:
        rotation = joystick_right.output.angle()

โš™๏ธ Options

OptionDescription
Joystick ModeFixed, Dynamic, or Following
Dead Zone SizeMinimum distance for output
Clamp Zone SizeMaximum distance for output
Visibility ModeAlways, Touchscreen Only, or When Touched
Use Input ActionsTrigger input actions defined in Project Settings

๐Ÿ›  Setup Tips

  1. Create a CanvasLayer node named "UI" for all UI elements
  2. Add the Joystick scene as a child of the UI node
  3. Enable "Editable Children" to customize joystick appearance
  4. Refer to the example scene in the "Test" folder

๐Ÿ“˜ FAQ

Multitouch Issues?

Ensure these settings in Project -> Project Settings -> General -> Input Devices:

  • "Emulate Touch from Mouse" : ON
  • "Emulate Mouse from Touch" : OFF

If other buttons don't work with this configuration, use TouchScreenButton instead of TextureButton.

Input.get_vector() Not Working?

โš ๏ธ Fixed in Godot 4.2.1

For earlier versions, use this workaround:

input_vector := Vector2.ZERO
input_vector.x = Input.get_axis("ui_left", "ui_right")
input_vector.y = Input.get_axis("ui_up", "ui_down")

Freeze/crash on Android editor

As mentioned in the Docs, the Android editor is still unstable.

๐Ÿค Contributing

Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with โค๏ธ for the Godot community

gdscript
godot
joystick
touchscreen

Significant stargazers

Jan Jurzitza

232 followers ยท starred Feb 2024

follower

91 followers ยท starred Oct 2019

Wilson Enrique Alvarez Torres

51 followers ยท starred Nov 2024

bitbrain

691 followers ยท starred May 2023