Skip to content

Instantly share code, notes, and snippets.

@momo-the-monster
Created April 14, 2018 00:14
Show Gist options
  • Save momo-the-monster/11e092db552d16beb881bd21c226040e to your computer and use it in GitHub Desktop.
Save momo-the-monster/11e092db552d16beb881bd21c226040e to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudienceCamera : MonoBehaviour
{
public GameObject mainCameraEye;
public bool lockZ = true;
[Range(10f,0.5f)]
public float positionLag = 3.0f;
[Range(10f, 0.5f)]
public float rotationLag = 2.0f;
void LateUpdate()
{
Quaternion targetRot;
Vector3 eulerRot = mainCameraEye.transform.localRotation.eulerAngles;
if (lockZ)
{
eulerRot.z = 0.0f;
}
targetRot = Quaternion.Euler(eulerRot);
transform.localPosition = Vector3.Slerp(transform.localPosition, mainCameraEye.transform.localPosition, positionLag * Time.unscaledDeltaTime);
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRot, rotationLag * Time.unscaledDeltaTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment