(2D sidescroller) How do I make the player stop when both arrow keys are down?

Hello all, I’m making a sidescroller. When both the left and right arrow keys are down, I want the character to stop, if not it keeps continuing at a slower speed due to I’m not using GetAxisRaw. It’s a Rigidbody2D.

Also, when the character is stopping due to both keys held down, I want it to decrease speed gradually as if NO arrow keys were held down. Right now it stops immediately, and if I let go of the key I pressed down last, it continues at the same speed as it had when both keys were pressed down. I don’t want that to happen, I just want it to decrease speed until it stays still.

How do I write this?

You haven’t told us how you’re getting your rigidbody2d to move around. The best way to move rigidbodies around is to apply forces or constant forces. When your player tries to move in opposite directions the force being applied should return to 0.

If you’re not using force to move your rigidbodies then that’s your problem. If you are then the problem may be in your rigidbody2D component settings. Try messing with the drag and mass properties. It may be that your body is just too heavy or too much drag.