Unity3D 陀螺仪两种方法
来源:互联网 发布:素描教学软件下载 编辑:程序博客网 时间:2024/06/05 05:19
//01 Gyroscope gyro; Quaternion quatMult; Quaternion quatMap; GameObject player; GameObject camParent; void Awake() { player = GameObject.Find("Player"); // find the current parent of the camera's transform Transform currentParent = transform.parent; // instantiate a new transform camParent = new GameObject("camParent"); // match the transform to the camera position camParent.transform.position = transform.position; // make the new transform the parent of the camera transform transform.parent = camParent.transform; // make the original parent the grandparent of the camera transform //camParent.transform.parent = currentParent; // instantiate a new transform GameObject camGrandparent = new GameObject("camGrandParent"); // match the transform to the camera position camGrandparent.transform.position = transform.position; // make the new transform the parent of the camera transform camParent.transform.parent = camGrandparent.transform; // make the original parent the grandparent of the camera transform camGrandparent.transform.parent = currentParent; //gyroBool = true; //if (gyroBool) { gyro = Input.gyro; gyro.enabled = true; camParent.transform.eulerAngles = new Vector3(90, 0, 0); quatMult = new Quaternion(0, 0, 1, 0); } void Update() { quatMap = new Quaternion(gyro.attitude.x, gyro.attitude.y, gyro.attitude.z, gyro.attitude.w); Quaternion qt = quatMap * quatMult; transform.localRotation = qt; } // 两种方法 ----------------------- 02 bool draw = false; bool gyinfo; Gyroscope go; void Start() { gyinfo = SystemInfo.supportsGyroscope; go = Input.gyro; go.enabled = true; } void Update() { if (gyinfo) { Vector3 a = go.attitude.eulerAngles; a = new Vector3(-a.x, -a.y, a.z); //直接使用读取的欧拉角发现不对,于是自己调整一下符号 this.transform.eulerAngles = a; this.transform.Rotate(Vector3.right * 90, Space.World); } }
阅读全文
0 0
- Unity3D 陀螺仪两种方法
- Unity3d 陀螺仪
- Unity3D 陀螺仪
- Unity3D纹理旋转两种实现方法
- unity3d 陀螺仪代码
- Unity3d获取、校准陀螺仪
- Unity3d陀螺仪看全景图
- Unity3d通过苹果和google两种方法加入广告
- Unity3d通过苹果和google两种方法加入广告
- Unity3D获取web数据的两种方法
- 在Unity3D中加载外部图片的两种方法
- 在Unity3D中加载外部图片的两种方法
- 在Unity3D中加载外部图片的两种方法
- 在Unity3D中加载外部图片的两种方法
- 在Unity3D中加载外部图片的两种方法
- Unity3D开发学习之路--两种在Unity3D中创建倒计时器的方法
- Unity3D 陀螺仪控制摄像头脚本 GyroController
- Unity3D中手机陀螺仪的使用
- leofs 安装部署
- ejs模板使用:Layout,Blocks,Partials
- 打开.class文件的方法
- 爱测未来移动-Android静默安装
- Mybatis--使用mybatis generator插件映射数据库,自动生成pojo对象,dao接口,mapper.xml文件的方法
- Unity3D 陀螺仪两种方法
- 了解和使用Android神器Xposed框架
- 数据压缩原理实验6_MPEG音频编码
- Java:String和Date、Timestamp之间的转换
- Leetcode-599.Minimum Index Sum of Two Lists
- Mac的最大连接数限制和端口的相关参数的设置
- ORA-28001错误
- Java多线程中实现原子操作的方法
- H2 数据库,进程死锁导致访问异常的问题