File size: 1,000 Bytes
05c9ac2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using UnityEngine;
namespace Unity.MLAgentsExamples
{
public class CameraFollow : MonoBehaviour
{
[Tooltip("The target to follow")] public Transform target;
[Tooltip("The time it takes to move to the new position")]
public float smoothingTime; //The time it takes to move to the new position
private Vector3 m_Offset;
private Vector3 m_CamVelocity; //Camera's velocity (used by SmoothDamp)
// Use this for initialization
void Start()
{
m_Offset = gameObject.transform.position - target.position;
}
void FixedUpdate()
{
var newPosition = new Vector3(target.position.x + m_Offset.x, transform.position.y,
target.position.z + m_Offset.z);
gameObject.transform.position =
Vector3.SmoothDamp(transform.position, newPosition, ref m_CamVelocity, smoothingTime, Mathf.Infinity,
Time.fixedDeltaTime);
}
}
}
|