Search code examples
c#unity-game-enginevirtual-reality

Unity3D CharacterController movement issue. Camera position not changed


I have a problem that main camera position doesn't change after CharacterController.SimpleMove() called. The task is to create scene where camera moves. I have Main Camera game object with Character Controller and Script attached. The issue is that nothing in vrCamera position changed after SimpleMove() called.
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.

enter image description here

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);
        }
    }
}

Solution

  • You can't move the VR Camera, it's the SDK that determine the mainCamera position.

    In order to move your camera you can just make a new GameObject as a parent of your mainCamera then move the parent GameObject