【问题标题】:how to make gameobject jump forward?如何让游戏对象向前跳跃?
【发布时间】:2015-08-02 19:12:58
【问题描述】:

嗨,我真的是新手,需要一些帮助,我想知道如何让我的游戏对象向前跳跃(你握得越久,它就会跳跃得越远),我有一个刚体我的游戏对象已经存在,以防万一。

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);
}

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

【问题讨论】:

    标签: c# unity3d gameobject


    【解决方案1】:
    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. 
    

    如果您想使用刚体进行移动,您应该对其施加力。现在您只是在移动对象的世界变换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多