On-Screen Joystick off centered when dragging

Hello everyone, I hope someone can help me figure this out. I have this script that I’m using to create an on-screen joystick the player can drag to move their character. The movement part works perfectly. The problem is that no matter where I put the joystick and pad UI elements, the ‘center’ of the joystick pad always defaults to the bottom left corner of my UI canvas. Such that the only want to actually drag the joystick down or to the left is to move the cursor off-screen. This is not ideal, as the game is a phone app and you can’t just drag your finger off the screen.

I can’t seem to figure out where in here or the object settings that the center area is being off-set.
Any help would be greatly appreciated.

Here’s the code I’m using.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Joystick : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
{
    public Transform player;
    Vector2 move;
    public float moveSpeed;

    public RectTransform pad;
    public void OnDrag(PointerEventData eventData)
    {
        transform.position = eventData.position;
        transform.localPosition =
            Vector2.ClampMagnitude(eventData.position - (Vector2)pad.position, pad.rect.width * 0.3f);
        move = new Vector2(transform.localPosition.x, transform.localPosition.y).normalized;
    }
    public void OnPointerUp(PointerEventData eventData)
    {
        transform.localPosition = Vector2.zero;
        move = Vector2.zero;
        StopCoroutine("PlayerMove");
    }
    public void OnPointerDown(PointerEventData eventData)
    {
      
        StartCoroutine("PlayerMove");
    }

    IEnumerator PlayerMove()
    {
        while (true)
        {
            player.Translate(move * moveSpeed * Time.deltaTime, Space.World);
          
          
            yield return null;
        }
    }

 
}

It’s probably because youre changing the joysticks local position to Vector2.zero in OnPointerUp(). Maybe try to delete that line (22), so that after the user cancels the press, the joystick doesnt move? If that doesnt work, could you post images of your ui components here?

The problem appears to be with something in the onDrag function. When I grab the stick component and move it around, it should be centered around the center of the pad component (I would assume) but it seems to ‘center’ on the bottom left corner of the screen/canvas.

Canvas Element


Pad Element

Stick Element

This is how the joystick looks in the game

The ‘center’ of where the drag area appears to be the corner of the UI canvas and not the center of the pad