I can't get my player's rotation working

My rotation for the player isn’t working and I would like to get help! I’ve looked into the documentation and youtube videos but I can’t get it right for some reason.


public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public float rotationSpeed = 5f;
    public Rigidbody2D rb;

    Vector2 moveDirection;
    
    

    void Update()
    {
        float moveX = Input.GetAxisRaw("Horizontal");
        float moveY = Input.GetAxisRaw("Vertical");

        if (Input.GetMouseButtonDown(0))
        {
            Fire();
        }
        moveDirection = new Vector2(moveX, moveY);
        float inputMagnitude =Mathf.Clamp01(moveDirection.magnitude);
        moveDirection.Normalize();

        transform.Translate(moveDirection * moveSpeed * inputMagnitude * Time.deltaTime, Space.World);

        rb.velocity = new Vector2(moveDirection.x * moveSpeed * Time.deltaTime, moveDirection.y * moveSpeed * Time.deltaTime);

        if (moveDirection != Vector2.zero)
        {
            Quaternion toRotation = Quaternion.LookRotation(transform.forward, moveDirection);
            Quaternion rotate = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
            rb.MoveRotation(rotate);
        }



    }

    

    public GameObject bulletPrefab;
    public Transform firePoint;
    public float fireForce;
    public void Fire()
    {
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        bullet.GetComponent<Rigidbody2D>().AddForce(firePoint.up * fireForce, ForceMode2D.Impulse);
    }

}

Here is my code for the player.

You’re probably not setting the rotation speed high enough. Try increasing it to around 500.

There’s also other issues with your code. Fixed below:

using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 10f;
    public float rotationSpeed = 500f;
    public Rigidbody2D rb;

    Vector2 moveDirection;
    
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Fire();
        }
    }
    // Physics movement goes in FixedUpdate:
    void FixedUpdate()
    {
        float moveX = Input.GetAxisRaw("Horizontal");
        float moveY = Input.GetAxisRaw("Vertical");

        moveDirection = new Vector2(moveX, moveY);
        moveDirection.Normalize();

        rb.velocity = new Vector2(moveDirection.x, moveDirection.y) * moveSpeed;

        if (moveDirection != Vector2.zero)
        {
            Quaternion toRotation = Quaternion.LookRotation(transform.forward, moveDirection);
            Quaternion rotate = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
            rb.MoveRotation(rotate);
        }
    }

    public GameObject bulletPrefab;
    public Transform firePoint;
    public float fireForce;
    public void Fire()
    {
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        bullet.GetComponent<Rigidbody2D>().AddForce(firePoint.up * fireForce, ForceMode2D.Impulse);
    }
}