脚本拖给相机,高度和距离在面板中设置。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlowTarget : MonoBehaviour
{
//跟随的目标
public Transform target;
//跟随的高度
public float height;
//跟随的距离
public float distance;
void Start ()
{
}
void LateUpdate ()
{
Vector3 forward = transform.forward;
forward.y = 0;
Vector3 newForward = Vector3.Lerp(forward, target.forward, 1 * Time.deltaTime);
transform.position = target.position - target.forward * distance + Vector3.up * height;
transform.LookAt(target);
}
}