- Home /
Look and walk in VR unity 5.6.6
Hi. I'm using unity 5.6 and googleVR 1.0v. This is script written below, i want to move forward when i look down while player rotation.x is greater than or equal to 30f and less than 90f.
When i look down and rotation.x goes to greater than 30f, my player is start moving down instead of moving forward.
I created an empty object and make it the parent of main Camera. This script is attached to the main camera and character controller is on the parent GameObject.
public Transform VR;
public float toggleAngle = 30f;
public float speed = 3.0f;
public bool moveForword;
public CharacterController cc;
void Start()
{
cc = GetComponentInParent<CharacterController> ();
}
void Update()
{
if (VR.eulerAngles.x > toggleAngle && VR.eulerAngles.x < 90f) {
moveForword = true;
} else
moveForword = false;
if (moveForword) {
Vector3 move = VR.TransformDirection (Vector3.forward);
cc.SimpleMove (move * speed);
}
}
Answer by Strixie13 · Jul 15, 2018 at 11:25 PM
Try making a reference to the character controller in update instead of just at start. so cc = GetComponentInParent<CharacterController>();
should be in update not start (according to the API documentation).
Also check line 17. I don't think it's giving you the forward vector you want. if "VR" is your empty parent object, then using its forward would always give the same direction since it is the camera that would be rotating. maybe Vector3 move = gameObject.TransformDirection(Vector3.forward)
.
Your answer
Follow this Question
Related Questions
Configure Unity to build in both iOS and Android 0 Answers
Strange Raycasting Behaviour in VR 0 Answers
PC controller work with android 0 Answers
Unity on Gear VR with Galaxy S6 2 Answers
Video textures appearing white in Samsung Gear Vr Android unity 0 Answers