add camera controller

This commit is contained in:
Mister_Nebula 2020-10-28 21:41:07 +00:00
parent 939a7222ce
commit 69d11c805b
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace QSB.Instruments.QSBCamera
{
class CameraController : MonoBehaviour
{
private float _degreesX;
private float _degreesY;
private Quaternion _rotationX;
private Quaternion _rotationY;
void FixedUpdate()
{
if (CameraManager.Instance.Mode != CameraMode.ThirdPerson)
{
return;
}
UpdateInput();
UpdateRotation();
}
private void UpdateInput()
{
var input = OWInput.GetValue(InputLibrary.look, false, InputMode.All);
_degreesX += input.x * 180f * Time.fixedDeltaTime;
_degreesY += input.y * 180f * Time.fixedDeltaTime;
}
private void UpdateRotation()
{
_degreesX %= 360f;
_degreesY %= 360f;
_degreesY = Mathf.Clamp(_degreesY, -80f, 80f);
_rotationX = Quaternion.AngleAxis(_degreesX, Vector3.up);
_rotationY = Quaternion.AngleAxis(_degreesY, -Vector3.right);
var localRotation = _rotationX * _rotationY * Quaternion.identity;
gameObject.transform.parent.localRotation = localRotation;
}
}
}

View File

@ -59,6 +59,7 @@ namespace QSB.Instruments.QSBCamera
Camera.enabled = false;
OWCamera = CameraObj.AddComponent<OWCamera>();
OWCamera.renderSkybox = true;
CameraObj.AddComponent<CameraController>();
var screenGrab = CameraObj.AddComponent<FlashbackScreenGrabImageEffect>();
screenGrab._downsampleShader = Locator.GetPlayerCamera().gameObject.GetComponent<FlashbackScreenGrabImageEffect>()._downsampleShader;

View File

@ -148,6 +148,7 @@
<Compile Include="Events\EventNames.cs" />
<Compile Include="DeathSync\PlayerDeathEvent.cs" />
<Compile Include="Events\IQSBEvent.cs" />
<Compile Include="Instruments\QSBCamera\CameraController.cs" />
<Compile Include="Instruments\QSBCamera\CameraManager.cs" />
<Compile Include="Instruments\QSBCamera\CameraMode.cs" />
<Compile Include="Instruments\InstrumentsManager.cs" />