Character Controller problem

Ok so I’m trying to make a character controller, and make it move in the X and Z axis, but whenever I press A / D (to make it go along the X axis) it slightly moves in the Z axis aswell. (The script also contains if I hit an enemy, I will respawn at my spawn point, and hit Goal to make it move to the next level) But here is my script:

using UnityEngine;
using System.Collections;

public class PlayerMove : MonoBehaviour 
{
	public float moveSpeed;
	public GameObject deathExplosion;

	private float maxSpeed = 6f;
	private Vector3 input;

	private Vector3 spawn; 


	void Start () 
	{
		spawn = transform.position;
	}

	void FixedUpdate () 
	{
		input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));

		if(rigidbody.velocity.magnitude < maxSpeed)
		{
			rigidbody.AddForce (input * moveSpeed);
		}
	}

	void OnCollisionEnter(Collision other)
	{
		if (other.gameObject.tag == "Enemy")
		{
			Instantiate(deathExplosion, transform.position, Quaternion.identity);
			transform.position = spawn;
		}
	}

	void OnTriggerEnter(Collider other)
	{
		if (other.transform.tag == "Goal")
		{
			GameManager.CompleteLevel();
		}
	}
}

And I do not get any errors if that helps

Hi Sweps,

Is the game a 2D/2.5D/3D game as far as character moving? If you never want to access the Z axis, you can disable it in your rigidbody by “freezing” the rotation and transform by clicking the respective tick boxes.

There is a very good rigidbody controller in Unity’s new Beta Standard Assets pack too; you may be interested in checking that out and altering it for your purposes.

Good luck!