mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
add clip prevention to camera
This commit is contained in:
parent
69d11c805b
commit
b61e95afb9
@ -1,8 +1,4 @@
|
||||
using QSB.Instruments.QSBCamera;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Instruments
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
@ -13,16 +9,50 @@ namespace QSB.Instruments.QSBCamera
|
||||
private Quaternion _rotationX;
|
||||
private Quaternion _rotationY;
|
||||
|
||||
private const float PercentToMove = 0.75f;
|
||||
|
||||
public GameObject CameraObject;
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (CameraManager.Instance.Mode != CameraMode.ThirdPerson)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdatePosition();
|
||||
UpdateInput();
|
||||
UpdateRotation();
|
||||
}
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
var origin = transform.position;
|
||||
var localDirection = CameraObject.transform.localPosition.normalized;
|
||||
Vector3 localTargetPoint;
|
||||
if (Physics.Raycast(origin, transform.TransformDirection(localDirection), out RaycastHit outRay, 10, LayerMask.GetMask("Default")))
|
||||
{
|
||||
localTargetPoint = transform.InverseTransformPoint(outRay.point) * PercentToMove;
|
||||
}
|
||||
else
|
||||
{
|
||||
localTargetPoint = localDirection * 10 * PercentToMove;
|
||||
}
|
||||
var targetDistance = Vector3.Distance(origin, transform.TransformPoint(localTargetPoint));
|
||||
var currentDistance = Vector3.Distance(origin, CameraObject.transform.position);
|
||||
Vector3 movement;
|
||||
if (targetDistance < currentDistance)
|
||||
{
|
||||
// Snap to target to avoid clipping
|
||||
movement = localTargetPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move camera out slowly
|
||||
movement = Vector3.MoveTowards(CameraObject.transform.localPosition, localTargetPoint, Time.fixedDeltaTime * 2f);
|
||||
}
|
||||
CameraObject.transform.localPosition = movement;
|
||||
}
|
||||
|
||||
private void UpdateInput()
|
||||
{
|
||||
var input = OWInput.GetValue(InputLibrary.look, false, InputMode.All);
|
||||
@ -38,7 +68,7 @@ namespace QSB.Instruments.QSBCamera
|
||||
_rotationX = Quaternion.AngleAxis(_degreesX, Vector3.up);
|
||||
_rotationY = Quaternion.AngleAxis(_degreesY, -Vector3.right);
|
||||
var localRotation = _rotationX * _rotationY * Quaternion.identity;
|
||||
gameObject.transform.parent.localRotation = localRotation;
|
||||
transform.localRotation = localRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,6 @@
|
||||
using OWML.Common;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.PostProcessing;
|
||||
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
@ -59,7 +54,8 @@ namespace QSB.Instruments.QSBCamera
|
||||
Camera.enabled = false;
|
||||
OWCamera = CameraObj.AddComponent<OWCamera>();
|
||||
OWCamera.renderSkybox = true;
|
||||
CameraObj.AddComponent<CameraController>();
|
||||
|
||||
CameraBase.AddComponent<CameraController>().CameraObject = CameraObj;
|
||||
|
||||
var screenGrab = CameraObj.AddComponent<FlashbackScreenGrabImageEffect>();
|
||||
screenGrab._downsampleShader = Locator.GetPlayerCamera().gameObject.GetComponent<FlashbackScreenGrabImageEffect>()._downsampleShader;
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
namespace QSB.Instruments.QSBCamera
|
||||
{
|
||||
public enum CameraMode
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user