Untitled

                Never    
C#
       
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMouvement : MonoBehaviour
{
    private float rad;
    private float deg;
    private Rigidbody2D body;
    public float Speed;
    void Start()
    {

        body = GetComponent<Rigidbody2D>();

    }

    void FixedUpdate()
    {



        Vector2 Target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //Target.z = transform.position.z;

        float deltaX = Target.x - transform.position.x;
        float deltaY = Target.y - transform.position.y;

        //transform.position = Vector3.MoveTowards(transform.position, Target, Speed * Time.deltaTime / transform.localScale.x);
        float rad = Mathf.Atan(deltaY / deltaX);
        Debug.Log(rad);

        
            if (rad > 0)
            {
                Debug.Log("Angle is greater than 0, so should be between 0 and 90.");

                // Going down and to the left, so convert to Quadrant III
                if (deltaX < 0)
                {
                    Debug.Log("Moving to the left with deltaX = " + deltaX + ", so convert to Quadrant III");
                    rad = Mathf.PI + rad;
                }
                else
                {
                    Debug.Log("In Quadrant I, so keeping angle of " + rad);
                }
            }
            // Initial angle is -90-0, so either in Quadrant II or Quadrant IV
            else if (rad < 0)
            {
                Debug.Log("Angle is less than 0, so should be between -90 and 0.");

                // Going to the left, so convert to Quadrant II
                if (deltaX < 0)
                {
                    Debug.Log("Moving to the left with deltaX = " + deltaX + ", so convert to Quadrant II");
                    rad = Mathf.PI - rad;
                }
                // Going to the right, so convert to Quadrant IV with a positive angle value
                else if (deltaX > 0)
                {
                    Debug.Log("Going to the right, so in Quadrant IV. Converting from " + rad + " to " + ((Mathf.PI * 2) - rad));
                    rad = (Mathf.PI * 2) - rad;
                }
            }
            // Angle is 0, so need to check if actually 0 or 180 deg
            else
            {
                if (deltaX < 0)
                {
                    rad = Mathf.PI * 2;
                }
            }

            deg = rad * Mathf.Rad2Deg;
            


            body.MovePosition(new Vector2((transform.position.x + Target.x * ((Speed * Mathf.Sin(rad)) * Time.fixedDeltaTime / transform.localScale.x)),
                  transform.position.y + Target.y * ((Speed * Mathf.Cos(rad)) * Time.fixedDeltaTime / transform.localScale.y)));


          

    }
}

Raw Text