Last active
September 5, 2020 02:36
-
-
Save kalineh/1eccb28c600ae98516ea577c0afb9339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CameraSmooth | |
: MonoBehaviour | |
{ | |
public Camera cameraTarget; | |
public Camera cameraSelf; | |
public bool enableSmooth = true; | |
[Range(0.0f, 12.0f)] | |
public float lerpPositionRate = 8.0f; | |
[Range(1.0f, 12.0f)] | |
public float lerpRotationRate = 4.0f; | |
public void Start() | |
{ | |
if (!cameraSelf) | |
cameraSelf = GetComponent<Camera>(); | |
cameraTarget = PlayerCameraSupport.GetCamera(); | |
// just make sure smooth camera set to None (Main Display) | |
// vive will render the both eyes camera, and main game window will show smooth | |
cameraSelf.stereoTargetEye = StereoTargetEyeMask.None; | |
cameraSelf.targetDisplay = 0; | |
cameraSelf.fieldOfView = GameSettings.Instance.OptionEnableCameraSmoothingFOV; | |
cameraSelf.nearClipPlane = cameraTarget.nearClipPlane; | |
cameraSelf.farClipPlane = cameraTarget.farClipPlane; | |
cameraSelf.transform.position = cameraTarget.transform.position; | |
cameraSelf.transform.rotation = cameraTarget.transform.rotation; | |
cameraTarget.targetDisplay = 0; | |
} | |
public void FixedUpdate() | |
{ | |
if (!cameraTarget) | |
return; | |
var posRate = lerpPositionRate; | |
var rotRate = lerpRotationRate; | |
if (enableSmooth) | |
{ | |
transform.position = Vector3.Lerp(transform.position, cameraTarget.transform.position, Mathf.Clamp01(posRate * Time.fixedDeltaTime)); | |
transform.rotation = Quaternion.Slerp(transform.rotation, cameraTarget.transform.rotation, Mathf.Clamp01(rotRate * Time.fixedDeltaTime)); | |
} | |
else | |
{ | |
transform.position = cameraTarget.transform.position; | |
transform.rotation = cameraTarget.transform.rotation; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the licence for this?