簡體   English   中英

如何使游戲對象向前跳躍?

[英]how to make gameobject jump forward?

嗨,我真的很陌生,想要一些幫助,我想知道如何使我的游戲對象向前跳躍(按住的時間越長,它會跳躍得越遠),我的游戲對象上有剛硬的身體以防萬一。

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. 

如果要使用剛體運動,則應對其施加力。 現在,您只是在移動對象的世界變換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM