how do i get my 2d character to rotate towards the direction the joystick is facing?

im trying to create a mobile game where you can control the player usnig 2 joysticks, one for movement, and one for looking(i might combine later)

how do i make the character rotate towards the direction the joystick is facing?

heres my current code, the rotate part doesnt work

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

public class PlayerController : MonoBehaviour
{
    public Rigidbody2D rb;

    public Joystick moveJoystick, shootJoystick;

    public Camera cam;

    public float moveSpeed;
    Vector3 moveDir;
    Vector2 mousePos;

    Quaternion targetRotation;

    public float rotateSpeed;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        var input = new Vector2(shootJoystick.Horizontal, shootJoystick.Vertical);
        if (input != Vector2.zero)
        {
            targetRotation = Quaternion.LookRotation(input);
        }
        // Rotate towards targetRotation here
        transform.rotation = Quaternion.Euler(0f, 0f, targetRotation.z);

        if (moveJoystick.Horizontal >= .2f || moveJoystick.Horizontal <= -.2f)
            moveDir.x = moveJoystick.Horizontal;
        else
        {
            moveDir.x = 0f;
        }

        if (moveJoystick.Vertical >= .2f || moveJoystick.Vertical <= -.2f)
            moveDir.y = moveJoystick.Vertical;
        else
        {
            moveDir.y = 0f;
        }
    }

    private void FixedUpdate()
    {
        rb.MovePosition(transform.position + (moveDir * moveSpeed * Time.fixedDeltaTime));
    }
}

I’m not sure what is going on in lines 33 and 36, but I know that accessing the .z field of a Quaternion is not going to be helpful to you in any way. Depending on how line 33 works, perhaps using eulerAngles.z might be an approach in line 36, but again, no idea really.

I do know how to make a twin-stick shooter though, and you’re welcome to the entire project, which is located inside of my proximity_buttons package.

All the rotation takes place around the Y axis but the rotational process (cartesian to polar) is identical to the problem you are solving, so just swap the axes around appropriately.

Look for the DemoTwinStickShooter scene.

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons

nvm i looked around and found a solution

Vector3 dir = Vector3.zero;
        dir.x = moveJoystick.Horizontal;
        dir.y = moveJoystick.Vertical;

        if (moveJoystick.Direction != Vector2.zero)
        {
            dir = moveJoystick.Direction;
        }

        //the turn part of my code
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(0f, 0f, angle);