How to link UI joystick to value

I’m modifying the karting microgame and I have already added controller support, but I also wanted to add on-screen joystick support. I’ve already managed to create a script that accelerates, brakes, and steers the car, but I can’t figure out how to link it to an on-screen joystick. I made this quick video to make what I’m talking about clearer:

In short, what I need to do is find a way to make it so that moving the joystick changes the “steer” value between -1 and 1 to control how much the car steers.

I’ve managed to, in the meanwhile, create functions called by UI buttons to steer the car left or right, which works, but is definitely not ideal because it doesn’t allow for very precise movements at all.
This is the UI input script, attached directly to the player car:

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

namespace KartGame.KartSystems
    public class UiInput : BaseInput

        public bool accelerate;
        public bool brake;
        public float turn;

        // Called by OnPointerDown event from Even Trigger attached to UI object
        public void StartAccelerate() => accelerate = true;

        // Called by OnPointerUp event from Even Trigger attached to UI object
        public void StopAccelerate() => accelerate = false;

        public void StartBrake() => brake = true;
        public void StopBrake() => brake = false;

        public void StartTurnLeft() => turn = Mathf.Max(turn - 1, -1);
        public void StopTurnLeft() => turn = Mathf.Min(turn + 1, 1);

        public void StartTurnRight() => turn = Mathf.Min(turn + 1, 1);
        public void StopTurnRight() => turn = Mathf.Max(turn - 1, -1);

        public override InputData GenerateInput()
            return new InputData
                Accelerate = accelerate,
                Brake = brake,
                TurnInput = turn

I’m currently using a joystick I found on the unity asset store but if you have any idea of another solution that might work better for this case please let me know.

If you’ve already hooked up your controls to the new input system, there is actually an ‘On-screen stick’ component, which should be exactly what you’re looking for :smiley: