Apply force then decrease it over time

Hello, I’m trying to make a ship
this is some of the script i have

	if(Input.GetKeyDown("w")){
		rigidbody.AddForce(Vector3.back*force);
	}
	if(Input.GetKeyUp("w")){
	rigidbody.AddForce(Vector3.back*Time.time*-force);

this instantly stops the ship in its path, instead of instantly stopping i need it too stop over time, kinda like an accelerator for a car, if you acell you go faster, if you don’t you gradually loose speed.
I tried playing around with Mathf.Clamp & failed, I’m still quite new to scripting.
Any help would be greatly appreciated!
Thanks for reading!

May be using the linear drag is what you are looking for. Just apply the force for acceleration like you did already (remove the GetKeyUp) and increase the rigidbody’s linear drag in the editor until you get the desired effect.