My Player flys off away through the X axis when I press play.

What’s going on? I want the player to be able to move the x and Z and jump, but I’ve had some trouble getting the Z to work.

@script RequireComponent(Rigidbody); //forces this gameObject to also have a rigibody component
//public variables
var maxAirJumpCount : int = 1; // 1 for a double jump
var normalJumpForce : float = 8; //strength of the normal jump's impulse
var airJumpForce : float = 8; //strength of the double jump's impulse
var raycastDistance : float = 1; //distance between the characters origin and the ground, 1 for a 2m high character
var xSpeed : float = 5; // horizontal speed of the character\

var zSpeed : float = 5; //zspeed
/* These values are all ideal settings that worked for me */
//private variables
private var airJumpCount : int = 0; //how many more times can the player jump?
private var xMove : float; // horizontal input (Input.GetAxisRaw("Horizontal")) *
                            // horizontal speed modifier (xSpeed)
private var isGrounded : boolean = false; //is the player on the ground?
function Update() {
    if(Physics.Raycast(transform.position, -Vector3.up, raycastDistance)) {
        isGrounded = true;
        airJumpCount = maxAirJumpCount;
    else {
        isGrounded = false;
    if(Input.GetKeyDown(KeyCode.Space)) {
        if(isGrounded) {
        else if(airJumpCount > 0) {
            airJumpCount -= 1;
    xMove = 0;
    xMove = Input.GetAxisRaw("Vertical") * xSpeed;
        z = Input.GetAxisRaw("Horizontal") * zSpeed; 
function FixedUpdate () {
function JumpNormal () { rigidbody.AddForce(Vector3.up * normalJumpForce, ForceMode.Impulse); }
function JumpInAir () { rigidbody.AddForce(Vector3.up * airJumpForce, ForceMode.Impulse); }

I can’t see how you use z variable in your code. Looks like it should be used in Translate().
Are you sure you really wish to make such translate:


It does nothing.

First you don’t need to do this:

xMove = 0;

The function for getting the axis will return 0 if nothing is being pressed so you don’t really need it.

Next you’re using transform.Translate which you don’t want to do if you’re moving with physics so you can take out the line:


What you’re really interested in is this:

function FixedUpdate () {

this line is what is actually moving your player, so you want to do a similar thing with the z, so since you’re using the vertical axis I’m assuming you want to move forward and backward with the z axis. This would be the line to add inside of FixedUpdate():


This will move forward or backward.