๐ mainCamera์ ๋ถ๋ ์คํฌ๋ฆฝํธ
using UnityEngine;
namespace FastCampus.Cameras {
public class TopDownCamera : Monobehaviour {
#region Variable
public Transform target;
private Vector3 refVelocity;
public float height = 5f;
public float distance = 10f;
public float angle = 45f;
public float lookAtHeight = 2f;
public float smoothSpeed = 0.5f;
#endregion
private void Start() {
HandleCamera();
}
private void LateUpdate() {
HandleCamera();
}
#region Helper Methods
[SerializeField]
public override void HandleCamera() {
if (!target) {
return;
}
// Build world position vector
Vector3 worldPosition = (Vector3.forward * -distance) + (Vector3.up * height);
// Build our Rotated vector
Vector3 rotatedVector = Quaternion.AngleAxis(angle, Vector3.up) * worldPosition;
// Move our position
Vector3 flatTargetPosition = target.position;
flatTargetPosition.y += lookAtHeight;
Vector3 finalPosition = flatTargetPosition + rotatedVector;
transform.position = Vector3.SmoothDamp(transform.position, finalPosition, ref refVelocity, smoothSpeed);
transform.LookAt(target.position);
}
private void OnDrawGizmos() {
Gizmos.color = new Color(1f, 0f, 0f, 0.5f);
if (target) {
Vector3 lookAtPosition = target.position;
lookAtPosition.y += lookAtHeight;
Gizmos.DrawLine(transform.position, lookAtPosition);
Gizmos.DrawSphere(lookAtPosition, 0.25f);
}
Gizmos.DrawSphere(transform.position, 0.25f);
}
#endregion
}
}