Skip to content

Commit

Permalink
Smooth third person camera. Closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Raicuparta committed May 4, 2022
1 parent 748e388 commit 0612f07
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion GorillaTagLIV/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Plugin : BaseUnityPlugin
{
private const string assetsDir = "/BepInEx/plugins/GorillaTagLIV/Assets/";
private Camera thirdPersonCamera;
private Quaternion livCameraRotation;
private Vector3 livCameraPosition;

private LIV.SDK.Unity.LIV liv;

Expand Down Expand Up @@ -85,6 +87,8 @@ private void SetUpThridPersonCamera()
if (cinemachineBrain)
{
thirdPersonCamera = cinemachineBrain.GetComponent<Camera>();
livCameraRotation = thirdPersonCamera.transform.localRotation;
livCameraPosition = thirdPersonCamera.transform.localPosition;
}
}

Expand All @@ -101,7 +105,14 @@ private void Update()
if (!liv || !thirdPersonCamera || !liv.isActive) return;

var cameraTransform = thirdPersonCamera.transform;
liv.render.SetPose(cameraTransform.position, cameraTransform.rotation, thirdPersonCamera.fieldOfView);

livCameraRotation = Quaternion.Slerp(livCameraRotation, cameraTransform.localRotation, Quaternion.Angle(livCameraRotation, cameraTransform.localRotation) / 180f);
livCameraPosition = Vector3.Slerp(livCameraPosition, cameraTransform.localPosition, (livCameraPosition - cameraTransform.localPosition).sqrMagnitude / 10f);

liv.render.SetPose(
cameraTransform.parent.TransformPoint(livCameraPosition),
cameraTransform.parent.rotation * livCameraRotation,
thirdPersonCamera.fieldOfView);
}
}
}

0 comments on commit 0612f07

Please # to comment.