首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何跳入2.5D的世界?

如何跳入2.5D的世界?
EN

Stack Overflow用户
提问于 2015-04-16 13:37:24
回答 3查看 1.1K关注 0票数 1

我对Unity (以及一般的游戏开发)完全陌生。我遵循了很棒的简单教程Survival Shooter,我有一个问题:在这个教程中,我们将Y约束位置添加到刚体的角色,并将阻力值和角度阻力值设置为无穷大。既然这些设置阻止了角色移动到Y轴,我们如何才能使角色跳跃?

如果有人能帮我一把的话...

非常感谢!

EN

回答 3

Stack Overflow用户

发布于 2015-04-16 14:02:50

为什么要在Y轴上添加约束?你可以去掉它,然后添加重力,让你的球员贴近地面。在那之后,只需施加一个力,或者只是简单的平移,以设定的速度向上移动,让玩家跳跃,然后等待重力将他带回地面。

票数 0
EN

Stack Overflow用户

发布于 2017-04-12 20:56:33

这就是我跳下去要做的事情。

附注:您需要删除矢量上Y轴上的约束

代码语言:javascript
复制
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 
        }
    }

}
票数 0
EN

Stack Overflow用户

发布于 2017-11-30 22:51:21

我会这样做,而不是在这篇文章中编辑代码。

代码语言:javascript
复制
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;
    }

}

你需要给你的地面物体分配一个叫做地面的标签,你需要创建一个你自己的标签,叫做地面,这并不难,你点击你的物体,然后在检查器的左上角有一个标签,然后你只需要创建一个新的标签,叫做地面。也请记住将其他值赋给您的player对象。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29666136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档