Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MarcoFazioRandom/Virtual-Joystick-Godot
A simple virtual joystick for touchscreens, for both 2D and 3D games, with useful options.
https://github.com/MarcoFazioRandom/Virtual-Joystick-Godot
gdscript godot joystick touchscreen
Last synced: about 2 months ago
JSON representation
A simple virtual joystick for touchscreens, for both 2D and 3D games, with useful options.
- Host: GitHub
- URL: https://github.com/MarcoFazioRandom/Virtual-Joystick-Godot
- Owner: MarcoFazioRandom
- License: mit
- Created: 2019-06-01T16:07:06.000Z (over 5 years ago)
- Default Branch: Main
- Last Pushed: 2024-09-21T15:38:44.000Z (3 months ago)
- Last Synced: 2024-10-29T17:12:03.456Z (about 2 months ago)
- Topics: gdscript, godot, joystick, touchscreen
- Language: GDScript
- Homepage:
- Size: 924 KB
- Stars: 717
- Watchers: 18
- Forks: 78
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-godot - Virtual Joystick - A virtual joystick for touchscreens. Simple to use and with useful options (Godot 3.x, 4.x). (Plugins and scripts / 3D)
README
# Godot Virtual Joystick
A simple virtual joystick for touchscreens, with useful options.
GitHub Page: https://github.com/MarcoFazioRandom/Virtual-Joystick-Godot
Godot Engine: https://godotengine.org
## PREVIEWS:
Easy to use:
```GDScript
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 the joystick output:
# if joystick_left and joystick_left.is_pressed:
# position += joystick_left.output * speed * delta## Movement using Input functions:
move_vector = Vector2.ZERO
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:
- Joystick mode:
- Fixed: The joystick doesn't move.
- Dynamic: Every time the joystick area is pressed, the joystick position is set on the touched position.
- Following: When the finger moves outside the joystick area, the joystick will follow it.- Dead zone size: If the tip is inside this range the output is zero.
- Clamp zone size: The max distance the tip can reach.
- Visibility mode:
- always: Always visible.
- touchscreen only: Visible on touch screens only (will hide if the device has not a touchscreen).
- when_touched: Visible only when touched.- Use input actions: if true the joystick will trigger the input actions created in Project -> Project Settings -> Input Map
## HELP:
- The Control parent of the joystick is the area in which the joystick can move in Dynamic mode.
- For moving the joystick inside his area, select it, right click, turn on "Editable Children" and then change the position of the Base node.
- With "Editable Children" turned on you can also edit the joystick textures and colors.
- Create a CanvasLayer node and name it "UI", it'll contain all the UI elements, then add the Joystick scene as a child of the UI node and move it where you prefer.
- An example scene is provided in the "Test" folder.## FAQ
### Multitouch doesn't work / can't use two joystick at the same time:
In Godot, the input events from the mouse don't support multitouch, so make sure to have this configuration:
Project -> Project Settings -> General -> Input Devices
"emulate touch from mouse" ON
"emulate mouse from touch" OFF### The joystick doesn't work when using Input.get_vector():
⚠ **This has been fixed in Godot Engine 4.2.1**
Unfortunately, this a bug in the Godot engine, so the only solution for now is using Input.get_axis:
This doesn't work:
```gdscript
input_vector := Input.get_vector("ui_left","ui_right","ui_up","ui_down")
```
This works:
```gdscript
input_vector := Vector2.ZERO
input_vector.x = Input.get_axis("ui_left", "ui_right")
input_vector.y = Input.get_axis("ui_up", "ui_down")
```