Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 如何跳入2.5D世界?_Unity3d_Physics_2.5d - Fatal编程技术网

Unity3d 如何跳入2.5D世界?

Unity3d 如何跳入2.5D世界?,unity3d,physics,2.5d,Unity3d,Physics,2.5d,我对Unity和游戏开发是全新的。我遵循了伟大的简单教程,我有一个问题:在本教程中,我们将Y约束位置添加到刚体的角色,并将阻力值和角度阻力值设置为无穷大。既然这些设置阻止角色移动到Y轴,我们如何使角色跳跃 如果有人能帮我,请 非常感谢 为什么要在Y轴上添加约束?你可以移除它,然后增加重力,让你的球员粘在地上。在那之后,只需施加一个力,或者只是一个简单的平移,以设定的速度向上移动,让玩家跳跃,然后等待重力把他拉下来 这就是我要跳的动作。 另外,您需要删除向量上Y轴上的约束 using System

我对Unity和游戏开发是全新的。我遵循了伟大的简单教程,我有一个问题:在本教程中,我们将Y约束位置添加到刚体的角色,并将阻力值和角度阻力值设置为无穷大。既然这些设置阻止角色移动到Y轴,我们如何使角色跳跃

如果有人能帮我,请


非常感谢

为什么要在Y轴上添加约束?你可以移除它,然后增加重力,让你的球员粘在地上。在那之后,只需施加一个力,或者只是一个简单的平移,以设定的速度向上移动,让玩家跳跃,然后等待重力把他拉下来

这就是我要跳的动作。 另外,您需要删除向量上Y轴上的约束

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    public Vector3 force;
    public Rigidbody rb;


    // Use this for initialization
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Space) && transform.position.y == 0) //Enter your y axix where ground is located or try to learn a little more about raycasting ill just use 0 for an example)
        {
            rb.AddForce(force);//Makes you jump up when you hold the space button down line line 19 will do so that you only can jump when you are on the ground.  

        } if (Input.GetKeyUp(KeyCode.Space))
        {
            rb.AddForce(-force); //When you realase the force gets inverted and you come back to ground 
        }
    }

}
我会这样做,而不是编辑这篇文章的代码。
你需要为你的地面对象指定一个名为地面的标记,你需要自己制作一个名为地面的标记。这并不难,只要你点击你的对象,在检查器的左上角有一个标记,然后你就可以制作一个名为地面的新标记。还请记住在玩家对象上指定其他值。

我试图删除Y约束,但由于阻力和角度阻力值设置为无穷大,我无法应用任何向上的力。一个解决方案是为阻力和角度阻力设置一个值,并在按下跳转按钮时删除Y约束,然后在接地时重置这些值,但不确定这是否是最佳解决方案……这里的问题是,为什么要添加所有这些约束?有没有什么特别的原因让你需要在你的播放器上设置这些严格的属性?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Just : MonoBehaviour {

    public Vector3 force;
    public Rigidbody rb;
    bool isGrounded;

  
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true) //Rember to got to your "Ground" object and tag it as Ground else this would not work 
        {
            rb.AddForce(force);
        }       
    }
     void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Ground")
        {
            isGrounded = true;
        }
    }
     void OnCollisionExit(Collision collision)
    {
        isGrounded = false;
    }

}