Unity3D 相机绕对象旋转和调整距离
来源:互联网 发布:英菲克下载软件口令 编辑:程序博客网 时间:2024/06/05 17:48
using UnityEngine;public class MouseFollowRotation : MonoBehaviour{ public Transform target; public float xSpeed = 200; public float ySpeed = 200; public float mSpeed = 10; public float yMinLimit = -50; public float yMaxLimit = 50; public float distance = 2; public float minDistance = 2; public float maxDistance = 30; //bool needDamping = false; public bool needDamping = true; float damping = 5.0f; public float x = 0.0f; public float y = 0.0f; // Use this for initialization void Start() { Vector3 angles = transform.eulerAngles; x = angles.y; y = angles.x; } // Update is called once per frame void LateUpdate() { if (target) { //use the light button of mouse to rotate the camera if (Input.GetMouseButton(1)) { x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; y = ClampAngle(y, yMinLimit, yMaxLimit); } distance -= Input.GetAxis("Mouse ScrollWheel") * mSpeed; distance = Mathf.Clamp(distance, minDistance, maxDistance); Quaternion rotation = Quaternion.Euler(y, x, 0.0f); Vector3 disVector = new Vector3(0.0f, 0.0f, -distance); Vector3 position = rotation * disVector + target.position; //adjust the camera if (needDamping) { transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * damping); transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * damping); } else { transform.rotation = rotation; transform.position = position; } } } static float ClampAngle(float angle, float min, float max) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp(angle, min, max); }}
0 0
- Unity3D 相机绕对象旋转和调整距离
- 【unity3d学习笔记】RPG 中控制相机距离拉近拉远以及旋转相机视角
- Unity3D脚本:相机旋转代码
- Unity3d实现相机的跟随缩放旋转
- MouseFollowRotation Unity3d鼠标点击旋转相机
- Unity3D游戏场景之控制模型移动、旋转和相机跟随
- 《Unity3D网络游戏实战》学习笔记--相机及视野调整
- 自动旋转和调整大小
- 自动旋转和调整大小
- unity3d 相机围绕某个物体旋转,四元数*位置
- Unity3D控制物体前后左右移动、旋转及相机跟随
- Unity3D的相机跟随、视野缩放以及旋转
- 相机特效来调整亮度和对比度
- Unity3D技术之相机使用技巧-从相机到给定距离的视锥体大小
- unity3d四元数和旋转矩阵
- Unity3D 中旋转和变换
- unity3d四元数和旋转矩阵
- unity3d四元数和旋转矩阵
- adb命令大全
- 【Linux&Unix--open/close/write/read系统调用】
- Zxing相关资料
- Linux内核: 修改TCP/IP调优参数
- 使用Ant打包工具
- Unity3D 相机绕对象旋转和调整距离
- 时时监控input值变化 oninput & onpropertychange
- 这个SQL面试题怎么做 求指导
- linux查看网卡
- linux内核TCP/IP调优相关资料汇总
- SDUTOJ3115-小鑫找基友
- iOS开发实用技巧—身份证的正则校验
- HCE基础知识普及
- Linux shell 基础