Problems with the movement of the player

Hey I have this code for moving the player:

void FixedUpdate () {
         var x = Input.GetAxis("Horizontal") * Time.deltaTime * 250.0f;
         var z = Input.GetAxis("Vertical") * Time.deltaTime * 6.0f;

         transform.Rotate(0, x, 0);
         transform.Translate(0, 0, z);
    }

But it’s not working correctly. If move the player towards a wall, the player bounces smoothly to the opposite direction even if I don’t press any key. Do you have a solution for this problem?

Try using RigidBodys Velocity Component instead of transform.Translate. Im assuming you already have a RigidBody Component on your object, so try:

public class PlayerController : MonoBehaviour
{
    private Rigidbody rb; 
    void Awake()
    {
        rb = GetComponent<Rigidbody>(); // Connects the rb variable to the Players RigidBody Component
    }
   void FixedUpdate()
   {
   var x = Input.GetAxis("Horizontal") * Time.deltaTime * 250.0f;
   rb.velocity = new Vector3(x, rb.velocity.y,rb.velocity.z); // Set the horizontal velocity to the "x" input value (as you've assigned above) and leave the other values as they are (at their current velocity)

   }
}

I normally work in 2D, so i may have got the Axis wrong there, but I believe that should work,Try using RigidBodys velocity component instead of transform.Translate()
I’m assuming your Player object already has a RigidBody Component, but if not, add one and use this.
eg.

private Rigidbody rb;
void Awake()
    {
        rb = GetComponent<Rigidbody>(); // Connects the rb variable to the Players RigidBody Component
    }
void FixedUpdate()
   {
    rb.velocity = new Vector3(x, rb.velocity.y,rb.velocity.z);
    // Set the player's x velocity to the Horizontal input of the player (using "x" as the input variable as in your code)
    }