Unity3d学习记录(一)摄像机跟随人物移动,并且注视人物

本文档详细介绍了如何使用Unity3D实现摄像机跟随目标移动,并确保摄像机始终注视目标。通过 LateUpdate 函数更新摄像机的位置和角度,使用 Lerp 函数平滑过渡,以及 LookAt 方法实现摄像机的注视效果。
摘要由CSDN通过智能技术生成
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值