How do I add continuous force on an object?

Hello, I’m a beginner in coding and programming, and I’ve been having complications on my object movement.

Currently, I have my script set up with a forward force, and a sideways force. My forward force is continuous as I didn’t bind a key input for it.

The script I have for the sideways force is:

**if ( Input.GetKey(“d”))
{
// Only executed if condition is met
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

    if (Input.GetKey("a"))
    {
        rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
    }**

Every time I press one of the keys, it adds a force on the object on the x axis, causing my object to move sideways. I can hold the key to have it keep on moving, but as soon as I let go, it stops. What I’m trying to do is make it have continuous force upon a single press of one of the keys.

Basically, I’m trying to have it go left automatically or continuously upon a single press of the “a” key and have it change direction with the “d” key while still having continuous force.

I’ve been searching for solutions to this problem, but I’ve had no luck there.

Does anyone have an idea or advice on how I may be able to solve this issue?

bool ContinuousMovementToLeft = false;
bool ContinuousMovementToRight = false;
Rigidbody rb;
float MovementSpeed = 400;

    private void Update()
    {
        if (ContinuousMovementToLeft == true)
        {
            rb.AddForce(-Vector3.right * MovementSpeed);
        }

        else if (ContinuousMovementToRight == true)
        {
            rb.AddForce(Vector3.right * MovementSpeed);
        }

        CheckIfKeysWerePressed();
    }

    void CheckIfKeysWerePressed()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            ContinuousMovementToLeft = true;
            ContinuousMovementToRight = false;
        }

        else if (Input.GetKeyDown(KeyCode.A))
        {
            ContinuousMovementToLeft = false;
            ContinuousMovementToRight = true;
        }
    }

@Miongu You needed to add flags in your update that if they were true, they would continuously move in the correct direction. They become true when you press either A or D. Hope this helps.