How to set the velocity in Z direction to 0?

Hi, i just made my first game using Unity which was a lot of fun X). Because i’m really new to C# I really have no idea how to code by myself and needed some help.

So this is the script that im using for my player movement:

using UnityEngine;

public class Playermovement : MonoBehaviour {

// Use this for initialization
public Rigidbody rb;

public float forwardForce = 2000f;
public float SidewaysForce = 500f;


//awodhbfa
//lzcnvl;kmfsd
 void FixedUpdate ()
 {
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

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

    if (rb.position.y < -1f)
        {
            FindObjectOfType<GameManager>().EndGame();
        }
      
} 

}

but when i go and play the game, the movement feels really sloppy and you feel like a drunk man getting forces of 100f in Z direction xd.
So what i was hoping that i could do was to add an if statement saying that if im not clicking A or D, set my speed in Z direction to 0. Does anyone know if this is possible?

this snippet will help you to make your z-axis velocity becomes 0 when both A and D are not pressed


if(!Input.GetKey("a") && !Input.GetKey("d")) {
    Vector3 resultVelocity = rb.velocity;
    resultVelocity.z = 0;
    rb.velocity = resultVelocity;
}