摄像机跟随脚本.docxVIP

  • 14
  • 0
  • 约1.49千字
  • 约 2页
  • 2020-06-11 发布于山东
  • 举报
Posted on 2013年05月29日 by U3d / \o 查看 Unity3D脚本/插件 中的全部文章 Unity3D脚本/插件/被围观 167 次 distanceAway:摄像机和目标点的水平面距离。 distanceUp:摄像机和目标的高度差。 smooth:摄像机移动到目标点的平滑度,也可以理解为速度。 transform.LookAt(); :使摄像机始终朝向目标点。 脚本如下: 01 using UnityEngine; 02 using System.Collections; 03 04 public class ThirdPersonCamera : MonoBehaviour 05 { 06 public float distanceAway; // distance from the back of the craft 07 public float distanceUp; // distance above the craft 08 public float smooth; // how smooth the camera movement is 09 10 private GameObject hovercraft; // to store the hovercraft 11 private Vector3 targetPosition; // the position the camera is trying to be in 12 13 Transform follow; 14 15 void Start(){ 16 follow = GameObject.FindWithTag (Player).transform; 17 } 18 19 void LateUpdate () 20 { 21 // setting the target position to be the correct offset from the hovercraft 22 targetPosition = follow.position + Vector3.up * distanceUp + follow.forward * distanceAway; 23 24 // making a smooth transition between its current position and the position it wants to be in 25 transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth); 26 27 // make sure the camera is looking the right way! 28 transform.LookAt(follow); 29 } 30 }

文档评论(0)

1亿VIP精品文档

相关文档