【问题标题】:Moving forward in cardboard using first person controller script使用第一人称控制器脚本在纸板中前进
【发布时间】:2016-05-26 10:57:02
【问题描述】:

如何在 google cardboard 中添加第一人称角色控制器,使其沿连续方向前进? 我知道这是个愚蠢的问题,但由于我是新手,实际上在几个小时前制作了一个简单的纸板游戏。我不知道如何将第一人称控制器脚本添加到我的谷歌卡片棋盘游戏中?

【问题讨论】:

    标签: unity3d google-cardboard


    【解决方案1】:

    这是一个来自 github 的 AutoWalk.cs 脚本,我个人用它来让我的角色行走。该脚本通过简单的头部倾斜或磁铁触发器使相机(和绑定的角色)向前移动。 https://github.com/JuppOtto/Google-Cardboard/blob/master/Autowalk.cs

    注意:github 中的代码适用于 Google Cardboard SDK。所以你会有 如果你想让它与 最新的 Google VR SDK(变量名称更改很少)。

    不过,我建议在等待 Google 发布 DayDream 时进行临时修复

    【讨论】:

    • 如何检测与某些对象的碰撞?
    • 您应该将其作为问题而不是评论提出。在游戏对象的检查器面板中,在该对象(立方体、球体或胶囊)上添加“碰撞器”组件。将其 isTrigger 属性设置为 true。当任何物体接触时,调用两个函数 OnTriggerEnter 和 OnCollision。选择适合您的功能。
    • 太棒了!谢谢我一直在寻找这个真的很糟糕!
    【解决方案2】:

    其实你只是在场景中插入了GvrViewerMain.prefab,这个prefab改变了你所有的摄像机立体渲染,你只需要把你的FPSController和修改脚本FirsPersonController.cs的101行放在他里面。

    改变这一行

    Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;//MODIFIED TO WALK FOR EVER
    

    你只需要将 m_Input.y 替换为 Time.deltaTime,就像这样。

    Vector3 desiredMove = transform.forward*Time.deltaTime + transform.right*m_Input.x;//MODIFIED TO WALK FOR EVER
    

    更干净的解决方案:

    在你的场景中添加一个相机,添加一个 characterController 组件。 在相机内添加一个新脚本:

    using UnityEngine;
    using System.Collections;
    
    public class movement : MonoBehaviour {
    
        public float speed = 6.0F;
        public float jumpSpeed = 8.0F;
        public float gravity = 20.0F;
        private Vector3 moveDirection = Vector3.zero;
        void Update() {
            CharacterController controller = GetComponent<CharacterController>();
            if (controller.isGrounded) {
                moveDirection = transform.TransformDirection(Vector3.forward);
                moveDirection *= speed;
                if (Input.GetButton("Jump"))
                    moveDirection.y = jumpSpeed;
    
            }
            moveDirection.y -= gravity * Time.deltaTime;
            controller.Move(moveDirection * Time.deltaTime);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多