Trying to Add jump to this code.

Hey guys,
I got this code from the unity script reference and I’ve been trying to add Jump function to it, I cannot work out how. I tried using the adforece.up and also tried to use the other move direction from another reference i couldnt work it. Ive also looked everywhere online but cant find a way to do it, can anyone help me with this please?
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
    public float speed = 10.0f;
    public float rotationSpeed = 100.0f;
	public float jumpSpeed = 8.0f;
	public float gravity = 20.0f;
    void Update() {
        float translation = Input.GetAxis("Vertical") * speed;
        float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
        translation *= Time.deltaTime;
        rotation *= Time.deltaTime;
        transform.Translate(0, 0, translation);
        transform.Rotate(0, rotation, 0);
    }
}

Hi!

I assume that you are not using a character controller :wink:
you probably did not apply a force, big enough to move the object. Also use ForceMode.Impulse

public class Player : MonoBehaviour {
    public float speed = 10.0f;
    public float rotationSpeed = 100.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;
    public float jumpForce = 10000.0f; // This will be a very high jump ;P
    // or jumpSpeed (see below)

    void Update() {

       float translation = Input.GetAxis("Vertical") * speed;
       float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
       translation *= Time.deltaTime;
       rotation *= Time.deltaTime;
       transform.Translate(0, 0, translation);
       transform.Rotate(0, rotation, 0);

       // -
       if(Input.GetKeyDown(KeyCode.Space))
       {
          rigidbody.AddForce(transform.TransformDirection(Vector3.up) * jumpForce, ForceMode.Impulse);
       }

   }
}

you can also set a velocity to the rigidbody:

rigidbody.velocity += transform.TransformDirection(Vector3.up) * jumpSpeed;

note that you set jumpSpeed to something around 5-10 while jumpForce needs to be a much bigger value.