Virtual-Joystick-Godot icon indicating copy to clipboard operation
Virtual-Joystick-Godot copied to clipboard

change base joystick size by scale.

Open kimk05 opened this issue 1 year ago • 6 comments

Thanks for you library.

Changing the scale of the 'Base' node causes it to behave abnormally. Below seems to be one of the ways to fix it.

func _move_base(new_position: Vector2) -> void:
	_base.global_position = new_position - _base.pivot_offset * _base.get_global_transform_with_canvas().get_scale() # <-- Add _base.get_global_...
func _update_joystick(touch_position: Vector2) -> void:
	var _base_radius = _get_base_radius()
	var center : Vector2 = _base.global_position + _base_radius
	var vector : Vector2 = touch_position - center
	
	var c = clampzone_size * _base.get_global_transform_with_canvas().get_scale().x  # <-- Assuming scale x and y are the same
	var d = deadzone_size * _base.get_global_transform_with_canvas().get_scale().x   # <-- Assuming scale x and y are the same
	
	vector = vector.limit_length(c)
	
	if joystick_mode == Joystick_mode.FOLLOWING and touch_position.distance_to(center) > c:
		_move_base(touch_position - vector)
	
	_move_tip(center + vector)
	
	if vector.length_squared() > d * d:
		is_pressed = true
		output = (vector - (vector.normalized() * d)) / (c - d)
	else:
		is_pressed = false 
		output = Vector2.ZERO
	
	if use_input_actions:
		# Release actions
		if output.x >= 0 and Input.is_action_pressed(action_left):
			Input.action_release(action_left)
		if output.x <= 0 and Input.is_action_pressed(action_right):
			Input.action_release(action_right)
		if output.y >= 0 and Input.is_action_pressed(action_up):
			Input.action_release(action_up)
		if output.y <= 0 and Input.is_action_pressed(action_down):
			Input.action_release(action_down)
		# Press actions
		if output.x < 0:
			Input.action_press(action_left, -output.x)
		if output.x > 0:
			Input.action_press(action_right, output.x)
		if output.y < 0:
			Input.action_press(action_up, -output.y)
		if output.y > 0:
			Input.action_press(action_down, output.y)

kimk05 avatar Feb 15 '25 18:02 kimk05

If you fixed the issue you can open a PR @kimk05

viktorpopp avatar Feb 18 '25 14:02 viktorpopp

OK, I opened a PR. @ViktorPopp

kimk05 avatar Feb 18 '25 19:02 kimk05

OK, I opened a PR. @ViktorPopp

Nice!

viktorpopp avatar Feb 18 '25 19:02 viktorpopp

Tested the fix, and it seems to be working. Also, it would be great to have a way to change the size directly on the VirtualJoystick scene, without having to enter the scene and changing the Base node size. I think I could add this functionality, but I would like to know why the PR wasn't merged yet first.

reisaraujo-miguel avatar Mar 27 '25 18:03 reisaraujo-miguel

Hi @reisaraujo-miguel,

Sorry but I had to prioritize work/life plans, I'll get to this asap.

MarcoFazioRandom avatar Mar 29 '25 07:03 MarcoFazioRandom