How do I make a MOBA skill Joystick and attack direction

I am trying to make a skill control joystick like those mobile moba games(If you do not know what’s a moba game, take Mobile legends as an example) . Can somebody give me ways on how to do this as this is my first time making a MOBA game.
This is an example on how would the skills work:
The first skill is a placement skill, you drag the skill’s joystick around to control the attack position and it should not go out of the maximum zone.
The second skill is a direction skill, you drag your joystick around to change the direction of the attack.
If anybody can give me some code example or overview on how to do it that would be nice.


the touch position and the joystick position are vectors with 2 dimensions (Vector2)

usually joysticks on mobile games have some extra space you can touch around there, so extend the actual range to detect more than the visual joystick and then the “indicator” circle that shows where the user is touching is capped at (touch-center).Unit * joystickRadius

the angle that the player makes in their joystick is atan2(touch.y-center.y, touch.x-center.x)

then using the angle you can get the attack direction or you can also use the magnitude (touch-center).Unit with the angle to get placement position