Translation issue

Hello i’m a fresh user of Unity3D and i’m trying to make some kind of 3D platformer where a cube needs to hit another cube to win the level with walls between the two.

The problem is that when my cube moves when pressing the left arrow for example he moves on the X, Y and Z axis but i only want him to move on the x.

it seems like he moves on the x but he hits the floor and that makes him go a bit up and down (0.2) but he moves a lot on the Z axis unfortunately.

So my question is how can I stop it from hitting the floor and doing that ? I just want him to glide smoothly.

code of the translation :

// Player Movement
	if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * Time.deltaTime * speed);


It sounds like you have a rigidbody component attached to your player, if thats the case then i would recommend using rigidbody methods to apply translations to your player.

rigidbody.velocity = Vector3.right * Input.GetAxis ("Horizontal") * Time.deltaTime * speed;


rigidbody.AddForce(Vector3.right * Input.GetAxis ("Horizontal") * Time.deltaTime * speed);

to prevent movement on certain axes checkout
rigidbody.constraints is accessible the inspector as checkboxes i belive