How to use joystick Unity Mobile?

I’m brand new to the mobile arena. I’ve got a simple game where you roll around a ball using the arrow keys (by using AddForce to the sphere’s rigidbody), but I want this game to be for android. So I’ve set the settings and all that, I have a joystick on the game screen, I just don’t know how to use it to move the ball. What values do I access to find the position of the joystick? I’ve had a lot of trouble trying to figure this out… Thanks.

First, create a joy stick base and a stick(use a cube or sprite, whatever), color them differently, make the stick 1/4th the size of the base. & parent the stick to the joy base.

Considering only the first touch, here’s some pseudo code:

// attach this script to the joystick base
if(touchcount  = 1)
{
  desiredStickLocalPosition = touch position - joy base position
  clamp desiredStickLocalPosition magnitude to joystick limits
  stick.localposition = desiredStickLocalPosition
}

You may want to consider a package like Prime31’s UIToolKit(free) or 2d toolkit(paid) to handle multi touch because you will end up needing it when you add other buttons.

I haven’t coded this myself but I’ve tried make it understandable, hope it helps.