Hello,
I am using a script on a camera to track a moving object, it should be centered on the screen, but it is always on the right and a little low. Why?
Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SmoothLookAt : MonoBehaviour
{
public Transform target;
public float damping = 6.0f;
public bool smooth = true;
private void LateUpdate()
{
if (target != null)
{
if (smooth)
{
// Look at and dampen the rotation
Quaternion rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
else
{
// Just lookat
transform.LookAt(target);
}
}
}
private void Start()
{
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>() != null)
{
GetComponent<Rigidbody>().freezeRotation = true;
}
}
}