现在VR游戏这么火,我也来赶个潮流,把游戏改成了VR游戏,并且用同事公司的设备试玩了一下,还不错,不过一些细节需要优化,
相关设备Oculus Rift DK2,
怎么改,看要求,好歹弄个样子那简单,把摄像机的相机跟随取消了,然后把相机拖到坦克里就好了,这样两者是一体了,调整好相机的位置,运行后的视角就一样了,
但是!但是!但是!,再完美一点,我想让坦克跟着我脑袋的移动左右旋转,咋办,那就要在代码上改变了
using UnityEngine;
using System.Collections;
public class TanksMove : MonoBehaviour {
public float speed = 5;
public float angularSpeed = 5;
private Rigidbody rigidbody;
private Vector3 temp = Vector3.zero;
// Use this for initialization
void Start () {
rigidbody = this.GetComponent<Rigidbody> ();
}
void Update(){
//float v = Input.GetAxis("Vertical");
//rigidbody.velocity = transform.forward * v * speed;
//float h = Input.GetAxis("Horizontal");
//rigidbody.angularVelocity = transform.up * h * angularSpeed;
//float h = Input.GetAxis("Horizontal");
//temp += new Vector3(0, h, 0);
//Camera.main.transform.rotation = Quaternion.Euler(temp);
transform.Translate(transform.TransformDirection(Vector3.forward*1.5f) * Time.deltaTime,Space.World);
float y = Camera.main.transform.localRotation.eulerAngles.y;
//获取头盔的旋转角度
transform.rotation = Quaternion.Euler(0, y, 0);
}
void LateUpdate()
{
}
}