this code below represents my character movement, how would I make the player only be able to move along X axis, but only down the Z axis?
var xMove : float = Input.GetAxis("Horizontal") * Time.deltaTime * 2;
transform.Translate( xMove , 0 , 0 );
var zMove : float = Input.GetAxis("Vertical") * Time.deltaTime * 2;
transform.Translate( 0 , 0 , zMove );
Thank you.
Well, what’s happening in this line:
var zMove : float = Input.GetAxis("Vertical") * Time.deltaTime * 2;
is that you’re getting data from the vertical axis and that can range from -1 to 1 (for down and up respectively). If you only want to allow movement when you detect the negative end of the axis’ input, use an if statement like:
if(Input.GetAxis("Vertical")<1){
var zMove : float = Input.GetAxis("Vertical") * Time.deltaTime * 2;
transform.Translate( 0 , 0 , zMove );
}
that way, your zMove will only be altered when you get a negative axis input.