Rigidbody.MovePosition() moves only in the GLOBAL z axis (forward and backward)

Hi,

I am making a simple character controller script, and I am using Rigidbody to move my character.
But my problem is that the character moves only forward and backward, which is the Global z axis.
Even if I rotate my character around the y axis, it only moves forward and backward (global of course).
I also tried to move the rigidbody using transform.localPosition instead of transform.position, but it also doesn’t work.

What did I do wrong? Can someone help me please?

Here is my code:

    public float moveSpeed = 50f;
    public float rotateSpeed = 200f;
    private Vector3 moveDir;
    private float rotate;

    public Rigidbody rb;

    void Update()
    {
        moveDir = new Vector3(0, 0, Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
        rotate = Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime;
    }

    void FixedUpdate()
    {
        rb.MovePosition(transform.position + moveDir);
        transform.Rotate(0, rotate, 0);
    }

To get the translation in local space you need to multiply transform.Forward by your vector length

so your moveDir would be

transform.Forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTIme