Unity陀螺仪功能
来源:互联网 发布:php print echo 区别 编辑:程序博客网 时间:2024/06/05 19:49
实现陀螺仪功能,旋转设备,摄像机跟随旋转
将下面脚本拖拽到摄像机上,打包为Android或iOS项目,在真机上测试即可
场景中要放一些模型,不然看不到效果
using UnityEngine; using System.Collections; public class AAA : MonoBehaviour { private const float lowPassFilterFactor = 0.2f; protected void Start() { //设置设备陀螺仪的开启/关闭状态,使用陀螺仪功能必须设置为 true Input.gyro.enabled = true; //获取设备重力加速度向量 Vector3 deviceGravity = Input.gyro.gravity; //设备的旋转速度,返回结果为x,y,z轴的旋转速度,单位为(弧度/秒) Vector3 rotationVelocity = Input.gyro.rotationRate; //获取更加精确的旋转 Vector3 rotationVelocity2 = Input.gyro.rotationRateUnbiased; //设置陀螺仪的更新检索时间,即隔 0.1秒更新一次 Input.gyro.updateInterval = 0.1f; //获取移除重力加速度后设备的加速度 Vector3 acceleration = Input.gyro.userAcceleration; } protected void Update() { //Input.gyro.attitude 返回值为 Quaternion类型,即设备旋转欧拉角 transform.rotation = Quaternion.Slerp(transform.rotation, Input.gyro.attitude, lowPassFilterFactor); } void OnGUI() { GUI.Label(new Rect(50, 100, 500, 20), "Label : " + Input.gyro.attitude.x + " " + Input.gyro.attitude.y + " " + Input.gyro.attitude.z); } }
阅读全文
0 0
- Unity陀螺仪功能
- Unity陀螺仪功能
- Unity陀螺仪
- Unity陀螺仪
- Unity陀螺仪
- unity陀螺仪
- Unity 陀螺仪。。哈哈。。。。
- unity 陀螺仪的脚本
- Unity陀螺仪应用
- unity陀螺仪参数详解
- Unity中陀螺仪控制
- 【Unity】Unity调用手机陀螺仪
- Unity 使用陀螺仪观察场景
- unity之陀螺仪和指南针
- Unity-陀螺仪控制Camera旋转
- Unity 根据手机陀螺仪做UI动态旋转移动的功能。像手游崩坏3里面流动的UI界面一样
- unity 只有一个方向旋转的陀螺仪
- 陀螺仪
- DOS黑窗口被选定导致tomcat项目访问不到
- composer windows安装,使用新手入门
- 剑指Offer_面试题41_和为s的两个数字 VS 和为s的连续正数序列
- RxTools一款强大实用的工具类集合
- 《Spring3实战》摘要(6)事务管理
- Unity陀螺仪功能
- ardupilot & px4 书写自己的app & drivers (二)
- Spring Boot学习--资源配置
- 670. Maximum Swap
- 正则表达式-速记理解技巧
- c/c++
- Vue.js-----轻量高效的MVVM框架,组件利用Props传递数据)
- wordpress 修改博客文章标题字体大小
- JavaScript种==和===