Compare commits
5 Commits
2715ba7a86
...
trey
| Author | SHA1 | Date | |
|---|---|---|---|
| d8295719b0 | |||
| fc78d599a8 | |||
| 0063735802 | |||
| 25236e29e6 | |||
| 16342f1ff4 |
Binary file not shown.
@@ -0,0 +1,110 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6c111ce829d1706468fa324e2283ab11
|
||||||
|
ModelImporter:
|
||||||
|
serializedVersion: 24200
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
materials:
|
||||||
|
materialImportMode: 2
|
||||||
|
materialName: 0
|
||||||
|
materialSearch: 1
|
||||||
|
materialLocation: 1
|
||||||
|
animations:
|
||||||
|
legacyGenerateAnimations: 4
|
||||||
|
bakeSimulation: 0
|
||||||
|
resampleCurves: 1
|
||||||
|
optimizeGameObjects: 0
|
||||||
|
removeConstantScaleCurves: 0
|
||||||
|
motionNodeName:
|
||||||
|
animationImportErrors:
|
||||||
|
animationImportWarnings:
|
||||||
|
animationRetargetingWarnings:
|
||||||
|
animationDoRetargetingWarnings: 0
|
||||||
|
importAnimatedCustomProperties: 0
|
||||||
|
importConstraints: 0
|
||||||
|
animationCompression: 1
|
||||||
|
animationRotationError: 0.5
|
||||||
|
animationPositionError: 0.5
|
||||||
|
animationScaleError: 0.5
|
||||||
|
animationWrapMode: 0
|
||||||
|
extraExposedTransformPaths: []
|
||||||
|
extraUserProperties: []
|
||||||
|
clipAnimations: []
|
||||||
|
isReadable: 0
|
||||||
|
meshes:
|
||||||
|
lODScreenPercentages: []
|
||||||
|
globalScale: 1
|
||||||
|
meshCompression: 0
|
||||||
|
addColliders: 0
|
||||||
|
useSRGBMaterialColor: 1
|
||||||
|
sortHierarchyByName: 1
|
||||||
|
importPhysicalCameras: 1
|
||||||
|
importVisibility: 1
|
||||||
|
importBlendShapes: 1
|
||||||
|
importCameras: 1
|
||||||
|
importLights: 1
|
||||||
|
nodeNameCollisionStrategy: 1
|
||||||
|
fileIdsGeneration: 2
|
||||||
|
swapUVChannels: 0
|
||||||
|
generateSecondaryUV: 0
|
||||||
|
useFileUnits: 1
|
||||||
|
keepQuads: 0
|
||||||
|
weldVertices: 1
|
||||||
|
bakeAxisConversion: 0
|
||||||
|
preserveHierarchy: 0
|
||||||
|
skinWeightsMode: 0
|
||||||
|
maxBonesPerVertex: 4
|
||||||
|
minBoneWeight: 0.001
|
||||||
|
optimizeBones: 1
|
||||||
|
generateMeshLods: 0
|
||||||
|
meshLodGenerationFlags: 0
|
||||||
|
maximumMeshLod: -1
|
||||||
|
meshOptimizationFlags: -1
|
||||||
|
indexFormat: 0
|
||||||
|
secondaryUVAngleDistortion: 8
|
||||||
|
secondaryUVAreaDistortion: 15.000001
|
||||||
|
secondaryUVHardAngle: 88
|
||||||
|
secondaryUVMarginMethod: 1
|
||||||
|
secondaryUVMinLightmapResolution: 40
|
||||||
|
secondaryUVMinObjectScale: 1
|
||||||
|
secondaryUVPackMargin: 4
|
||||||
|
useFileScale: 1
|
||||||
|
strictVertexDataChecks: 0
|
||||||
|
tangentSpace:
|
||||||
|
normalSmoothAngle: 60
|
||||||
|
normalImportMode: 0
|
||||||
|
tangentImportMode: 3
|
||||||
|
normalCalculationMode: 4
|
||||||
|
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
|
||||||
|
blendShapeNormalImportMode: 1
|
||||||
|
normalSmoothingSource: 0
|
||||||
|
referencedClips: []
|
||||||
|
importAnimation: 1
|
||||||
|
humanDescription:
|
||||||
|
serializedVersion: 3
|
||||||
|
human: []
|
||||||
|
skeleton: []
|
||||||
|
armTwist: 0.5
|
||||||
|
foreArmTwist: 0.5
|
||||||
|
upperLegTwist: 0.5
|
||||||
|
legTwist: 0.5
|
||||||
|
armStretch: 0.05
|
||||||
|
legStretch: 0.05
|
||||||
|
feetSpacing: 0
|
||||||
|
globalScale: 1
|
||||||
|
rootMotionBoneName:
|
||||||
|
hasTranslationDoF: 0
|
||||||
|
hasExtraRoot: 0
|
||||||
|
skeletonHasParents: 1
|
||||||
|
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||||
|
autoGenerateAvatarMappingIfUnspecified: 1
|
||||||
|
animationType: 2
|
||||||
|
humanoidOversampling: 1
|
||||||
|
avatarSetup: 0
|
||||||
|
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
|
||||||
|
importBlendShapeDeformPercent: 1
|
||||||
|
remapMaterialsIfMaterialImportModeIsNone: 0
|
||||||
|
additionalBone: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -4926,6 +4926,100 @@ ParticleSystemRenderer:
|
|||||||
m_MeshWeighting1: 1
|
m_MeshWeighting1: 1
|
||||||
m_MeshWeighting2: 1
|
m_MeshWeighting2: 1
|
||||||
m_MeshWeighting3: 1
|
m_MeshWeighting3: 1
|
||||||
|
--- !u!1 &6363008927783646894
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 3726223533882090415}
|
||||||
|
- component: {fileID: 3526635589839092049}
|
||||||
|
- component: {fileID: 7545598716694529264}
|
||||||
|
- component: {fileID: 7668621773188834713}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: ExplodeRadius
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 0
|
||||||
|
--- !u!4 &3726223533882090415
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 18.43488, y: 18.43488, z: 18.43488}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 6754763150105653226}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!135 &3526635589839092049
|
||||||
|
SphereCollider:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_LayerOverridePriority: 0
|
||||||
|
m_IsTrigger: 1
|
||||||
|
m_ProvidesContacts: 0
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 3
|
||||||
|
m_Radius: 0.5
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &7545598716694529264
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fcf160d0f430fff438a4e57b70f778b2, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::Explosion
|
||||||
|
--- !u!54 &7668621773188834713
|
||||||
|
Rigidbody:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 6363008927783646894}
|
||||||
|
serializedVersion: 5
|
||||||
|
m_Mass: 1
|
||||||
|
m_LinearDamping: 0
|
||||||
|
m_AngularDamping: 0.05
|
||||||
|
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||||
|
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||||
|
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ImplicitCom: 1
|
||||||
|
m_ImplicitTensor: 1
|
||||||
|
m_UseGravity: 0
|
||||||
|
m_IsKinematic: 0
|
||||||
|
m_Interpolate: 0
|
||||||
|
m_Constraints: 0
|
||||||
|
m_CollisionDetection: 0
|
||||||
--- !u!1 &7529463216777598777
|
--- !u!1 &7529463216777598777
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -4964,6 +5058,7 @@ Transform:
|
|||||||
- {fileID: 2953567605728542920}
|
- {fileID: 2953567605728542920}
|
||||||
- {fileID: 6184526720724378978}
|
- {fileID: 6184526720724378978}
|
||||||
- {fileID: 4002096401500763546}
|
- {fileID: 4002096401500763546}
|
||||||
|
- {fileID: 3726223533882090415}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!33 &8008322410806594511
|
--- !u!33 &8008322410806594511
|
||||||
@@ -5087,6 +5182,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Assembly-CSharp::Tnt
|
m_EditorClassIdentifier: Assembly-CSharp::Tnt
|
||||||
explodeLight: {fileID: 5338768621936571555}
|
explodeLight: {fileID: 5338768621936571555}
|
||||||
explodeParticle: {fileID: 5366483297162523608}
|
explodeParticle: {fileID: 5366483297162523608}
|
||||||
|
explosion: {fileID: 7545598716694529264}
|
||||||
fuseTime: 2
|
fuseTime: 2
|
||||||
explosionLengthTime: 0.2
|
explosionLengthTime: 0.2
|
||||||
--- !u!1 &8211024835675607581
|
--- !u!1 &8211024835675607581
|
||||||
|
|||||||
+10175
-33147
File diff suppressed because it is too large
Load Diff
@@ -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)
|
UnityEngine.Cursor.visible = true;
|
||||||
{
|
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
||||||
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
|
|
||||||
camTargetRotation = currentY + 90f;
|
|
||||||
isCamRotating = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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;
|
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(
|
private void HandleZoom()
|
||||||
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 =
|
if (!Input.GetMouseButton(1))
|
||||||
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()
|
|
||||||
{
|
|
||||||
if (dougBody == null)
|
|
||||||
{
|
|
||||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
|
||||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
|
||||||
else
|
|
||||||
return;
|
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,
|
|
||||||
out RaycastHit hit,
|
|
||||||
currentDistance,
|
|
||||||
collisionMask,
|
|
||||||
QueryTriggerInteraction.Ignore))
|
|
||||||
{
|
|
||||||
adjustedDistance =
|
|
||||||
Mathf.Max(
|
|
||||||
hit.distance - collisionOffset,
|
|
||||||
minDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desired Position
|
private void UpdateCameraPosition()
|
||||||
Vector3 offset = rotation * Vector3.forward * -adjustedDistance;
|
|
||||||
Vector3 desiredPosition = target + offset;
|
|
||||||
|
|
||||||
if (desiredPosition.y < dougBody.position.y)
|
|
||||||
{
|
{
|
||||||
desiredPosition.y = dougBody.position.y;
|
Vector3 targetPosition = target.position + targetOffset;
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
correctedDistance = Mathf.Max(minDistance, hit.distance - collisionOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Smooth Follow
|
Vector3 finalPosition = targetPosition + desiredDirection * correctedDistance;
|
||||||
playerCamHome.transform.position = Vector3.Lerp(
|
|
||||||
playerCamHome.transform.position,
|
|
||||||
desiredPosition,
|
|
||||||
followSpeed * Time.deltaTime
|
|
||||||
);
|
|
||||||
|
|
||||||
// Look at player
|
MainCamera.transform.position = Vector3.SmoothDamp(MainCamera.transform.position, finalPosition, ref currentVelocity, 1f / positionSmoothness);
|
||||||
playerCamHome.transform.LookAt(target + Vector3.up);
|
|
||||||
|
MainCamera.transform.rotation = Quaternion.LookRotation(targetPosition - MainCamera.transform.position, 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,6 +236,19 @@ void RotatePlayerTowardMouse()
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
// When rotating the cam with right mouse, look forward
|
||||||
|
if (Input.GetMouseButton(1))
|
||||||
|
{
|
||||||
|
Quaternion targetRotation = Quaternion.LookRotation(cameraController.Forward);
|
||||||
|
|
||||||
|
DougBody.transform.rotation = Quaternion.Slerp(
|
||||||
|
DougBody.transform.rotation,
|
||||||
|
targetRotation,
|
||||||
|
rotationSpeed * Time.deltaTime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Camera cam = cameraController.MainCamera;
|
Camera cam = cameraController.MainCamera;
|
||||||
|
|
||||||
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
||||||
@@ -283,6 +288,7 @@ void RotatePlayerTowardMouse()
|
|||||||
rotationSpeed * Time.deltaTime
|
rotationSpeed * Time.deltaTime
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Try to interact by detecting nearest interactable
|
/// Try to interact by detecting nearest interactable
|
||||||
|
|||||||
@@ -2,12 +2,23 @@
|
|||||||
|
|
||||||
public class BurriedItem : Diggable
|
public class BurriedItem : Diggable
|
||||||
{
|
{
|
||||||
public GameObject ItemToSpawn;
|
// Spawnpoint is optional, will spawn at location of dig spot, translated up
|
||||||
|
// on y-axis
|
||||||
public Transform Spawnpoint;
|
public Transform Spawnpoint;
|
||||||
|
public GameObject ItemToSpawn;
|
||||||
|
|
||||||
public override void Dig()
|
public override void Dig()
|
||||||
|
{
|
||||||
|
if (Spawnpoint == null)
|
||||||
|
{
|
||||||
|
Vector3 newPos = new Vector3(transform.position.x, transform.position.y + 0.2f, transform.position.z);
|
||||||
|
Instantiate(ItemToSpawn, newPos, transform.rotation, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Instantiate(ItemToSpawn, Spawnpoint.position, Spawnpoint.rotation, null);
|
Instantiate(ItemToSpawn, Spawnpoint.position, Spawnpoint.rotation, null);
|
||||||
|
}
|
||||||
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
// Put this on things that will explode when they enter the collision trigger
|
||||||
|
// an Explosion script
|
||||||
|
public class Explodable : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Light is optional (only if you want the exploded object to create light)
|
||||||
|
public Light explodeLight;
|
||||||
|
public ParticleSystem explodeParticle;
|
||||||
|
public float explosionLengthTime;
|
||||||
|
|
||||||
|
public void Explode()
|
||||||
|
{
|
||||||
|
if (explodeLight != null)
|
||||||
|
{
|
||||||
|
explodeLight.gameObject.SetActive(true);
|
||||||
|
explodeLight.transform.parent = null;
|
||||||
|
|
||||||
|
Destroy(explodeLight.gameObject, explosionLengthTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (explodeParticle != null)
|
||||||
|
{
|
||||||
|
explodeParticle.gameObject.SetActive(true);
|
||||||
|
explodeParticle.transform.parent = null;
|
||||||
|
//explodeParticle.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
|
||||||
|
explodeParticle.Play();
|
||||||
|
|
||||||
|
Destroy(explodeParticle.gameObject, explosionLengthTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0c0bbb84f48543046b86f073995c09b1
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
// Put this on an empty game object with a trigger collider. Anything inside of this
|
||||||
|
// trigger collider with an Explodable script will explode
|
||||||
|
public class Explosion : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (other != null)
|
||||||
|
{
|
||||||
|
Explodable explodable = other.GetComponent<Explodable>();
|
||||||
|
if (explodable != null)
|
||||||
|
{
|
||||||
|
explodable.Explode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fcf160d0f430fff438a4e57b70f778b2
|
||||||
@@ -4,6 +4,7 @@ public class Tnt : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public Light explodeLight;
|
public Light explodeLight;
|
||||||
public ParticleSystem explodeParticle;
|
public ParticleSystem explodeParticle;
|
||||||
|
public Explosion explosion;
|
||||||
|
|
||||||
public float fuseTime;
|
public float fuseTime;
|
||||||
public float explosionLengthTime;
|
public float explosionLengthTime;
|
||||||
@@ -17,6 +18,8 @@ void Update()
|
|||||||
if (!exploded && timer > fuseTime)
|
if (!exploded && timer > fuseTime)
|
||||||
{
|
{
|
||||||
exploded = true;
|
exploded = true;
|
||||||
|
explosion.gameObject.SetActive(true);
|
||||||
|
explosion.transform.parent = null;
|
||||||
explodeLight.gameObject.SetActive(true);
|
explodeLight.gameObject.SetActive(true);
|
||||||
explodeLight.transform.parent = null;
|
explodeLight.transform.parent = null;
|
||||||
explodeParticle.gameObject.SetActive(true);
|
explodeParticle.gameObject.SetActive(true);
|
||||||
@@ -26,6 +29,7 @@ void Update()
|
|||||||
|
|
||||||
Destroy(explodeLight.gameObject, explosionLengthTime);
|
Destroy(explodeLight.gameObject, explosionLengthTime);
|
||||||
Destroy(explodeParticle.gameObject, explosionLengthTime);
|
Destroy(explodeParticle.gameObject, explosionLengthTime);
|
||||||
|
Destroy(explosion.gameObject, 0.1f);
|
||||||
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ TagManager:
|
|||||||
- CameraObstructions
|
- CameraObstructions
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
- Dither
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
|||||||
Reference in New Issue
Block a user