Prevent rigidbody.AddForce from moving character on global Y axis

I have a rigidbody first person character. To move, you click and hold the mouse and rigidbody.AddForce will accelerate character in that direction. This mostly works fine, but when the player looks up and clicks, they are able to fly.

I want to prevent rigidbody.AddForce from applying any force to the global Y axis. Freezing the position on the Y axis on the rigidbody is almost exactly what I want, but it means the level must be completely flat and the character wont be able to move up or down slopes.

Is there a way to only apply force to the X and Z axis? Here’s what I’m currently using:

function FixedUpdate () {

	if (Input.GetMouseButton (0))
	{
		rigidbody.AddForce(-transform.forward * 50);
	}
}

Something like:

Vector3 forward = transform.forward;
forward.y = 0;
forward.Normalise();

This is pseudocode, so you’ll need to check. Naturally then apply force to the RigidBody as you are, replacing -transform.forward with your forward vector.

Unless I’m missing something here?