BGE Consistent character speed
I think you should separate the logic for movement+rotZ and mouselooking+rotX into two different objects, and then parent the second one to the first one. With such setup, the object moved by keyboard is always facing parallel to the ground, not trying to dig into it. The example of this would be camera and cuboid. The camera is rotated only in X axis (relating to your orientation from screen) with mouse and it's parented to cuboid. The cuboid is rotated in Z axis with mouse and also is moved with keyboard. You can check the blend file below to see how it's done (Blender 2.74 or the latest build). Note the camera from my example can be replaced with your object of choice, and cuboid can be set to invisible so it can't be seen ingame. I hope this can help solve your problem. If you have additional questions, please consider providing a .blend file for more accurate feedback.