关于unity3d模型的重力感应,在这里我们使用unity引擎提供的Input.acceleration重力感应;

例如:
public Transform m_round;
Transform trans;
//小球在屏幕的最大范围
float cross_x=0;
float cross_y=0;
float cross_z=0;
float m_x=0;
float m_y=0;
Vector3 screenpioint;
// Use this for initialization
void Start () {
trans = ( Transform ) Instantiate ( m_round, m_round.position, Quaternion.identity );
m_x= trans.GetComponent ( ).mesh.bounds.size.x * trans.localScale.x;
m_y = trans.GetComponent ( ).mesh.bounds.size.y * trans.localScale.y;
cross_x = Screen.width - m_x;
cross_y = Screen.width - m_y;
}
void OnGUI ( )
{
//整体显示x,y,z的重力分量
GUI.Label ( new Rect ( 0, 0, 400, 200 ), "position is" + Input.acceleration + "--x" + trans.GetComponent ( ).mesh.bounds.size.x * trans.localScale.x + "--" + trans.GetComponent ( ).mesh.bounds.size.y * trans.localScale.y );
GUI.Label ( new Rect ( 2, 30, 400, 200 ), "screenpioint.x is" + screenpioint.x + "screenpioint.y is" + screenpioint.y );
}
// Update is called once per frame
void Update () {
// 根据重力分量修改小球的位置
screenpioint=Camera.main.WorldToScreenPoint ( trans.position );
screenpioint.x += Input.acceleration.x * 100 * Time.deltaTime;
screenpioint.y -= Input.acceleration.y * 100 * Time.deltaTime;
if (screenpioint.x <= m_x*2)
screenpioint.x = m_x*2;
if (screenpioint.y <=m_y*2)
screenpioint.y = m_y*2;
if (screenpioint.x >= cross_x)
screenpioint.x = cross_x;
if (screenpioint.y >= cross_y)
screenpioint.y = cross_y;
trans.position = Camera.main.ScreenToWorldPoint ( screenpioint );
}

快来试试吧,哇咔咔!

Unity3D模型重力感应相关推荐

  1. Unity3D 游戏引擎之平面小球重力感应详解【转】

    http://blog.csdn.net/xys289187120/article/details/6969333       手机重力感应应该对大多数开发者并不陌生,在新一代智能手机Android  ...

  2. 如何 DIY 一款属于自己的【3D 重力感应 动态壁纸 】,看完这篇文章你也可以学会

    文章目录 ??前言 ??Unity实战篇 | unity制作动态壁纸,一款支持 DIY的[重力感应 的 3D动态壁纸] 制作过程 ??新建一个Unity工程,导入壁纸插件 ??导入Unity的模型素材 ...

  3. Cocos2d-x3.2 重力感应

    为什么80%的码农都做不了架构师?>>>    //GameScene.h#include "cocos2d.h"USING_NS_CC;class GameSc ...

  4. Kinect for windows的重力感应和角度马达

    上图是Kinect的重力感应方向图,Kinect右边为X正方向,最大值为1,反方向为-1,Kinect下方为Y正方向,最大值为1,反方向为-1,Kinect后面为Z正方向,最大值为1,反方向为-1. ...

  5. 重力感应的测试程序andriod源代码

    2019独角兽企业重金招聘Python工程师标准>>> 重力感应的测试程序andriod源代码,不多说了适合初学者,界面需要改进 转载:http://www.adobex.com/a ...

  6. 重力感应机制和手机的屏幕绘画

    2019独角兽企业重金招聘Python工程师标准>>> 摘要: 利用手机的重力感应机制和手机的屏幕绘画功能,实现一款躲避休闲游戏. 实现平台,工具: 采用java ADT工具,jav ...

  7. Windows Phone 7(accelerometer)重力感应编程

    使用重力感应器accelerometer,需要引用类库Microsoft.Devices.Sensors ,所以需要在WMAppManifest.xml 加上  <Capability Name ...

  8. android小游戏模版—重力感应

    好久没更新博客了,今天来谈谈android小游戏---重力感应,一般在游戏里运用的比較多,比方这类游戏有:神庙逃亡.极品飞车,平衡球.三围重力迷宫,重力赛车等. 首先什么是重力感应.重力感应是指如今手 ...

  9. Android重力感应示例

    android中的很多游戏的游戏都使用了重力感应的技术,就研究了一下重力感应 以屏幕的左下方为原点,箭头指向的方向为正.从-10到10,以浮点数为等级单位,想象以下情形: 手机屏幕向上(z轴朝天)水平 ...

最新文章

  1. python subprocess_python subprocess
  2. java comparable接口作用_Java 中 Comparable 接口的意义和用法
  3. ubuntu通过apt-get方式搭建lnmp环境以及php扩展安装
  4. Python Socket Programming
  5. Shell 前后台任务
  6. HDU 4288 Coder [线段树]
  7. ExtJS 4.2 教程-07:Ext.Direct
  8. 05-windows下SQL Developer连接Orcale
  9. 为什么学前端不先学框架?
  10. 你真的理解反向传播吗?面试必备
  11. Quartus 与modelSim联合仿真常见错误以及系统任务$readmemb和$readmemh解释
  12. 解决windows下使用pycharm的anaconda安装numpy或tensorflow不成功的问题
  13. matlab 好看的颜色代码,科学网—什么是好的颜色表(colormap)? - 雷朝阳的博文...
  14. 如何部署局域网即时通讯软件
  15. 医院在线问诊小程序开发制作
  16. Android人脸支付功能,人脸支付是未来吗?盘点安卓人脸支付手机,小米看后很尴尬…...
  17. echarts散点图使用(转:http://www.suchso.com/UIweb/echarts-sandiantu.html)
  18. 精心整理的ebay大数据面试题(全)
  19. 关于数据库连接IDEA报错
  20. 干货| 生鲜电商的冷库内部该怎么设计(含案例)

热门文章

  1. SSL/TLS 的工作原理
  2. muduo Timestamp详解
  3. 【软考高项笔记】第3章 信息系统治理(针对甲方)3.2 IT审计
  4. 短视频怎么精准定位,哪种定位方式涨粉变现快?丨国仁网络
  5. java学生课程设计报告,Java课程设计报告学生管理系统
  6. 在IDEA编写Shell脚本
  7. Java 实现sequence
  8. 微型计算机原理思维导图
  9. 新浪付稳:揭秘微博如何10分钟快速应对百亿级访问量
  10. python panda 库 累积分布,Python Pandas:使用滚动回溯窗口计算累计总和