博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
摄像机平滑更随脚本
阅读量:6986 次
发布时间:2019-06-27

本文共 1924 字,大约阅读时间需要 6 分钟。

hot3.png

This camera smoothes out rotation around the y-axis and height.Horizontal Distance to the target is always fixed.There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.For every of those smoothed values we calculate the wanted value and the current value.Then we smooth it using the Lerp function.Then we apply the smoothed values to the transform's position.// The target we are followingvar target : Transform;// The distance in the x-z plane to the targetvar distance = 10.0;// the height we want the camera to be above the targetvar height = 5.0;// How much we var heightDamping = 2.0;var rotationDamping = 3.0;// Place the script in the Camera-Control group in the component menu@script AddComponentMenu("Camera-Control/Smooth Follow")function LateUpdate () {    // Early out if we don't have a target    if (!target)        return;    // Calculate the current rotation angles    wantedRotationAngle = target.eulerAngles.y;    wantedHeight = target.position.y + height;    currentRotationAngle = transform.eulerAngles.y;    currentHeight = transform.position.y;    // Damp the rotation around the y-axis    currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);    // Damp the height    currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);    // Convert the angle into a rotation    currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);    // Set the position of the camera on the x-z plane to:    // distance meters behind the target    transform.position = target.position;    transform.position -= currentRotation * Vector3.forward * distance;    // Set the height of the camera    transform.position.y = currentHeight;    // Always look at the target    transform.LookAt (target);}

转载于:https://my.oschina.net/u/698044/blog/546591

你可能感兴趣的文章
BZOJ 1061: [Noi2008]志愿者招募【单纯形裸题】
查看>>
JVM上的随机数与熵池策略
查看>>
Java8并发教程:Threads和Executors
查看>>
v8世界探险(3) - v8的抽象语法树结构
查看>>
《C语言及程序设计》实践项目——用if语句实现分支结构
查看>>
“AI +跨界+技术” 看2018中国会展创新者大会的新观点
查看>>
JavaScript——数据类型转换(显式和隐式)
查看>>
【半月刊 4】前端高频面试题及答案汇总
查看>>
lc686. Repeated String Match
查看>>
RHEL 7.1操作系统安装过程说明
查看>>
基于Python的性能自动化测试框架设计思路和实现
查看>>
Spark里几个重要的概念及架构
查看>>
dubbo-rpc基本功能
查看>>
7月国内电脑分辨率TOP10 :1366*768跌破13%
查看>>
CefSharp获取网页源码时卡住长时间没有返回结果
查看>>
刚入门Python的小伙伴,这是腾讯大牛工作中总结的爬虫经验!
查看>>
智能微型机器人可随周围环境“变身”
查看>>
Linux操作系统 MBR扇区故障了怎么办
查看>>
Java网络编程基础(一)
查看>>
在Mac版本下的IDEA中设置代码注释模版
查看>>