Camera now has collison detection. As well as main functionality. These are easily edited using the Cinemachine freelook options. The camera is controlled using the Cinemachine input provider and is attached to the current look controls.

This commit is contained in:
Programmer-DField 2021-03-01 23:26:35 +00:00
parent 7fee30a4bd
commit 368b03f848
4 changed files with 94 additions and 79 deletions

View File

@ -1,33 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CinemachineFreeLook))]
public class FreeLookAddOn : MonoBehaviour
{
[Range(0f, 10f)] public float LookSpeed = 1f;
public bool InvertY = false;
private CinemachineFreeLook _freeLookComponent;
public void Start()
{
_freeLookComponent = GetComponent<CinemachineFreeLook>();
}
// Update the look movement each time the event is trigger
public void OnLook(InputAction.CallbackContext context)
{
//Normalize the vector to have an uniform vector in whichever form it came from (I.E Gamepad, mouse, etc)
Vector2 lookMovement = context.ReadValue<Vector2>().normalized;
lookMovement.y = InvertY ? -lookMovement.y : lookMovement.y;
// This is because X axis is only contains between -180 and 180 instead of 0 and 1 like the Y axis
lookMovement.x = lookMovement.x * 180f;
//Ajust axis values using look speed and Time.deltaTime so the look doesn't go faster if there is more FPS
_freeLookComponent.m_XAxis.Value += lookMovement.x * LookSpeed * Time.deltaTime;
_freeLookComponent.m_YAxis.Value += lookMovement.y * LookSpeed * Time.deltaTime;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4e2b06b1980697747a979f7637a7276c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -407,6 +407,38 @@ Transform:
m_Father: {fileID: 1509348081}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &720883428
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 720883429}
m_Layer: 0
m_Name: Cameras
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &720883429
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 720883428}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1.8, z: -3}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1031434361}
- {fileID: 1428383935}
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &827761301
GameObject:
m_ObjectHideFlags: 3
@ -452,7 +484,7 @@ MonoBehaviour:
m_LookAt: {fileID: 0}
m_Follow: {fileID: 0}
m_Lens:
FieldOfView: 50
FieldOfView: 55
OrthographicSize: 10
NearClipPlane: 0.1
FarClipPlane: 5000
@ -473,7 +505,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 827761301}
m_LocalRotation: {x: 0.12082611, y: 0.000000020641723, z: -0.0000000025124665, w: 0.9926737}
m_LocalRotation: {x: 0.12082611, y: 1.7763568e-15, z: -1.6069556e-21, w: 0.9926737}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
@ -616,7 +648,7 @@ Camera:
height: 1
near clip plane: 0.1
far clip plane: 5000
field of view: 50
field of view: 55
orthographic: 0
orthographic size: 5
m_Depth: 0
@ -641,12 +673,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1031434356}
m_LocalRotation: {x: 0.09732475, y: 0.08331483, z: -0.008176249, w: 0.9917256}
m_LocalPosition: {x: 0, y: 1.91, z: -3}
m_LocalRotation: {x: 0.120692424, y: 0.046688613, z: -0.005682839, w: 0.9915751}
m_LocalPosition: {x: 0, y: 0.110000014, z: -3.7200003}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_Father: {fileID: 720883429}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1148358018
GameObject:
@ -962,7 +994,7 @@ MonoBehaviour:
m_LookAt: {fileID: 0}
m_Follow: {fileID: 0}
m_Lens:
FieldOfView: 50
FieldOfView: 55
OrthographicSize: 10
NearClipPlane: 0.1
FarClipPlane: 5000
@ -983,8 +1015,8 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1325377636}
m_LocalRotation: {x: 0.11930971, y: -0.15677473, z: 0.019082276, w: 0.98021567}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: 0.12082521, y: -0.00000002848674, z: 0.0000000034673187, w: 0.9926738}
m_LocalPosition: {x: 0, y: -0.0000059604645, z: 0.0000009536743}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2023640839}
@ -1041,7 +1073,7 @@ MonoBehaviour:
m_LookAt: {fileID: 0}
m_Follow: {fileID: 0}
m_Lens:
FieldOfView: 50
FieldOfView: 55
OrthographicSize: 10
NearClipPlane: 0.1
FarClipPlane: 5000
@ -1062,7 +1094,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1363578753}
m_LocalRotation: {x: 0.09732475, y: 0.08331482, z: -0.008176248, w: 0.9917256}
m_LocalRotation: {x: 0.120692395, y: 0.046688605, z: -0.005682837, w: 0.9915751}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
@ -1080,6 +1112,7 @@ GameObject:
m_Component:
- component: {fileID: 1428383935}
- component: {fileID: 1428383934}
- component: {fileID: 1428383937}
- component: {fileID: 1428383936}
m_Layer: 0
m_Name: CM_ThirdPerson
@ -1110,7 +1143,7 @@ MonoBehaviour:
m_Follow: {fileID: 1020089140}
m_CommonLens: 1
m_Lens:
FieldOfView: 50
FieldOfView: 55
OrthographicSize: 10
NearClipPlane: 0.1
FarClipPlane: 5000
@ -1118,7 +1151,7 @@ MonoBehaviour:
LensShift: {x: 0, y: 0}
m_Transitions:
m_BlendHint: 0
m_InheritPosition: 0
m_InheritPosition: 1
m_OnCameraLive:
m_PersistentCalls:
m_Calls: []
@ -1142,7 +1175,7 @@ MonoBehaviour:
m_LegacyHeadingDefinition: -1
m_LegacyVelocityFilterStrength: -1
m_YAxisRecentering:
m_enabled: 0
m_enabled: 1
m_WaitTime: 1
m_RecenteringTime: 2
m_LegacyHeadingDefinition: -1
@ -1171,8 +1204,8 @@ MonoBehaviour:
m_Bias: 0
m_RecenterToTargetHeading:
m_enabled: 0
m_WaitTime: 1
m_RecenteringTime: 2
m_WaitTime: 0
m_RecenteringTime: 0
m_LegacyHeadingDefinition: -1
m_LegacyVelocityFilterStrength: -1
m_BindingMode: 4
@ -1196,15 +1229,15 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1428383933}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1.91, z: -3}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.110000014, z: -3.7200003}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1325377638}
- {fileID: 1363578755}
- {fileID: 827761303}
m_Father: {fileID: 0}
m_RootOrder: 6
m_Father: {fileID: 720883429}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1428383936
MonoBehaviour:
@ -1215,11 +1248,42 @@ MonoBehaviour:
m_GameObject: {fileID: 1428383933}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e2b06b1980697747a979f7637a7276c, type: 3}
m_Script: {fileID: 11500000, guid: e501d18bb52cf8c40b1853ca4904654f, type: 3}
m_Name:
m_EditorClassIdentifier:
LookSpeed: 5
InvertY: 0
m_CollideAgainst:
serializedVersion: 2
m_Bits: 1
m_IgnoreTag:
m_TransparentLayers:
serializedVersion: 2
m_Bits: 0
m_MinimumDistanceFromTarget: 0.1
m_AvoidObstacles: 1
m_DistanceLimit: 0
m_MinimumOcclusionTime: 0
m_CameraRadius: 0.1
m_Strategy: 1
m_MaximumEffort: 4
m_SmoothingTime: 0
m_Damping: 0
m_DampingWhenOccluded: 0
m_OptimalTargetDistance: 0
--- !u!114 &1428383937
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1428383933}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fb7194dc27b9df64c8beca7482ee8e0d, type: 3}
m_Name:
m_EditorClassIdentifier:
PlayerIndex: -1
XYAxis: {fileID: -4136360517957968697, guid: d4d9eb5db7beac84ca3cb36cfc09cd0a, type: 3}
ZAxis: {fileID: 0}
--- !u!1 &1479115167
GameObject:
m_ObjectHideFlags: 3
@ -1272,7 +1336,7 @@ MonoBehaviour:
m_HorizontalDamping: 0
m_VerticalDamping: 0
m_ScreenX: 0.45
m_ScreenY: 0.55
m_ScreenY: 0.5
m_DeadZoneWidth: 0
m_DeadZoneHeight: 0
m_SoftZoneWidth: 0.8
@ -1744,13 +1808,13 @@ MonoBehaviour:
m_LookaheadIgnoreY: 0
m_HorizontalDamping: 0.5
m_VerticalDamping: 0.5
m_ScreenX: 0.597
m_ScreenX: 0.5
m_ScreenY: 0.5
m_DeadZoneWidth: 0
m_DeadZoneHeight: 0
m_SoftZoneWidth: 0.8
m_SoftZoneHeight: 0.8
m_BiasX: 0
m_BiasX: -0.000000074505806
m_BiasY: 0
m_CenterOnActivate: 1
--- !u!114 &2023640841
@ -1905,7 +1969,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 13726836969441544, guid: 5efe0b059275dbe48a4108d03ad03fd9, type: 3}
propertyPath: m_LocalPosition.z
value: 0
value: -3.72
objectReference: {fileID: 0}
- target: {fileID: 13726836969441544, guid: 5efe0b059275dbe48a4108d03ad03fd9, type: 3}
propertyPath: m_LocalRotation.w
@ -1942,10 +2006,10 @@ PrefabInstance:
- target: {fileID: 13726836969441780, guid: 5efe0b059275dbe48a4108d03ad03fd9, type: 3}
propertyPath: m_ActionEvents.Array.data[1].m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 1428383936}
objectReference: {fileID: 11500000, guid: f1cbb1d5d2a7715478647c26d4e71482, type: 3}
- target: {fileID: 13726836969441780, guid: 5efe0b059275dbe48a4108d03ad03fd9, type: 3}
propertyPath: m_ActionEvents.Array.data[1].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: OnLook
value:
objectReference: {fileID: 0}
- target: {fileID: 13726836969441780, guid: 5efe0b059275dbe48a4108d03ad03fd9, type: 3}
propertyPath: m_ActionEvents.Array.data[1].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName

View File

@ -12,9 +12,6 @@ public class CameraController : MonoBehaviour
[SerializeField]
private PlayerInputHandler _inputHandler;
//[SerializeField]
//private CinemachineFreeLook freeLookCam;
private Vector2 _cameraRotation;
void FixedUpdate()
@ -24,8 +21,6 @@ public class CameraController : MonoBehaviour
_cameraRotation += _inputHandler.InputState.Look * ( deltaTime * _settings.LookSpeed );
_cameraRotation.y = Mathf.Clamp( _cameraRotation.y, _settings.LookYMin, _settings.LookYMax );
_inputHandler.SetCameraRotation(_cameraRotation.x * -180.0f);
//freeLookCam.m_XAxis.Value = Input.GetAxis("Horizontal");
//freeLookCam.m_YAxis.Value = Input.GetAxis("Vertical");
}
private void LateUpdate()