When player is moved horizontally, it is also going forward

Hello,

I’ve made script so that the player object can me moved with the arrow keys, but when I press right or left the player is not only going right or left but also a little bit forward(in the z-axis). This is my move script:

	void FixedUpdate () {

		if(isGrounded){
		input = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis("Vertical"));
		if(rigidbody.velocity.magnitude < maxSpeed){
			rigidbody.AddRelativeForce(input * moveSpeed);
		}
		}

	}

When I set the gravity in the rigidbody in the inspector off, it isn’t happening anymore. But then I have no gravity. Is it better to use the character controller and set a gravityY variable so the player object can fall?

How is it possible that the object is also going forward, and how can I prevent this?

It seems, that it’s an issue (but may be it’s a feature) of physical engine in part, associated with friction calculations. It looks like the value of this effect depends on square of colliding surfaces. I was able to reproduce the effect for box collider, but not for sphere and capsule collider. So, you can change collider for the player object to capsule or sphere. Or, if you stay with box collider, you can assign to it physics material with following settings: Dynamic Friction - 0, Static Friction - 0, Friction Combine - Minimum

UPD: Effect exists for capsule collider too, but it’s almost invisible.

31178-physicsmaterial.png