MoveTowards not working on a slope

Hello Human Beings,

I have a player that is suppose to go where I click on the map using MoveTowards.
It does that but not on a slope. How do I fix that?
The character has a rigidbody. No character controller.

Assigning point to go code:

public GameObject player;

    private Vector3 pointToGo;
	
	void Update ()
    {
        if (player == null)
            return;

        if (Input.GetMouseButton(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                pointToGo = hit.point;
                player.GetComponent<PlayerMovement>().pointToGo = this.pointToGo;
            }
        }
    }

Moving code:

public float speed = 4;
    public Vector3 pointToGo;

    private Rigidbody rb;
    private Animator animator;

    private void Start()
    {
        rb = this.GetComponent<Rigidbody>();
        animator = this.GetComponent<Animator>();
    }

    void Update ()
    {
        if ( Vector3.Distance(this.transform.position, pointToGo) > 0.5f )
        {
            this.transform.position = Vector3.MoveTowards(this.transform.position, pointToGo, speed * Time.deltaTime);
            this.transform.LookAt(new Vector3(pointToGo.x,
                                            this.transform.position.y,
                                            pointToGo.z));
            rb.isKinematic = false;
            animator.SetBool("isIdle", false);
            animator.SetBool("isWalking", true);
        }
        else
        {
            animator.SetBool("isIdle", true);
            animator.SetBool("isWalking", false);
            rb.isKinematic = true;
        }
    }

Thanks in advance,
Ethan

You don’t need the character controller, I find it useless and write my own movement anyway.

Just use velocity. Something like this.

            rotationOverTIme = Quaternion.LookRotation(targetPosition - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, rotationOverTIme, turningSpeed * Time.deltaTime);
            if (Vector3.Distance(transform.position, targetPosition) > 0.1f)
            {
                body.velocity = transform.forward * speed * Time.deltaTime;
            }

Have you considered using the NavMeshAgent instead of the Rigidbody? That would handle it automatically, but it would only work with levels that can have their nav mesh pre-computed (i.e. not generated at runtime).

If that doesn’t work, then the simple answer is to run a raycast from the center, straight down. Then you take the hit point, and adjust your Y-position accordingly.