摄像机视角优化
来源:互联网 发布:阿里云计算是什么 编辑:程序博客网 时间:2024/05/21 03:27
public GameObject target; public float ZoomSpeed = 30;//镜头缩放速率 public float MovingSpeed = 1;//镜头移动速率 public float RotateSpeed = 3; //镜头旋转速率 public float distance = 20;//设置距离角色的距离 public float ViewAngle = 30;//设置镜头斜视的角度 void Start() { if (target) { transform.rotation = Quaternion.Euler(ViewAngle, target.transform.rotation.eulerAngles.y, 0); transform.position = transform.rotation * new Vector3(0,0,-distance) +target.transform.position; } } void LateUpdate() { Quaternion rotation; float delta_x, delta_y; float delta_rotation_x, delta_rotation_y; if (target) { if (Input.GetMouseButton(0)) { delta_x = Input.GetAxis("Mouse X") * MovingSpeed; delta_y = Input.GetAxis("Mouse Y") * MovingSpeed; rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0); transform.position = rotation * new Vector3(-delta_x, 0, -delta_y) + transform.position; } else { if (Input.GetAxis("Mouse ScrollWheel") != 0) { distance += -Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed; } if (Input.GetMouseButton(1)) { delta_rotation_x = Input.GetAxis("Mouse X") * RotateSpeed; delta_rotation_y = -Input.GetAxis("Mouse Y") * RotateSpeed; transform.Rotate(0, delta_rotation_x, 0, Space.World); transform.Rotate(delta_rotation_y, 0, 0); } else { //transform.rotation = Quaternion.Slerp(transform.rotation, //Quaternion.Euler(transform.rotation.eulerAngles.x, target.transform.rotation.eulerAngles.y, 0 //), Time.deltaTime * 2); } transform.position = transform.rotation * new Vector3(0, 0, -distance) + target.transform.position; } } Vector3 startPos = target.transform.position; Vector3 dir = (target.transform.position - transform.position).normalized; Vector3 aim = startPos - dir * transform.localEulerAngles.y; Debug.DrawLine(startPos, aim, Color.red); RaycastHit hit; if (Physics.Linecast(startPos, aim, out hit)) { if (hit.collider.gameObject.tag != "MainCamera") { Debug.Log(11); transform.position = hit.point + transform.forward* 0.5f; } } transform.LookAt(target.transform); }
0 0
- 摄像机视角优化
- unity GearVr 摄像机视角
- Unity固定视角摄像机
- 【Untiy&摄像机视角】
- 控制摄像机移动和视角
- 摄像机的拉近视角代码:
- Unity之-----背后视角摄像机
- 第三人视角,摄像机跟随代码
- 摄像机 第一视角和第三视角的切换
- Unity3D 第一人称视角摄像机旋转控制
- Unity视角转动之摄像机环绕效果
- opengl摄像机系统,视角变换知识点
- 自由视角摄像机,实现旋转,缩放
- GameBryo中全视角第三人称摄像机的实现
- Android官网培训课:运用投影和摄像机视角
- Unity学习笔记--鹰击长空类固定视角游戏摄像机跟随
- [Unity]将摄像机移动到Scene视角位置
- hololens画布始终跟随摄像机视角和字体模糊了
- 3.1 JS window对象&&document文档对象&&变量的作用域&&隐藏样式&&入口函数
- MVC模式
- DriverManagerDataSource
- 数据库中的join连接
- Java运行时异常和非运行时异常
- 摄像机视角优化
- LeetCode 15. 3Sum 三个正数之和
- 简述Servlet的生命周期
- 接口的特性
- XML入门
- kettle中"数据库查询"与"数据库连接"步骤的区别
- QT All Modules QT所有模块
- 黑金AX7020 && ZYNQ7000 (一) PL流水灯设计
- Windows编程_Lesson001_Windows 简介