using UnityEngine;
using System.Collections;
public class camera : MonoBehaviour {
// 设定绑定目标
public Transform target;
// 设置隔离目标的距离
float distance = 10.0f;
// 设置隔离目标的高度
float height = 5.0f;
//转动的速度
float heightDamping = 2.0f;
float rotationDamping = 3.0f;
void LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// 想要旋转的角度和高度
//float wantedRotationAngle = target.eulerAngles.y;
float wantedHeight = target.position.y + height;
//当前的高度和欧拉角
//float currentRotationAngle = transform.eulerAngles.y;
float currentHeight = transform.position.y;
//从当前的欧拉角旋转到
//currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
//从当前的高度到想到的高度
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
//这里是我修改的,直接让它等于1,
//摄像机就不会旋转。
float currentRotation = 1;
// 设置于目标的Y轴的距离
transform.posit
Unity3d学习记录(一)摄像机跟随人物移动,并且注视人物
最新推荐文章于 2024-07-29 21:59:26 发布
本文档详细介绍了如何使用Unity3D实现摄像机跟随目标移动,并确保摄像机始终注视目标。通过 LateUpdate 函数更新摄像机的位置和角度,使用 Lerp 函数平滑过渡,以及 LookAt 方法实现摄像机的注视效果。
摘要由CSDN通过智能技术生成