一.第三人称视角,一般可用于赛车游戏
先设置好相机与玩家之间的角度
给相机添加代码
1 using UnityEngine; 2 using System.Collections; 3 4 namespace CompleteProject 5 { 6 public class CameraFollow : MonoBehaviour 7 { 8 public Transform target; // The position that that camera will be following. 9 public float smoothing = 5f; // The speed with which the camera will be following. 10 11 12 Vector3 offset; // The initial offset from the target. 13 14 15 void Start () 16 { 17 // Calculate the initial offset. 18 offset = transform.position - target.position; 19 } 20 21 22 void FixedUpdate () 23 { 24 // Create a postion the camera is aiming for based on the offset from the target. 25 Vector3 targetCamPos = target.position + offset; 26 27 // Smoothly interpolate between the camera‘s current position and it‘s target position. 28 //相机平滑的移动到目标位置,插值 29 transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime); 30 } 31 } 32 }
原文:http://www.cnblogs.com/ninomiya/p/6486534.html