unity新手可以参考,相机360度观察一个对象
来源:互联网 发布:pythonxy linux 编辑:程序博客网 时间:2024/06/08 13:18
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);
}
}
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
- unity新手可以参考,相机360度观察一个对象
- [Unity实战]相机观察物体
- Unity 相机围绕物体指定观察角度和位置
- 在Unity中控制相机围绕物体自由观察
- php和asp对象的等价关系(ASP转PHP的新手朋友可以参考一下)
- Unity 3D 新手开发日志·鼠标观察
- java中对象属性可以是另外一个对象或对象的参考
- Unity 怎么得到一个可以直接使用的对象与另一个对象之间的Float夹角
- 观察者模式,让一个对象观察另一个对象的状态
- ARP 360度观察
- Unity 观察模型例子
- Unity隐身 观察隐身
- Unity学习笔记——利用脚本实现对一个物体的第三人称观察
- Unity 使用陀螺仪观察场景
- unity接微信androidSDK,一个供参考测试的Demo
- Observable(可观察对象)
- macbook 新手可以参考下(随记的常用操作,很乱,多少有点用)
- Unity 相机控制集合。。。。
- JSP中application session request cookie 生命周期的问题
- 深入剖析之通过IAR MAP文件查看目标文件内存分配
- C++ 单例模板
- 【MySQL】慢查询日志
- bindService的使用方法
- unity新手可以参考,相机360度观察一个对象
- 自定义图标列表
- 2017滴滴前端笔试题总结
- 单调队列与单调栈用法详解
- 模拟地和数字地单点接地
- 图片预览插件Viewer
- 勇于尝试——AJ
- JPA之第一个JPA程序
- [BZOJ1565][NOI2009]植物大战僵尸-拓扑排序-网络流