I'm making a joystick and I don't want the center circle to go past the boundaries of the outer circle.
func _input(event):
if event is InputEventScreenDrag or (event is InputEventScreenTouch and event.is_pressed()):
global_position = event.position - radius
var dist = (global_position).distance_to(get_parent().global_position - radius)
if dist > bounds:
position = (position - event.position).normalized() * bounds
The center just merely disappears when dist > bounds
because the line after it is returning wrong calculations.
What is the correct way to achieve this? Thanks in advance.