如何让游戏对象向前跳跃?

how to make gameobject jump forward?

嗨,我对此很陌生,希望得到一些帮助,我想知道如何让我的游戏对象向前跳跃(你坚持的时间越长,它就会跳得越远),我有一个刚性body 已经放在我的游戏对象上以防万一。

public class PlayerScript : MonoBehaviour {

public float speed;

private Vector3 dir;

// Use this for initialization
void Start () 
{
    dir = Vector3.zero;
}

// Update is called once per frame
void Update () 
{
    if (Input.GetMouseButtonDown(0)) 
    {
        if (dir == Vector3.forward)
        {
            dir = Vector3.right;
        }
        else 
        {
            dir = Vector3.forward;
        }

    }

    float AmToMove = speed * Time.deltaTime;
    transform.Translate (dir * AmToMove);
}

到目前为止,我只能让它向前和向右移动,但我希望它向前跳和向右跳。

public float thrust;
        public Rigidbody rb;
        void Start() {
            rb = GetComponent<Rigidbody>();
        }
        void FixedUpdate() {
            rb.AddForce(transform.up * thrust);
        }
//This will add a force to the rigidbody upwards. 

如果你想使用刚体来移动你应该给它施加一个力。现在您只是在移动对象的世界变换。