27 lines
630 B
C#
27 lines
630 B
C#
using UnityEngine;
|
|
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
public Vector3 offset = new Vector3(0, 4, -7);
|
|
public float smoothSpeed = 5f;
|
|
|
|
private Vector3 velocity = Vector3.zero;
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (target == null) return;
|
|
|
|
Vector3 desiredPosition = target.position + target.TransformDirection(offset);
|
|
|
|
// Smooth lebih stabil (tidak getar)
|
|
transform.position = Vector3.SmoothDamp(
|
|
transform.position,
|
|
desiredPosition,
|
|
ref velocity,
|
|
0.1f
|
|
);
|
|
|
|
transform.LookAt(target);
|
|
}
|
|
} |