dithering, close cam, rain
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using static Unity.Cinemachine.CinemachineTargetGroup;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
|
||||
@@ -13,21 +14,28 @@ public class CameraController : MonoBehaviour
|
||||
|
||||
private bool isCamRotating = false;
|
||||
|
||||
[Header("Free Cam Settings")]
|
||||
[Header("Rotation")]
|
||||
public float mouseSensitivity = 200f;
|
||||
public float minPitch = -30f;
|
||||
public float maxPitch = 60f;
|
||||
public float distance = 5f;
|
||||
public float heightOffset = -0.5f;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
[Header("Zoom")]
|
||||
public float followSpeed = 10f;
|
||||
public float maxDistance = 6f;
|
||||
public float minDistance = 1f;
|
||||
public float zoomSpeed = 5f;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
public float heightOffset = -0.5f;
|
||||
private float currentDistance;
|
||||
private float distanceVelocity;
|
||||
|
||||
[Header("Collision")]
|
||||
public float collisionRadius = 0.3f;
|
||||
public float collisionOffset = 0.2f;
|
||||
public LayerMask collisionMask;
|
||||
|
||||
[Header("Occlusion Settings")]
|
||||
public LayerMask obstructionMask;
|
||||
public float fadedAlpha = 0.25f;
|
||||
@@ -51,11 +59,15 @@ private void Update()
|
||||
{
|
||||
HandleFreeCamRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
CamAvoidCollisions();
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Vector3 angles = transform.eulerAngles;
|
||||
Vector3 angles = playerCamHome.transform.eulerAngles;
|
||||
|
||||
yaw = angles.y;
|
||||
pitch = angles.x;
|
||||
@@ -120,10 +132,10 @@ void HandleFreeCamRotation()
|
||||
{
|
||||
if (dougBody == null)
|
||||
{
|
||||
if (GameManager.Instance.PlayerController.DougBody == null)
|
||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
else
|
||||
return;
|
||||
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
}
|
||||
|
||||
Vector3 target = new Vector3(dougBody.position.x, dougBody.position.y + heightOffset, dougBody.position.z);
|
||||
@@ -137,6 +149,9 @@ void HandleFreeCamRotation()
|
||||
|
||||
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
|
||||
|
||||
// Rotation
|
||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
||||
|
||||
// Zoom
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
|
||||
@@ -152,13 +167,87 @@ void HandleFreeCamRotation()
|
||||
ref distanceVelocity,
|
||||
0.05f);
|
||||
|
||||
// Rotation
|
||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
||||
float adjustedDistance = currentDistance;
|
||||
|
||||
Vector3 desiredDirection =
|
||||
rotation * Vector3.back;
|
||||
|
||||
// Camera obstruction handling
|
||||
if (Physics.SphereCast(
|
||||
target,
|
||||
collisionRadius,
|
||||
desiredDirection,
|
||||
out RaycastHit hit,
|
||||
currentDistance,
|
||||
collisionMask,
|
||||
QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
adjustedDistance =
|
||||
Mathf.Max(
|
||||
hit.distance - collisionOffset,
|
||||
minDistance);
|
||||
}
|
||||
|
||||
// Desired Position
|
||||
Vector3 offset = rotation * Vector3.forward * -currentDistance;
|
||||
Vector3 offset = rotation * Vector3.forward * -adjustedDistance;
|
||||
Vector3 desiredPosition = target + offset;
|
||||
|
||||
if (desiredPosition.y < dougBody.position.y)
|
||||
{
|
||||
desiredPosition.y = dougBody.position.y;
|
||||
}
|
||||
|
||||
// Smooth Follow
|
||||
playerCamHome.transform.position = Vector3.Lerp(
|
||||
playerCamHome.transform.position,
|
||||
desiredPosition,
|
||||
followSpeed * Time.deltaTime
|
||||
);
|
||||
|
||||
// Look at player
|
||||
playerCamHome.transform.LookAt(target + Vector3.up);
|
||||
}
|
||||
|
||||
void CamAvoidCollisions()
|
||||
{
|
||||
if (dougBody == null)
|
||||
{
|
||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 target = new Vector3(dougBody.position.x, dougBody.position.y + heightOffset, dougBody.position.z);
|
||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
||||
Vector3 desiredDirection = rotation * Vector3.back;
|
||||
|
||||
float adjustedDistance = currentDistance;
|
||||
|
||||
if (Physics.SphereCast(
|
||||
target,
|
||||
collisionRadius,
|
||||
desiredDirection,
|
||||
out RaycastHit hit,
|
||||
currentDistance,
|
||||
collisionMask,
|
||||
QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
adjustedDistance =
|
||||
Mathf.Max(
|
||||
hit.distance - collisionOffset,
|
||||
minDistance);
|
||||
}
|
||||
|
||||
// Desired Position
|
||||
Vector3 offset = rotation * Vector3.forward * -adjustedDistance;
|
||||
Vector3 desiredPosition = target + offset;
|
||||
|
||||
if (desiredPosition.y < dougBody.position.y)
|
||||
{
|
||||
desiredPosition.y = dougBody.position.y;
|
||||
}
|
||||
|
||||
// Smooth Follow
|
||||
playerCamHome.transform.position = Vector3.Lerp(
|
||||
playerCamHome.transform.position,
|
||||
@@ -174,14 +263,12 @@ void UpdateOcclusion()
|
||||
{
|
||||
if (dougBody == null)
|
||||
{
|
||||
if (GameManager.Instance.PlayerController.DougBody == null)
|
||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
else
|
||||
return;
|
||||
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
}
|
||||
|
||||
if (dougBody == null) return;
|
||||
|
||||
// Reset all renderers to visible
|
||||
foreach (Renderer r in new List<Renderer>(targetAlpha.Keys))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user