2

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);
        }
    }
}
Dávid Florek
  • 552
  • 6
  • 17
Evgeny Gerbut
  • 390
  • 1
  • 4
  • 10
  • Try printing `vrCamera.eulerAngles.x` to the console in `Update`, in order to see if its value is indeed between 30 and 90. – Eldy Feb 13 '18 at 10:35
  • I debugged script. Code in "if" statement returns true; Line cc.SimpleMove() executes. – Evgeny Gerbut Feb 13 '18 at 10:45
  • Possible duplicate of [Unity GVR Cardboard Camera incorrect work on Android](https://stackoverflow.com/questions/43610722/unity-gvr-cardboard-camera-incorrect-work-on-android) – Ludovic Feltz Feb 13 '18 at 13:06

2 Answers2

2

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

Ludovic Feltz
  • 11,416
  • 4
  • 47
  • 63
  • Thanks a lot! I have already tried such approach and it works. Camera moves, but there is new problem: i expected each `Update()` method will change camera position: after `cc.SimpleMove()` called, the value `vrCamera.transform.forward` will be updated, thus when `Update()` called next time `vrCamera.transform.forward` will have new value. But for now `vrCamera.transform.forward` is always the same. So it looks like player just make 1 step and freeze. When `if()` statement equals to **false**, camera moves to its initial position. Do you have any ideas why it works like that? – Evgeny Gerbut Feb 13 '18 at 13:25
  • @EvgenyDes You can reference your camera and use his vector forward (eg: Camera.mainCamera.transform.foward) – Ludovic Feltz Feb 13 '18 at 13:28
1

Try this. Your TransformDirection probably returns wrong vector.

Vector3 forward = vrCamera.transform.forward;
cc.SimpleMove(forward * speed);
Dávid Florek
  • 552
  • 6
  • 17