小坦克改VR后续篇

这里写图片描述

现在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()
    {

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值