Reputation: 4291
How to add first person character controller in google cardboard so that it moves forward in continuous direction? I know it is stupid question but since I am new and actually made a simple cardboard game just few hours ago.I am not getting how to add first person controller script to my google card board game?
Upvotes: 2
Views: 4460
Reputation: 370
Actually you just insert the GvrViewerMain.prefab in the scene, this prefab change all your cameras in Stereoscopic rendering, u just need put ur FPSController and modify the 101 line in script FirsPersonController.cs inside him.
Change this line
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;//MODIFIED TO WALK FOR EVER
U just need replace m_Input.y by Time.deltaTime, like this.
Vector3 desiredMove = transform.forward*Time.deltaTime + transform.right*m_Input.x;//MODIFIED TO WALK FOR EVER
more clean solution:
Add a camera in your scene, add a characterController component.; Add a new script inside the camera:
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = transform.TransformDirection(Vector3.forward);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
Upvotes: 1
Reputation: 365
Here is a AutoWalk.cs script from github that I personally use to make my character walk. This script makes the camera (and the binded character) move forward with a simple head tilt or magnet trigger. https://github.com/JuppOtto/Google-Cardboard/blob/master/Autowalk.cs
NOTE: The code in github is for Google Cardboard SDK. So you will have to modify it a little bit if you want to make it compatible to the latest Google VR SDK (few variable name changes).
This is however a temporary fix that I recommend as we wait for Google to release DayDream
Upvotes: 4