Unity3D CharacterController 移动问题。相机位置没有改变
Unity3D CharacterController movement issue. Camera position not changed
我有一个问题,在 CharacterController.SimpleMove() 调用后主摄像头位置没有改变。任务是创建相机移动的场景。
我有带有角色控制器和脚本的主相机游戏对象。
问题是调用 SimpleMove() 后 vrCamera 位置没有任何变化。
我的问题是这段代码有什么问题。我建议 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);
}
}
}
试试这个。你的 TransformDirection 可能 returns 错误的向量。
Vector3 forward = vrCamera.transform.forward;
cc.SimpleMove(forward * speed);
VR Camera不能移动,SDK决定了mainCamera的位置。
为了移动您的相机,您只需创建一个新的 GameObject
作为您的 mainCamera
的父级,然后移动父级 GameObject
我有一个问题,在 CharacterController.SimpleMove() 调用后主摄像头位置没有改变。任务是创建相机移动的场景。
我有带有角色控制器和脚本的主相机游戏对象。
问题是调用 SimpleMove() 后 vrCamera 位置没有任何变化。
我的问题是这段代码有什么问题。我建议 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);
}
}
}
试试这个。你的 TransformDirection 可能 returns 错误的向量。
Vector3 forward = vrCamera.transform.forward;
cc.SimpleMove(forward * speed);
VR Camera不能移动,SDK决定了mainCamera的位置。
为了移动您的相机,您只需创建一个新的 GameObject
作为您的 mainCamera
的父级,然后移动父级 GameObject