Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d8295719b0 | |||
| fc78d599a8 |
@@ -935,6 +935,118 @@ Transform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 1757155171}
|
m_Father: {fileID: 1757155171}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &907193628
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 907193632}
|
||||||
|
- component: {fileID: 907193631}
|
||||||
|
- component: {fileID: 907193630}
|
||||||
|
- component: {fileID: 907193629}
|
||||||
|
m_Layer: 6
|
||||||
|
m_Name: Cube
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!65 &907193629
|
||||||
|
BoxCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 907193628}
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_LayerOverridePriority: 0
|
||||||
|
m_IsTrigger: 0
|
||||||
|
m_ProvidesContacts: 0
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 3
|
||||||
|
m_Size: {x: 1, y: 1, z: 1}
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!23 &907193630
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 907193628}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 1
|
||||||
|
m_ReceiveShadows: 1
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 2
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_ForceMeshLod: -1
|
||||||
|
m_MeshLodSelectionBias: 0
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 78be8f8bd251f244ab82d30f189c8824, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_GlobalIlluminationMeshLod: 0
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!33 &907193631
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 907193628}
|
||||||
|
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!4 &907193632
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 907193628}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 14.41, y: 36.27, z: -1.91}
|
||||||
|
m_LocalScale: {x: 6.073, y: 5.7034, z: 0.72736}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &1073270999
|
--- !u!1001 &1073270999
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1069,9 +1181,33 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalScale.y
|
propertyPath: m_LocalScale.y
|
||||||
value: 2.41278
|
value: 2.41278
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: maxDistance
|
||||||
|
value: 4
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: rotationSpeed
|
||||||
|
value: 1000
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: targetOffset.y
|
||||||
|
value: 0.15
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: collisionOffset
|
||||||
|
value: 0.5
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
propertyPath: collisionRadius
|
propertyPath: collisionRadius
|
||||||
value: 0.01
|
value: 0.3
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: collisionLayers.m_Bits
|
||||||
|
value: 8
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: obstructionMask.m_Bits
|
||||||
|
value: 64
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5526037850913171920, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
- target: {fileID: 5526037850913171920, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
@@ -1113,6 +1249,18 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 0.7071068
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0.7071068
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 90
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8111368525007731252, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
- target: {fileID: 8111368525007731252, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||||
propertyPath: m_Height
|
propertyPath: m_Height
|
||||||
value: 2.67
|
value: 2.67
|
||||||
@@ -11198,3 +11346,4 @@ SceneRoots:
|
|||||||
- {fileID: 273139142}
|
- {fileID: 273139142}
|
||||||
- {fileID: 1073270999}
|
- {fileID: 1073270999}
|
||||||
- {fileID: 2107450398}
|
- {fileID: 2107450398}
|
||||||
|
- {fileID: 907193632}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Unity.VisualScripting;
|
using Unity.VisualScripting;
|
||||||
|
using UnityEditor.Rendering;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
using static Unity.Cinemachine.CinemachineTargetGroup;
|
using static Unity.Cinemachine.CinemachineTargetGroup;
|
||||||
@@ -8,38 +9,35 @@
|
|||||||
|
|
||||||
public class CameraController : MonoBehaviour
|
public class CameraController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float camTargetRotation { get; private set; } = 0;
|
[Header("Target")]
|
||||||
public CameraControlMode CamControlMode { get; private set; } = CameraControlMode.SnapRotate;
|
[SerializeField] private Transform target;
|
||||||
|
[SerializeField] private Vector3 targetOffset = new Vector3(0f, 1.5f, 0f);
|
||||||
public Camera MainCamera;
|
public Camera MainCamera;
|
||||||
|
public Transform playerCamHome;
|
||||||
|
|
||||||
private bool isCamRotating = false;
|
[Header("Orbit")]
|
||||||
|
[SerializeField] private float distance = 5f;
|
||||||
[Header("Rotation")]
|
[SerializeField] private float minDistance = 1f;
|
||||||
public float mouseSensitivity = 200f;
|
[SerializeField] private float maxDistance = 8f;
|
||||||
public float minPitch = -30f;
|
[SerializeField] private float rotationSpeed = 180f;
|
||||||
public float maxPitch = 60f;
|
[SerializeField] private float rotationOffset = 270f;
|
||||||
public float distance = 5f;
|
[SerializeField] private float minPitch = -30f;
|
||||||
private float yaw;
|
[SerializeField] private float maxPitch = 75f;
|
||||||
private float pitch;
|
|
||||||
|
|
||||||
[Header("Zoom")]
|
[Header("Zoom")]
|
||||||
public float followSpeed = 10f;
|
[SerializeField] private float zoomSpeed = 2f;
|
||||||
public float maxDistance = 6f;
|
[SerializeField] private float zoomSmoothness = 10f;
|
||||||
public float minDistance = 1f;
|
|
||||||
public float zoomSpeed = 5f;
|
|
||||||
public float heightOffset = -0.5f;
|
|
||||||
private float currentDistance;
|
|
||||||
private float distanceVelocity;
|
|
||||||
|
|
||||||
[Header("Collision")]
|
[Header("Camera Collision")]
|
||||||
public float collisionRadius = 0.3f;
|
[SerializeField] private LayerMask collisionLayers;
|
||||||
public float collisionOffset = 0.2f;
|
[SerializeField] private float collisionRadius = 0.25f;
|
||||||
public LayerMask collisionMask;
|
[SerializeField] private float collisionOffset = 0.1f;
|
||||||
|
[SerializeField] private float positionSmoothness = 15f;
|
||||||
|
|
||||||
[Header("Occlusion Settings")]
|
[Header("Occlusion Settings")]
|
||||||
public LayerMask obstructionMask;
|
[SerializeField] private LayerMask obstructionMask;
|
||||||
public float fadedAlpha = 0.25f;
|
[SerializeField] private float fadedAlpha = 0.25f;
|
||||||
public float fadeSpeed = 5f;
|
[SerializeField] private float fadeSpeed = 5f;
|
||||||
|
|
||||||
private Dictionary<Renderer, float> currentAlpha =
|
private Dictionary<Renderer, float> currentAlpha =
|
||||||
new Dictionary<Renderer, float>();
|
new Dictionary<Renderer, float>();
|
||||||
@@ -47,228 +45,119 @@ public class CameraController : MonoBehaviour
|
|||||||
private Dictionary<Renderer, float> targetAlpha =
|
private Dictionary<Renderer, float> targetAlpha =
|
||||||
new Dictionary<Renderer, float>();
|
new Dictionary<Renderer, float>();
|
||||||
|
|
||||||
public Transform playerCamHome;
|
private float yaw;
|
||||||
Transform dougBody;
|
private float pitch = 20f;
|
||||||
|
private float targetDistance;
|
||||||
|
private Vector3 currentVelocity;
|
||||||
|
|
||||||
private void Update()
|
public Vector3 Forward
|
||||||
{
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Vector3 forward = MainCamera.transform.forward;
|
||||||
|
forward.y = 0f;
|
||||||
|
return forward.normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Vector3 Right
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Vector3 right = MainCamera.transform.right;
|
||||||
|
right.y = 0f;
|
||||||
|
return right.normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
targetDistance = distance;
|
||||||
|
|
||||||
|
Vector3 startingAngles = MainCamera.transform.eulerAngles;
|
||||||
|
yaw = startingAngles.y + rotationOffset;
|
||||||
|
pitch = startingAngles.x;
|
||||||
|
|
||||||
|
if (pitch > 180f)
|
||||||
|
{
|
||||||
|
pitch -= 360f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LateUpdate()
|
||||||
|
{
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||||
|
target = GameManager.Instance.PlayerController.DougBody.transform;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UpdateOcclusion();
|
UpdateOcclusion();
|
||||||
UpdateFade();
|
UpdateFade();
|
||||||
|
HandleRotation();
|
||||||
if (Input.GetMouseButton(1))
|
HandleZoom();
|
||||||
{
|
UpdateCameraPosition();
|
||||||
HandleFreeCamRotation();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CamAvoidCollisions();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start()
|
private void HandleRotation()
|
||||||
{
|
{
|
||||||
Vector3 angles = playerCamHome.transform.eulerAngles;
|
if (!Input.GetMouseButton(1))
|
||||||
|
|
||||||
yaw = angles.y;
|
|
||||||
pitch = angles.x;
|
|
||||||
currentDistance = distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Trigger cam rotation
|
|
||||||
/// </summary>
|
|
||||||
public void RotateCam()
|
|
||||||
{
|
|
||||||
if (!isCamRotating)
|
|
||||||
{
|
{
|
||||||
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
|
UnityEngine.Cursor.visible = true;
|
||||||
camTargetRotation = currentY + 90f;
|
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
||||||
isCamRotating = true;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set cam rotation immediately
|
|
||||||
/// </summary>
|
|
||||||
void SnapToRotation(float rotation)
|
|
||||||
{
|
|
||||||
if (CamControlMode == CameraControlMode.SnapRotate)
|
|
||||||
{
|
|
||||||
playerCamHome.RotateAround(
|
|
||||||
transform.position,
|
|
||||||
Vector3.up,
|
|
||||||
rotation
|
|
||||||
);
|
|
||||||
|
|
||||||
camTargetRotation = rotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Move cam to desired rotation (every frame)
|
|
||||||
/// </summary>
|
|
||||||
void HandleSnapCamRotation()
|
|
||||||
{
|
|
||||||
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
|
|
||||||
float step = 200 * Time.deltaTime;
|
|
||||||
float newY = Mathf.MoveTowardsAngle(currentY, camTargetRotation, step);
|
|
||||||
|
|
||||||
playerCamHome.RotateAround(
|
|
||||||
transform.position,
|
|
||||||
Vector3.up,
|
|
||||||
newY - currentY
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Mathf.Abs(Mathf.DeltaAngle(newY, camTargetRotation)) < 0.01f)
|
|
||||||
{
|
|
||||||
isCamRotating = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Move cam to desired free rotation (every frame)
|
|
||||||
/// </summary>
|
|
||||||
void HandleFreeCamRotation()
|
|
||||||
{
|
|
||||||
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);
|
UnityEngine.Cursor.visible = false;
|
||||||
|
UnityEngine.Cursor.lockState = CursorLockMode.Locked;
|
||||||
|
|
||||||
// Mouse Input
|
yaw += Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
|
||||||
float mouseX = Input.GetAxis("Mouse X");
|
pitch -= Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
|
||||||
float mouseY = Input.GetAxis("Mouse Y");
|
|
||||||
|
|
||||||
yaw += mouseX * mouseSensitivity * Time.deltaTime;
|
|
||||||
pitch -= mouseY * mouseSensitivity * Time.deltaTime;
|
|
||||||
|
|
||||||
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
|
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
|
||||||
|
|
||||||
// Rotation
|
|
||||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
|
||||||
|
|
||||||
// Zoom
|
|
||||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
|
||||||
|
|
||||||
if (Mathf.Abs(scroll) > 0.0001f)
|
|
||||||
{
|
|
||||||
distance -= scroll * zoomSpeed;
|
|
||||||
distance = Mathf.Clamp(distance, minDistance, maxDistance);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentDistance = Mathf.SmoothDamp(
|
|
||||||
currentDistance,
|
|
||||||
distance,
|
|
||||||
ref distanceVelocity,
|
|
||||||
0.05f);
|
|
||||||
|
|
||||||
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 * -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()
|
private void HandleZoom()
|
||||||
{
|
{
|
||||||
if (dougBody == null)
|
if (!Input.GetMouseButton(1))
|
||||||
{
|
{
|
||||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
return;
|
||||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 target = new Vector3(dougBody.position.x, dougBody.position.y + heightOffset, dougBody.position.z);
|
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
||||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
|
||||||
Vector3 desiredDirection = rotation * Vector3.back;
|
|
||||||
|
|
||||||
float adjustedDistance = currentDistance;
|
targetDistance -= scrollInput * zoomSpeed;
|
||||||
|
targetDistance = Mathf.Clamp(targetDistance, minDistance, maxDistance);
|
||||||
|
|
||||||
if (Physics.SphereCast(
|
distance = Mathf.Lerp(distance, targetDistance, zoomSmoothness * Time.deltaTime);
|
||||||
target,
|
}
|
||||||
collisionRadius,
|
|
||||||
desiredDirection,
|
private void UpdateCameraPosition()
|
||||||
out RaycastHit hit,
|
{
|
||||||
currentDistance,
|
Vector3 targetPosition = target.position + targetOffset;
|
||||||
collisionMask,
|
|
||||||
QueryTriggerInteraction.Ignore))
|
Quaternion orbitRotation = Quaternion.Euler(pitch, yaw, 0f);
|
||||||
|
|
||||||
|
Vector3 desiredDirection = orbitRotation * Vector3.back;
|
||||||
|
Vector3 desiredPosition = targetPosition + desiredDirection * distance;
|
||||||
|
|
||||||
|
float correctedDistance = distance;
|
||||||
|
|
||||||
|
if (Physics.SphereCast(targetPosition, collisionRadius, desiredDirection, out RaycastHit hit, distance, collisionLayers, QueryTriggerInteraction.Ignore))
|
||||||
{
|
{
|
||||||
adjustedDistance =
|
correctedDistance = Mathf.Max(minDistance, hit.distance - collisionOffset);
|
||||||
Mathf.Max(
|
|
||||||
hit.distance - collisionOffset,
|
|
||||||
minDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desired Position
|
Vector3 finalPosition = targetPosition + desiredDirection * correctedDistance;
|
||||||
Vector3 offset = rotation * Vector3.forward * -adjustedDistance;
|
|
||||||
Vector3 desiredPosition = target + offset;
|
|
||||||
|
|
||||||
if (desiredPosition.y < dougBody.position.y)
|
MainCamera.transform.position = Vector3.SmoothDamp(MainCamera.transform.position, finalPosition, ref currentVelocity, 1f / positionSmoothness);
|
||||||
{
|
|
||||||
desiredPosition.y = dougBody.position.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smooth Follow
|
MainCamera.transform.rotation = Quaternion.LookRotation(targetPosition - MainCamera.transform.position, Vector3.up);
|
||||||
playerCamHome.transform.position = Vector3.Lerp(
|
|
||||||
playerCamHome.transform.position,
|
|
||||||
desiredPosition,
|
|
||||||
followSpeed * Time.deltaTime
|
|
||||||
);
|
|
||||||
|
|
||||||
// Look at player
|
|
||||||
playerCamHome.transform.LookAt(target + Vector3.up);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateOcclusion()
|
void UpdateOcclusion()
|
||||||
{
|
{
|
||||||
if (dougBody == null)
|
|
||||||
{
|
|
||||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
|
||||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset all renderers to visible
|
// Reset all renderers to visible
|
||||||
foreach (Renderer r in new List<Renderer>(targetAlpha.Keys))
|
foreach (Renderer r in new List<Renderer>(targetAlpha.Keys))
|
||||||
{
|
{
|
||||||
@@ -276,12 +165,12 @@ void UpdateOcclusion()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector3 dir =
|
Vector3 dir =
|
||||||
MainCamera.transform.position - dougBody.position;
|
MainCamera.transform.position - target.position;
|
||||||
|
|
||||||
float dist = dir.magnitude;
|
float dist = dir.magnitude;
|
||||||
|
|
||||||
RaycastHit[] hits = Physics.RaycastAll(
|
RaycastHit[] hits = Physics.RaycastAll(
|
||||||
dougBody.position,
|
target.position,
|
||||||
dir.normalized,
|
dir.normalized,
|
||||||
dist,
|
dist,
|
||||||
obstructionMask,
|
obstructionMask,
|
||||||
|
|||||||
@@ -149,17 +149,9 @@ void ApplyWalk()
|
|||||||
verticalMovement = Input.GetAxisRaw("Vertical");
|
verticalMovement = Input.GetAxisRaw("Vertical");
|
||||||
horizontalMovement = Input.GetAxisRaw("Horizontal");
|
horizontalMovement = Input.GetAxisRaw("Horizontal");
|
||||||
}
|
}
|
||||||
|
Vector3 input = Vector3.ClampMagnitude(new Vector3(horizontalMovement, 0f, verticalMovement), 1f);
|
||||||
|
|
||||||
moveDir = new Vector3(horizontalMovement, 0, verticalMovement).normalized;
|
moveDir = cameraController.Forward * input.z + cameraController.Right * input.x;
|
||||||
|
|
||||||
if (cameraController != null)
|
|
||||||
{
|
|
||||||
// re-matrix the rotation direction so movement is consistent no matter what
|
|
||||||
// the camera rotation is
|
|
||||||
|
|
||||||
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
|
||||||
moveDir = matrix.MultiplyPoint3x4(moveDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -244,44 +236,58 @@ void RotatePlayerTowardMouse()
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
Camera cam = cameraController.MainCamera;
|
// When rotating the cam with right mouse, look forward
|
||||||
|
if (Input.GetMouseButton(1))
|
||||||
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
|
||||||
|
|
||||||
Vector3 targetPoint;
|
|
||||||
|
|
||||||
// 1. Try real world hit first (most stable)
|
|
||||||
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
|
|
||||||
{
|
{
|
||||||
targetPoint = hit.point;
|
Quaternion targetRotation = Quaternion.LookRotation(cameraController.Forward);
|
||||||
|
|
||||||
|
DougBody.transform.rotation = Quaternion.Slerp(
|
||||||
|
DougBody.transform.rotation,
|
||||||
|
targetRotation,
|
||||||
|
rotationSpeed * Time.deltaTime
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 2. Fallback to plane at player height
|
Camera cam = cameraController.MainCamera;
|
||||||
Plane plane = new Plane(Vector3.up, DougBody.transform.position);
|
|
||||||
|
|
||||||
if (!plane.Raycast(ray, out float enter))
|
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
||||||
|
|
||||||
|
Vector3 targetPoint;
|
||||||
|
|
||||||
|
// 1. Try real world hit first (most stable)
|
||||||
|
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
|
||||||
|
{
|
||||||
|
targetPoint = hit.point;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 2. Fallback to plane at player height
|
||||||
|
Plane plane = new Plane(Vector3.up, DougBody.transform.position);
|
||||||
|
|
||||||
|
if (!plane.Raycast(ray, out float enter))
|
||||||
|
return;
|
||||||
|
|
||||||
|
targetPoint = ray.GetPoint(enter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Flatten direction so we only rotate on Y axis
|
||||||
|
Vector3 direction = targetPoint - DougBody.transform.position;
|
||||||
|
direction.y = 0f;
|
||||||
|
|
||||||
|
if (direction.sqrMagnitude < 0.001f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
targetPoint = ray.GetPoint(enter);
|
// 4. Convert to rotation
|
||||||
|
Quaternion targetRotation = Quaternion.LookRotation(direction.normalized);
|
||||||
|
|
||||||
|
// 5. Smooth rotation
|
||||||
|
DougBody.transform.rotation = Quaternion.Slerp(
|
||||||
|
DougBody.transform.rotation,
|
||||||
|
targetRotation,
|
||||||
|
rotationSpeed * Time.deltaTime
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Flatten direction so we only rotate on Y axis
|
|
||||||
Vector3 direction = targetPoint - DougBody.transform.position;
|
|
||||||
direction.y = 0f;
|
|
||||||
|
|
||||||
if (direction.sqrMagnitude < 0.001f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 4. Convert to rotation
|
|
||||||
Quaternion targetRotation = Quaternion.LookRotation(direction.normalized);
|
|
||||||
|
|
||||||
// 5. Smooth rotation
|
|
||||||
DougBody.transform.rotation = Quaternion.Slerp(
|
|
||||||
DougBody.transform.rotation,
|
|
||||||
targetRotation,
|
|
||||||
rotationSpeed * Time.deltaTime
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ TagManager:
|
|||||||
- CameraObstructions
|
- CameraObstructions
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
- Dither
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|||||||
Reference in New Issue
Block a user