控制摄像机一直看物体的正方,并且相距一定距离
来源:互联网 发布:橡树岛宝藏 知乎 编辑:程序博客网 时间:2024/04/30 17:04
private bool blStart;
private GameObject camer;
private GameObject target;
// private float height = 10;
private float rotationDamping = 3;
private float curDis = 100;
// private float heightDamping = 3;
private Vector3 tartPos;
void Update()
{
UpdateCamerLogic();
}
public void ControlCamerLogic(GameObject camer, GameObject target)
{
blStart = true;
this.camer = camer;
this.target = target;
tartPos = target.transform.position - target.transform.forward * curDis;
}
private void UpdateCamerLogic()
{
if (blStart)
{
// Calculate the current rotation angles
var wantedRotationAngleY = target.transform.eulerAngles.y;
var wantedRotationAngleX = target.transform.eulerAngles.x;
var currentRotationAngleY = camer.transform.eulerAngles.y;
var currentRotationAngleX = camer.transform.eulerAngles.x;
// Damp the rotation around the y-axis
currentRotationAngleY = Mathf.LerpAngle(currentRotationAngleY, wantedRotationAngleY, rotationDamping * Time.deltaTime);
currentRotationAngleX = Mathf.LerpAngle(currentRotationAngleX, wantedRotationAngleX, rotationDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler(currentRotationAngleX, currentRotationAngleY, 0);
//var testRotation = Quaternion.LookRotation(target.transform.forward); //这个方法和上面的方法等价,是unity封装的
//Debug.Log("========>currentRotation:" + currentRotation + "=========>testRotation:" + testRotation);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
var curPos = camer.transform.position;
float posX = Mathf.Lerp(curPos.x, tartPos.x, rotationDamping * Time.deltaTime);
float posY = Mathf.Lerp(curPos.y, tartPos.y, rotationDamping * Time.deltaTime);
float posZ = Mathf.Lerp(curPos.z, tartPos.z, rotationDamping * Time.deltaTime);
camer.transform.position = new Vector3(posX, posY, posZ);
camer.transform.rotation = currentRotation;
}
}
- 控制摄像机一直看物体的正方,并且相距一定距离
- 使物体一直面向摄像机
- Unity3D摄像机跟随物体移动的代码控制
- 鼠标控制摄像机旋转,平移,物体的移动
- Unity3D里实现物体移动到目标点,并且摄像机跟着移动的简单方案
- Unity3D里实现物体移动到目标点,并且摄像机跟着移动的简单方案
- Unity3D里实现物体移动到目标点,并且摄像机跟着移动的简单方案
- Unity里用最简单的办法实现一个物体一直看另一个物体
- 鼠标控制摄像机围绕物体旋转拍摄
- Unity 控制摄像机跟随运动物体
- unity 鼠标控制摄像机围绕物体旋转
- Unity 控制摄像机跟随运动物体
- UILabel 文字靠右显示 并且 文字尾部距UILabel有一定的距离,使用attributeString
- UE4改变摄像机的距离
- 修改DX代码:实现按方向键上下能控制摄像机的距离
- 基于一维物体的摄像机定标
- Unity物体或摄像机的旋转缩放
- Unity_简单的摄像机绕物体旋转
- mjpg-streamer详解2
- mysql修改root密码及root密码忘记的解决办法
- 我的2016--收获的一年
- (4.2.9.1)OrmLite整合SqlCipher
- 关于国产项目Apache Kylin 发展历程及背后的那些事
- 控制摄像机一直看物体的正方,并且相距一定距离
- MongoDB 简介
- Unity3D黑暗之光项目里面额事件运用--事件监听
- MySQL AHI 实现解析
- 程序员后半程之路,管理?技术?
- 【WPF】弹窗定位、弹窗关闭后再打开的报错
- MongoDB下载与安装
- 考试完了,继续学习
- linux下用/proc/stat文件来计算cpu的利用率(附源码)