Completely stop addForce on rigidbody

Hey, I have tried for some time now to create a script that makes my player not to be pushed by the addForce when i hold down a key. So far I haven’t found a good solution on how to do this.

What I want: addForce is automatically added to the player, so it pushes the player along the screen. But when I press a key (for example F) I want the player to completely stop in the period the button is held down.

What I have tried, and what works in some degree:

    	void FixedUpdate () {
    		if(Input.GetKeyDown(KeyCode.F)){
    			rigidbody.velocity = Vector3.zero;
    			rigidbody.angularVelocity = Vector3.zero;
    			rigidbody.Sleep();
    			
    		}
    		else{
    			rigidbody.AddForce(acceleration, 0f, 0f, ForceMode.Acceleration); //This pushes the player with addForce
    		}
    	}

Problem here is that it won’t hold back the character for a long period, but only stops it for one frame.

How my game looks like at the moment: - YouTube

Thanks for any kind of help and suggestions

GetKey instead of GetKeyDown.

Try making it instead of add force, a constant force, and make it 0 when f is pressed down.
I found this video tutorial.( - YouTube ) This guy shows you somewhat how it works. You have to find where he starts talking about the movement, i think it’s in around the middle of the video. I used this tutorial with a game that i was making and it worked. I think it should work for you too.