Unity3D 摄像机跟随物体平滑移动
作者:
醉杀楚天白 | 来源:发表于
2018-01-02 20:25 被阅读0次using UnityEngine;
using System.Collections;
namespace CompleteProject
{
public class CameraFollow : MonoBehaviour
{
public Transform target; // The position that that camera will be following.
public float smoothing = 5f; // The speed with which the camera will be following.
Vector3 offset; // The initial offset from the target.
void Start ()
{
// Calculate the initial offset.
offset = transform.position - target.position;
}
void FixedUpdate ()
{
// Create a postion the camera is aiming for based on the offset from the target.
Vector3 targetCamPos = target.position + offset;
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
}
本文标题:Unity3D 摄像机跟随物体平滑移动
本文链接:https://www.haomeiwen.com/subject/coiqnxtx.html
网友评论