Godot Version
Godot_v3.5.1-stable_win64
Question
Hello, I need help, I am trying to put a virtual joystick but when I try to put @onready and @export I get the error
extends CharacterBody2D
@onready var joystick = $“…/Camera2D/Joystick”
var speed = 300
func _physics_process(delta):
var direction = joystick.posVector
if direction:
velocity = direction * speed
else:
velocity = Vector2(0,0)
move_and_slide()
extends Sprite
@export var max_length = 50 # Clearer variable name
@export var dead_zone = 5 # Consistent naming convention
var is_pressing = false # Using a more descriptive name
func _ready():
# Check if a parent node is necessary. If not, remove the line.
# If a parent is needed, ensure it’s a valid NodePath.
# var parent = $“…”
func _process(delta):
if is_pressing:
var mouse_pos = get_global_mouse_position()
var distance = mouse_pos.distance_to(global_position)
# Handle dead zone
if distance > dead_zone:
# Limit movement within max_length
global_position = mouse_pos.clamped(global_position - max_length, global_position + max_length)
func _on_Button_button_down():
is_pressing = true
func _on_Button_button_up():
is_pressing = false