Move only x axis

Hi, how can I move my character only in x axis?..I have character controller and rigidbody on my player and now I want to add script that allows to move only in x-axis…I don’t want to make my character rotate only move in X-axis.

You did not provide any real information other than you want it to move in the X-axis-direction, so I’ll have to work with what I got.

var moveSpeed = 5.0;

function Update (){ 
    transform.position.x += moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; 
}

Very simple and basic, but maybe that’ll be enough.

If you already have your script that moves the character and you want to lock rotation axis and/or movement axis, then you can do this on the rigidbody itself within the inspector window. Rigidbody has constraints built in, so if you want to completely freeze any rotation & only allow movement on x, tick x, y & z in freeze rotation and tick y & z in freeze position.
If it’s a script you’re after then the simple one OrangeLightning provided will do the trick.
rigidbody constraints

So, i also want this (only allow the character to move along the x AND y axis.) but i add Rigidbody, and i open constraints and nothing happens when i check those boxes?!