2D - Move an object

I’m trying to implement a function which allow IA to move an object randomly (smoothly, NOT like from a point to point directly without seeing that the object is moving).

My question is if I’m coding movements right.
This is just the movement parts which I’m having doubts about:

//Moving towards right
transform.position += transform.right * movementSpeed * Time.deltaTime;
//Moving towards left
transform.position -= transform.right * movementSpeed * Time.deltaTime;
//Moving upwards
transform.position += transform.up * movementSpeed * Time.deltaTime;
//Moving downwards
transform.position -= transform.up * movementSpeed * Time.deltaTime;

I’m asking this question, because seems that after few movements, the object is starting to make small movements in random direction (like if the transform.position is = 1).

If it can help, here the function complete:

public class Movement_Worker : MonoBehaviour
{
    public float movementSpeed;
    public int limiteStessaDirezione = 15;
    bool UP = false;
    bool DOWN = false;
    bool RIGHT = false;
    bool LEFT = false;
    bool FERMO = false;

    //sceltaMovimento indicates if we can choose a new direction or not  
    bool sceltaMovimento = true;
    //i_tipoMovimento is just a counter.
    int i_tipoMovimento = 0;

   
    void FixedUpdate()
    {
        sceltaMov();
    }

    private void sceltaMov()
    {
        Debug.Log("tipoMovimento = " + sceltaMovimento);
        int scelta = Random.Range(1, 6);

        if (i_tipoMovimento >= limiteStessaDirezione)
        {
            sceltaMovimento = true;
            i_tipoMovimento = 0;
        }
            
        if (sceltaMovimento == true)
        {
            switch (scelta)
            {
                case 1:
                    //RIGHT
                    transform.position += transform.right * movementSpeed * Time.deltaTime;
                    RIGHT = true;
                    sceltaMovimento = false;
                    break;
                case 2:
                    //LEFT
                    transform.position -= transform.right * movementSpeed * Time.deltaTime;
                    LEFT = true;
                    sceltaMovimento = false;
                    break;
                case 3:
                    //UP
                    transform.position += transform.up * movementSpeed * Time.deltaTime;
                    UP = true;
                    sceltaMovimento = false;
                    break;
                case 4:
                    //DOWN
                    transform.position -= transform.up * movementSpeed * Time.deltaTime;
                    DOWN = true;
                    sceltaMovimento = false;
                    break;
                default:
                    //DONT MOVE
                    //transform.position = transform.position;
                    FERMO = true;
                    sceltaMovimento = false;
                    break;
            }         
        }
        //Repeat same movement X times
        while(sceltaMovimento == false)
        {
            if (FERMO == true)
            {
                i_tipoMovimento += 1;
                break;
            }
            else if (RIGHT == true)
            {
                i_tipoMovimento += 1;
                transform.position += transform.right * movementSpeed * Time.deltaTime;
                break;
            }
            else if (LEFT == true)
            {
                i_tipoMovimento += 1;
                transform.position -= transform.right * movementSpeed * Time.deltaTime;
                break;
            }
            else if (UP == true)
            {
                i_tipoMovimento += 1;
                transform.position += transform.up * movementSpeed * Time.deltaTime;
                break;
            }
            else if (DOWN == true)
            {
                i_tipoMovimento += 1;
                transform.position -= transform.up * movementSpeed * Time.deltaTime;
                break;
            }
        }
    }
}

I think that you are trying to move a gameobject in a certain direction. This script may be useful:

public float direction = 45; //in degrees (plus 270 degrees)
public float speed = 2; //in Units per second

private float directionInRadians;
private Vector3 movementPerTimestepVector;
void FixedUpdate()
{
    directionInRadians = direction * Mathf.Deg2Rad;
    movementPerTimestepVector = new Vector3(Mathf.Cos(directionInRadians), Mathf.Sin(directionInRadians), 0) * speed * Time.deltaTime;
    transform.position += movementPerTimestepVector;
}

It moves the gameobject in a certain direction at a fixed speed. You can set the direction to random.