I have this script of camera controller which follow the player:
public GameObject player;
private float smoothness = 0.1f;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 desiredPosition = player.transform.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothness);
transform.position = smoothedPosition;
}
Normally it goes nicely and very smooth. However when the player object boards a moving platform, the camera stutters back and forth a little which cause image tearing. What should I add to make it smooth?
Here is the script to hold the player object on a moving platform which I suspect as the cause of the issue:
private Vector3 offset;
private GameObject target = null;
private void Start()
{
target = null;
}
private void OnTriggerStay(Collider other)
{
target = other.gameObject;
offset = target.transform.position - transform.position;
}
private void OnTriggerExit(Collider other)
{
target = null;
}
private void LateUpdate()
{
if(target != null)
{
target.transform.position = transform.position + offset;
}
}
Thank you in advance!