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

来源:互联网 发布:mindmanager注册机mac 编辑:程序博客网 时间:2024/05/16 09:00
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 targetif (!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.position = target.position;//先让目标的位置和摄像机的位置一致transform.position -= currentRotation * Vector3.forward * distance;//改变摄像机的Z轴// 设置摄像机的位置transform.position = new Vector3( transform.position.x, currentHeight, transform.position.z);//摄像机总是注视目标transform.LookAt (target);}}

0 0