Turn a button into joystick

Anyone knows how to use an UI button as a right virtual joystick? I want the button to have an action on clicked/released but when pressed and moved to have a joystick function. Or find the logic behind a joystick movement so i can replicate it, or changing the z order of the joystick and be able to do an action when i release it. Or any other suggestion.

Nevermind. I found a solution