Duplicated Sprites w/ Joystick

Godot Version

4.4.1

Question

So I’ve made a joystick for a top down RPG I’m making. I followed a tutorial and changed some things to fit my game. For some reason the center knob is duplicating itself whenever I move the sprite. I’ve been playing with it for a while now and can’t seem to figure this one out.

Here’s my code for the knob’s movement:

	if pressing:
		if get_global_mouse_position().distance_to(parent.global_position) <= maxLength:
			global_position = get_global_mouse_position()
		else:
			GameManager.angle = parent.global_position.angle_to_point(get_global_mouse_position())
			global_position.x = parent.global_position.x + cos(GameManager.angle) * maxLength
			global_position.y = parent.global_position.y + sin(GameManager.angle) * maxLength
			calculateVector()
	else:
		global_position = lerp(global_position, parent.global_position, delta*10)
		GameManager.posVector = Vector2(0,0)

And here’s a picture of what the knob is doing in game:

The movement is working fine, I just can’t seem to get that duplicate knob to go away!

Thank you!

Is there any chance you have two of these virtual joysticks? Did you instantiate it and add it as a global example?

I have the joystick scene in my Player HUD CanvasLayer. I can’t find any other instances in my code. I did include a variable for the Joystick root note in my GameManager global (so the player and the joystick scene could access it).

How do you define the variable in your GameManager global? How is it set?

GameManager.gd

extends Node

var angle = 0
var posVector: Vector2

Then I just refer to the variables in my Joystick scene as GameManager.angle or GameManager.posVector

Also, whenever I have the Joystick within my Player Scene instead of my PlayerHud Scene, the error doesn’t occur.

PlayerHud/Control/Joystick – Doesn’t work
Overworld/Player/Joystick – Works

Interesting, what happens if you remove it from both? Does a joystick still appear?

No joystick appears. :[

Are you drawing the joystick with CanvasItem._draw()? Make sure that you aren’t drawing 2 knobs if that’s the case.