diff --git a/UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Gluecose.prefab b/UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Gluecose.prefab
index 9b19281d5..70062f4c6 100644
--- a/UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Gluecose.prefab
+++ b/UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Gluecose.prefab
@@ -58,8 +58,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_attackConfigSO: {fileID: 11400000, guid: fa67200955f70e64abecdd0107951472, type: 2}
---- !u!135 &6188918218575104391
-SphereCollider:
+--- !u!65 &85085901128719611
+BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@@ -69,9 +69,9 @@ SphereCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
- m_Radius: 0.35
- m_Center: {x: 0, y: 0.32, z: 0}
---- !u!135 &6274847306283701072
+ m_Size: {x: 0.64422137, y: 0.5481757, z: 0.72591937}
+ m_Center: {x: -0.004921645, y: 0.2887556, z: 0.014988601}
+--- !u!135 &8467386107611288299
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
diff --git a/UOP1_Project/Assets/Prefabs/Nature/Bush.prefab b/UOP1_Project/Assets/Prefabs/Nature/Bush.prefab
index 5f30c550f..3c7eda7f9 100644
--- a/UOP1_Project/Assets/Prefabs/Nature/Bush.prefab
+++ b/UOP1_Project/Assets/Prefabs/Nature/Bush.prefab
@@ -1,7 +1,7 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
---- !u!136 &1143880073
-CapsuleCollider:
+--- !u!65 &306546508537069537
+BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@@ -10,10 +10,9 @@ CapsuleCollider:
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
- m_Radius: 0.5
- m_Height: 1.3
- m_Direction: 1
- m_Center: {x: 0, y: 0, z: 0.018966928}
+ serializedVersion: 2
+ m_Size: {x: 0.8377218, y: 0.55013984, z: 0.8510349}
+ m_Center: {x: -0.0015015602, y: 0.2526749, z: 0.011384085}
--- !u!1 &6860398699643004296
GameObject:
m_ObjectHideFlags: 0
@@ -134,6 +133,11 @@ PrefabInstance:
propertyPath: m_Name
value: Bush
objectReference: {fileID: 0}
+ - target: {fileID: 919132149155446097, guid: 9659edb29993c4ba2a4f75b3265d81de,
+ type: 3}
+ propertyPath: m_TagString
+ value: Bush
+ objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 9659edb29993c4ba2a4f75b3265d81de,
type: 3}
propertyPath: m_NavMeshLayer
diff --git a/UOP1_Project/Assets/Prefabs/Nature/BushThick2.prefab b/UOP1_Project/Assets/Prefabs/Nature/BushThick2.prefab
index 813207c23..8528e2823 100644
--- a/UOP1_Project/Assets/Prefabs/Nature/BushThick2.prefab
+++ b/UOP1_Project/Assets/Prefabs/Nature/BushThick2.prefab
@@ -42,8 +42,8 @@ LightProbeGroup:
m_SourcePositions:
- {x: 0, y: 0.74264735, z: -0.00000002371987}
m_Dering: 1
---- !u!136 &4946972002693030379
-CapsuleCollider:
+--- !u!65 &967800462607294721
+BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@@ -52,10 +52,9 @@ CapsuleCollider:
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
- m_Radius: 0.45
- m_Height: 1.34
- m_Direction: 0
- m_Center: {x: 0, y: 0.18, z: 0}
+ serializedVersion: 2
+ m_Size: {x: 1.0791984, y: 0.5343887, z: 0.839382}
+ m_Center: {x: -0.025821447, y: 0.26473704, z: -0.022540838}
--- !u!1001 &3596012594732811070
PrefabInstance:
m_ObjectHideFlags: 0
@@ -133,6 +132,11 @@ PrefabInstance:
propertyPath: m_Name
value: BushThick2
objectReference: {fileID: 0}
+ - target: {fileID: 919132149155446097, guid: 1d579b5b4d7455941a284294eecc3c1d,
+ type: 3}
+ propertyPath: m_TagString
+ value: Bush
+ objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 1d579b5b4d7455941a284294eecc3c1d,
type: 3}
propertyPath: m_NavMeshLayer
diff --git a/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs b/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs
index c390ca7aa..57814fdfd 100644
--- a/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs
+++ b/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs
@@ -1,139 +1,165 @@
-using System;
-using UnityEngine;
-
-///
-/// This component consumes input on the InputReader and stores its values. The input is then read, and manipulated, by the StateMachines's Actions.
-///
-public class Protagonist : MonoBehaviour
-{
- [SerializeField] private InputReader _inputReader = default;
- [SerializeField] private TransformAnchor _gameplayCameraTransform = default;
-
- private Vector2 _inputVector;
- private float _previousSpeed;
-
- //These fields are read and manipulated by the StateMachine actions
- [NonSerialized] public bool jumpInput;
- [NonSerialized] public bool extraActionInput;
- [NonSerialized] public bool attackInput;
- [NonSerialized] public Vector3 movementInput; //Initial input coming from the Protagonist script
- [NonSerialized] public Vector3 movementVector; //Final movement vector, manipulated by the StateMachine actions
- [NonSerialized] public ControllerColliderHit lastHit;
- [NonSerialized] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1
-
- public const float GRAVITY_MULTIPLIER = 5f;
- public const float MAX_FALL_SPEED = -50f;
- public const float MAX_RISE_SPEED = 100f;
- public const float GRAVITY_COMEBACK_MULTIPLIER = .03f;
- public const float GRAVITY_DIVIDER = .6f;
- public const float AIR_RESISTANCE = 5f;
-
- private void OnControllerColliderHit(ControllerColliderHit hit)
- {
- lastHit = hit;
- }
-
- //Adds listeners for events being triggered in the InputReader script
- private void OnEnable()
- {
- _inputReader.JumpEvent += OnJumpInitiated;
- _inputReader.JumpCanceledEvent += OnJumpCanceled;
- _inputReader.MoveEvent += OnMove;
- _inputReader.StartedRunning += OnStartedRunning;
- _inputReader.StoppedRunning += OnStoppedRunning;
- _inputReader.AttackEvent += OnStartedAttack;
- //...
- }
-
- //Removes all listeners to the events coming from the InputReader script
- private void OnDisable()
- {
- _inputReader.JumpEvent -= OnJumpInitiated;
- _inputReader.JumpCanceledEvent -= OnJumpCanceled;
- _inputReader.MoveEvent -= OnMove;
- _inputReader.StartedRunning -= OnStartedRunning;
- _inputReader.StoppedRunning -= OnStoppedRunning;
- _inputReader.AttackEvent -= OnStartedAttack;
- //...
- }
-
- private void Update()
- {
- RecalculateMovement();
- }
-
- private void RecalculateMovement()
- {
- float targetSpeed;
- Vector3 adjustedMovement;
-
- if (_gameplayCameraTransform.isSet)
- {
- //Get the two axes from the camera and flatten them on the XZ plane
- Vector3 cameraForward = _gameplayCameraTransform.Value.forward;
- cameraForward.y = 0f;
- Vector3 cameraRight = _gameplayCameraTransform.Value.right;
- cameraRight.y = 0f;
-
- //Use the two axes, modulated by the corresponding inputs, and construct the final vector
- adjustedMovement = cameraRight.normalized * _inputVector.x +
- cameraForward.normalized * _inputVector.y;
- }
- else
- {
- //No CameraManager exists in the scene, so the input is just used absolute in world-space
- Debug.LogWarning("No gameplay camera in the scene. Movement orientation will not be correct.");
- adjustedMovement = new Vector3(_inputVector.x, 0f, _inputVector.y);
- }
-
- //Fix to avoid getting a Vector3.zero vector, which would result in the player turning to x:0, z:0
- if (_inputVector.sqrMagnitude == 0f)
- adjustedMovement = transform.forward * (adjustedMovement.magnitude + .01f);
-
- //Accelerate/decelerate
- targetSpeed = Mathf.Clamp01(_inputVector.magnitude);
- if (targetSpeed > 0f)
- {
- // This is used to set the speed to the maximum if holding the Shift key,
- // to allow keyboard players to "run"
- if (isRunning)
- targetSpeed = 1f;
-
- if (attackInput)
- targetSpeed = .05f;
- }
- targetSpeed = Mathf.Lerp(_previousSpeed, targetSpeed, Time.deltaTime * 4f);
-
- movementInput = adjustedMovement.normalized * targetSpeed;
-
- _previousSpeed = targetSpeed;
- }
-
- //---- EVENT LISTENERS ----
-
- private void OnMove(Vector2 movement)
- {
-
- _inputVector = movement;
- }
-
- private void OnJumpInitiated()
- {
- jumpInput = true;
- }
-
- private void OnJumpCanceled()
- {
- jumpInput = false;
- }
-
- private void OnStoppedRunning() => isRunning = false;
-
- private void OnStartedRunning() => isRunning = true;
-
-
- private void OnStartedAttack() => attackInput = true;
-
- // Triggered from Animation Event
- public void ConsumeAttackInput() => attackInput = false;
-}
+using System;
+using UnityEngine;
+
+///
+/// This component consumes input on the InputReader and stores its values. The input is then read, and manipulated, by the StateMachines's Actions.
+///
+public class Protagonist : MonoBehaviour
+{
+ [SerializeField] private InputReader _inputReader = default;
+ [SerializeField] private TransformAnchor _gameplayCameraTransform = default;
+
+ private Vector2 _inputVector;
+ private float _previousSpeed;
+
+ // For the slime/bush hopping bug: sets the max distance between player and object allowed when colliders clip
+ public float maxDistance = 0.5f;
+
+ //These fields are read and manipulated by the StateMachine actions
+ [NonSerialized] public bool jumpInput;
+ [NonSerialized] public bool extraActionInput;
+ [NonSerialized] public bool attackInput;
+ [NonSerialized] public Vector3 movementInput; //Initial input coming from the Protagonist script
+ [NonSerialized] public Vector3 movementVector; //Final movement vector, manipulated by the StateMachine actions
+ [NonSerialized] public ControllerColliderHit lastHit;
+ [NonSerialized] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1
+
+ public const float GRAVITY_MULTIPLIER = 5f;
+ public const float MAX_FALL_SPEED = -50f;
+ public const float MAX_RISE_SPEED = 100f;
+ public const float GRAVITY_COMEBACK_MULTIPLIER = .03f;
+ public const float GRAVITY_DIVIDER = .6f;
+ public const float AIR_RESISTANCE = 5f;
+
+ private void OnControllerColliderHit(ControllerColliderHit hit)
+ {
+ lastHit = hit;
+ }
+
+ //Adds listeners for events being triggered in the InputReader script
+ private void OnEnable()
+ {
+ _inputReader.JumpEvent += OnJumpInitiated;
+ _inputReader.JumpCanceledEvent += OnJumpCanceled;
+ _inputReader.MoveEvent += OnMove;
+ _inputReader.StartedRunning += OnStartedRunning;
+ _inputReader.StoppedRunning += OnStoppedRunning;
+ _inputReader.AttackEvent += OnStartedAttack;
+ //...
+ }
+
+ //Removes all listeners to the events coming from the InputReader script
+ private void OnDisable()
+ {
+ _inputReader.JumpEvent -= OnJumpInitiated;
+ _inputReader.JumpCanceledEvent -= OnJumpCanceled;
+ _inputReader.MoveEvent -= OnMove;
+ _inputReader.StartedRunning -= OnStartedRunning;
+ _inputReader.StoppedRunning -= OnStoppedRunning;
+ _inputReader.AttackEvent -= OnStartedAttack;
+ //...
+ }
+
+ private void Update()
+ {
+ RecalculateMovement();
+ }
+
+ private void RecalculateMovement()
+ {
+ float targetSpeed;
+ Vector3 adjustedMovement;
+
+ if (_gameplayCameraTransform.isSet)
+ {
+ //Get the two axes from the camera and flatten them on the XZ plane
+ Vector3 cameraForward = _gameplayCameraTransform.Value.forward;
+ cameraForward.y = 0f;
+ Vector3 cameraRight = _gameplayCameraTransform.Value.right;
+ cameraRight.y = 0f;
+
+ //Use the two axes, modulated by the corresponding inputs, and construct the final vector
+ adjustedMovement = cameraRight.normalized * _inputVector.x +
+ cameraForward.normalized * _inputVector.y;
+ }
+ else
+ {
+ //No CameraManager exists in the scene, so the input is just used absolute in world-space
+ Debug.LogWarning("No gameplay camera in the scene. Movement orientation will not be correct.");
+ adjustedMovement = new Vector3(_inputVector.x, 0f, _inputVector.y);
+ }
+
+ //Fix to avoid getting a Vector3.zero vector, which would result in the player turning to x:0, z:0
+ if (_inputVector.sqrMagnitude == 0f)
+ adjustedMovement = transform.forward * (adjustedMovement.magnitude + .01f);
+
+ //Accelerate/decelerate
+ targetSpeed = Mathf.Clamp01(_inputVector.magnitude);
+ if (targetSpeed > 0f)
+ {
+ // This is used to set the speed to the maximum if holding the Shift key,
+ // to allow keyboard players to "run"
+ if (isRunning)
+ targetSpeed = 1f;
+
+ if (attackInput)
+ targetSpeed = .05f;
+ }
+ targetSpeed = Mathf.Lerp(_previousSpeed, targetSpeed, Time.deltaTime * 4f);
+
+ movementInput = adjustedMovement.normalized * targetSpeed;
+
+ _previousSpeed = targetSpeed;
+ }
+
+ //---- EVENT LISTENERS ----
+
+ private void OnMove(Vector2 movement)
+ {
+
+ _inputVector = movement;
+ }
+
+ private void OnJumpInitiated()
+ {
+ jumpInput = true;
+ }
+
+ private void OnJumpCanceled()
+ {
+ jumpInput = false;
+ }
+
+ private void OnStoppedRunning() => isRunning = false;
+
+ private void OnStartedRunning() => isRunning = true;
+
+
+ private void OnStartedAttack() => attackInput = true;
+
+ // Triggered from Animation Event
+ public void ConsumeAttackInput() => attackInput = false;
+
+ //---- Slime/bush hopping fail-safe ----
+ private void OnCollisionStay(Collision collision)
+ {
+ // If the player has continued contact with a critter or bush object
+ if (collision.gameObject.tag == "Critter" || collision.gameObject.tag == "Bush")
+ {
+ // Calculates the distance between the player and the object
+ float distance = Vector3.Distance(collision.gameObject.transform.position, this.transform.position);
+ // Checks if colliders are clipping
+ if (distance <= maxDistance)
+ {
+ // Calculates the direction between the player and object
+ Vector3 direction = collision.gameObject.transform.position - this.transform.position;
+ // Sets vertical direction to 0, to prevent hopping
+ direction.y = 0f;
+
+ // Calculates new position for player to move outside of clipped collider based on direction
+ Vector3 newPos = this.transform.position + direction.normalized * (maxDistance - distance);
+ this.transform.position = Vector3.Lerp(this.transform.position, newPos, Time.deltaTime);
+ }
+ }
+ }
+}
diff --git a/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs.meta b/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs.meta
index d29a40c25..26efcc238 100644
--- a/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs.meta
+++ b/UOP1_Project/Assets/Scripts/Characters/Protagonist.cs.meta
@@ -1,14 +1,14 @@
-fileFormatVersion: 2
-guid: 45f6466be0a32e746abeb31b2a794001
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences:
- - _inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
- - gameplayCameraTransform: {fileID: 11400000, guid: bc205269957643647a8b5f98f028f9fb,
- type: 2}
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
+fileFormatVersion: 2
+guid: 45f6466be0a32e746abeb31b2a794001
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences:
+ - _inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
+ - gameplayCameraTransform: {fileID: 11400000, guid: bc205269957643647a8b5f98f028f9fb,
+ type: 2}
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: