简体   繁体   English

Unity3D CharacterController运动问题。 相机位置未更改

[英]Unity3D CharacterController movement issue. Camera position not changed

I have a problem that main camera position doesn't change after CharacterController.SimpleMove() called. 我有一个问题,即在调用CharacterController.SimpleMove()之后,主摄像机位置不会更改。 The task is to create scene where camera moves. 任务是创建摄像机移动的场景。 I have Main Camera game object with Character Controller and Script attached. 我有带有“角色控制器”和“脚本”的Main Camera游戏对象。 The issue is that nothing in vrCamera position changed after SimpleMove() called. 问题是在调用SimpleMove()之后,vrCamera位置没有任何变化。
My question is what is wrong in this code. 我的问题是这段代码有什么问题。 I suggest something wrong with binding between MainCamera object and CharacterController component, but I have spend a lot of time investigating and nothing working found. 我建议MainCamera对象和CharacterController组件之间的绑定有问题,但是我花了很多时间进行调查,但没有发现任何问题。

在此处输入图片说明

using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class VRLookWalk : MonoBehaviour {

    public Transform vrCamera;

    public float toggleAngle = 30.0f;
    public float speed = 3.0f;
    public bool moveForwad;
    private CharacterController cc;

  // Use this for initialization
  void Start () {
        cc = vrCamera.GetComponent<CharacterController>();
  }

  // Update is called once per frame
  void Update () {
        if (vrCamera.eulerAngles.x >= toggleAngle && vrCamera.eulerAngles.x < 90.0f)
        {
            Vector3 forward = vrCamera.TransformDirection(Vector3.forward);
            cc.SimpleMove(forward * speed);
        }
    }
}

You can't move the VR Camera, it's the SDK that determine the mainCamera position. 您无法移动VR摄像机,而是由SDK决定mainCamera的位置。

In order to move your camera you can just make a new GameObject as a parent of your mainCamera then move the parent GameObject 为了移动您的相机,您可以只创建一个新GameObject mainCamera作为mainCamera的父mainCamera然后移动父GameObject

Try this. 尝试这个。 Your TransformDirection probably returns wrong vector. 您的TransformDirection可能返回错误的向量。

Vector3 forward = vrCamera.transform.forward;
cc.SimpleMove(forward * speed);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM