问题:

怎么让当手指滑动的同时对应的模型发生旋转

解决办法:

1:通过控制摄像机或者模型来实现效果

2:通过获取鼠标移动时X轴Y轴的偏移量来确定模型的旋转角度

3:为了不让人感觉到突兀,建议使用Mathf.SmoothDamp方法实现角度的改变

实现代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class ChinarSmoothUi3DCamera : MonoBehaviour { public Transform point;
private Vector3 Tras = Vector3.zero; public float distance = 10.0f;
public float minDistance = 2f;
public float maxDistance = 15f;
public float zoomSpeed = 1f;
public float xSpeed = 250.0f;
public float ySpeed = 250.0f;
public bool allowYTilt = true;
public float yMinLimit = -90f;
public float yMaxLimit = 90f; private float x = 0.0f;
private float y = 0.0f;
private float targetX = 0f;
private float targetY = 0f;
public float targetDistance = 0f;
private float xVelocity = 1f;
private float yVelocity = 1f;
private float zoomVelocity = 1f;
void Start () { Vector3 tange = transform.eulerAngles;
targetX = x = tange.x;
//targetY = y = ClampAngle(tange.y, yMinLimit, yMaxLimit);
targetDistance = distance; } // Update is called once per frame void LateUpdate() {
if(point==null)
{
return;
}
if(Input.GetAxis("Mouse ScrollWheel")>0)
{
targetDistance -= zoomSpeed;
}
if(Input.GetAxis("Mouse ScrollWheel")<0)
{
targetDistance += zoomSpeed;
}
targetDistance = Mathf.Clamp(targetDistance, minDistance, maxDistance);
if(Input.GetMouseButton(1))
{ targetX+= Input.GetAxis("Mouse X") * xSpeed * 0.02f;
if (allowYTilt)
{
//targetY -= Input.GetAxis("Mouse Y") * xSpeed * 0.02f;
//targetY= ClampAngle(targetY, yMinLimit, yMaxLimit);
}
}
x = Mathf.SmoothDampAngle(x, targetX, ref xVelocity, 0.3f);
//y = allowYTilt ? Mathf.SmoothDampAngle(y, targetY, ref yVelocity, 0.3f) : targetY;
//Quaternion rotation = Quaternion.Euler(y, x, 0);
Quaternion rotation = Quaternion.Euler(0, x, 0);
distance = Mathf.SmoothDamp(distance, targetDistance, ref zoomVelocity, 0.5f);
Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + point.position + Tras;
transform.rotation = rotation;
transform.position = position; } public float ClampAngle(float angle,float min,float max)
{
if(angle>360)
{
angle -= 360;
}
if(angle<-360)
{
angle += 360;
}
return Mathf.Clamp(angle, min, max);
}
}

  

模拟人的手指在UI上滑动时3D模型跟随着移动(Unity)的更多相关文章

  1. Android ScrollView里嵌套RecyclerView时,在RecyclerView上滑动时出现卡顿(冲突)的现象

    最近在项目中遇到一个现象,一个界面有一个RecyclerView(GridView型的),外面套了一层ScrollView,通过ScrollView上下滚动,但是在滑动的时候如果是在RecyclerV ...

  2. Mask裁切UI粒子特效或者3D模型

    刚好前几天有人问我这个问题,再加上新项目也可能用,所以这两天就研究了一下.其实如果粒子特效 和3D模型 都用RenderTexture来做的话就不会有裁切的问题,但是粒子特效用RenderTextur ...

  3. 【安卓】给gallery内&quot;控件&quot;挂载事件,滑动后抬起手指时也触发事件(滑动时不应触发)的解决、!

    思路: 1.gallery内控件挂载事件(如:onClickListener)的方法类似listview,可直接在baseAdapter.getView内给控件挂载(详细方法百度). 2.貌似没问题, ...

  4. Unity在UI界面上显示3D模型/物体,控制模型旋转

    Unity3D物体在UI界面的显示 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...

  5. Flash Stage3D 在2D UI 界面上显示3D模型问题完美解决

    一直以来很多Stage3D开发者都在为3D模型在2DUI上显示的问题头疼.Stage3D一直是在 Stage2D下面.为了做到3D模型在2DUI上显示通常大家有几种实现方式,下面来说说这几种实现方式吧 ...

  6. Unity3D_UGUI判断鼠标或者手指是否点击在UI上

    比如战斗场景,UI和3D场景同时都需要响应触摸事件,如果同时响应可能就会出现触摸UI的时候影响到了3D部分.为了解决这个问题在判断3D响应之前要先判断手指是否点击在UI上. 以前NGUI的时候都是自己 ...

  7. Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏

    效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  8. 结合 CSS3 & Canvas 模拟人行走的效果

    HTML5 和 CSS3 技术给 Web 带来了新的利器,点燃了 Web 开发人员的激情.所谓只有想不到,没有做不到,的确如此.下面给大家分享一个结合 CSS3 & Canvas 模拟人行走的 ...

  9. unity区分点击在3D物体还是2D UI上

    当场景中的3D物体需要响应点击,但同时有UI显示时,存在判断点击是在3D物体上还是UI上的问题,办法如下: 1. 射线检测所有2D 3D物体,有2D物体被检测到时表明当前有UI.但无论Physics2 ...

随机推荐

  1. hdu_1049_Climbing Worm_201311061331

    Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. K - Count the string kmp_Next数组应用

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  3. code vs 3376 符号三角形

    3376 符号三角形  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 如下图是由14个“+”和14个“-”组 ...

  4. RDS for MySQL 通过 mysqlbinlog 查看 binlog 乱码

    问题描述: 使用 mysqlbinlog -vv mysql-bin.000110 查看 RDS mysql 二进制文件发现类似如下结果: BINLOG ' MgI+UA8BAAAAZwAAAGsAA ...

  5. 解释为什么word2vec也被称作deep learning

    作者:orangeprince链接:https://www.zhihu.com/question/27689129/answer/39117725来源:知乎著作权归作者所有.商业转载请联系作者获得授权 ...

  6. [Angular] Why should we using Protal

    Origianl article Protal from Angular CDK, is a way to create dynammic component. Consider an example ...

  7. 《鸟哥的Linux私房菜-基础学习篇(第三版)》(五)

    第4章 安装CentOS 5.x与多重引导小技巧        1. 本练习机的规划(尤其是分区參数)        分了四个分区: 1)/boot:primary 2)/:primary 3)/ho ...

  8. javascript 获取当前对象

    <a href="dsfjlsdjf" onclick="testGet()"> 请教编写testGet()函数获取这个超链接href属性,限制例如 ...

  9. B1270 [BeijingWc2008]雷涛的小猫 dp

    这个题的原始方法谁都会,但是n^3会T.之后直接优化,特别简单,就是每次处理出来每层的最大值,而不用枚举.之前没这么做是因为觉得在同一棵树的时候没有下落,所以不能用这个方法.后来想明白了,在同一棵树上 ...

  10. 杂项:ESB接口

    ylbtech-杂项:ESB接口 ESB全称为Enterprise Service Bus,即企业服务总线.它是传统中间件技术与XML.Web服务等技术结合的产物.ESB提供了网络中最基本的连接中枢, ...