diff --git a/Assets/Prefabs/PlayerBelongings.prefab b/Assets/Prefabs/PlayerBelongings.prefab index 0a7003c2..28493f2b 100644 --- a/Assets/Prefabs/PlayerBelongings.prefab +++ b/Assets/Prefabs/PlayerBelongings.prefab @@ -2629,25 +2629,17 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 23851ed43df78d3489915c8a195d9036, type: 3} m_Name: m_EditorClassIdentifier: - body: {fileID: 2356435387424043641} + isAirborne: 0 + isRunning: 0 + isSneaking: 0 + dialogueInterface: {fileID: 7994511833790087655} + interactor: {fileID: 2356435387424043642} inventory: {fileID: 5251964727823270906} + mouseSensitivity: 250 + pauseMenu: {fileID: 3412898498111374142} playerCameraTransform: {fileID: 5496631978485877498} - rigidbody: {fileID: 2356435387424043640} - groundDetector: {fileID: 2356435386095074309} - interactor: {fileID: 2356435387424043642} playerProperties: {fileID: 2356435387424043644} - questlog: {fileID: 0} questDisplay: {fileID: 7585652203083821388} - questjournalSearchbar: {fileID: 7519064917230829377} - pauseMenu: {fileID: 3412898498111374142} - mouseSensitivity: 250 - isRunning: 0 - isSneaking: 0 - sneakSlow: 0.7 - isAirborne: 0 - isSprinting: 0 - sprintBoost: 1.3 - dialogueInterface: {fileID: 7994511833790087655} --- !u!65 &2356435387424043643 BoxCollider: m_ObjectHideFlags: 0 @@ -2712,6 +2704,7 @@ MonoBehaviour: speed: {fileID: 11400000, guid: da106d5806969c14693d9c523cd6f87d, type: 2} sneakMultiplier: 0.7 runMultiplier: 2 + sidewaysMultiplier: 0.7 jumpPower: 450 weight: {fileID: 11400000, guid: 614a093e4ff687f47b74804bf6ef4bea, type: 2} maxWeight: {fileID: 11400000, guid: 1b6144f0b378a564184f78a60f5a177e, type: 2} @@ -8973,34 +8966,16 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 24317b369c54e2143af902331f595adf, type: 3} ---- !u!1 &4666713041352449235 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 1338428400787657039, guid: 24317b369c54e2143af902331f595adf, - type: 3} - m_PrefabInstance: {fileID: 5931367441388064156} - m_PrefabAsset: {fileID: 0} ---- !u!1 &3047925629568477781 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8654822773299619785, guid: 24317b369c54e2143af902331f595adf, - type: 3} - m_PrefabInstance: {fileID: 5931367441388064156} - m_PrefabAsset: {fileID: 0} ---- !u!224 &7567846488276705717 stripped -RectTransform: - m_CorrespondingSourceObject: {fileID: 4275630235739450409, guid: 24317b369c54e2143af902331f595adf, - type: 3} - m_PrefabInstance: {fileID: 5931367441388064156} - m_PrefabAsset: {fileID: 0} ---- !u!114 &1099457508181913526 stripped +--- !u!114 &7585652203083821388 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 6706560802818712106, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 4257543492969479376, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4666713041352449235} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e64b2bbe094026a4299165af1a474ab1, type: 3} + m_Script: {fileID: 11500000, guid: 422b3d1f0377a0d47acb782b4a7682ad, type: 3} m_Name: m_EditorClassIdentifier: --- !u!114 &4135858231327417772 stripped @@ -9015,18 +8990,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f4e3ec7d8aceeb94c84f0b3d14916afd, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7585652203083821388 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4257543492969479376, guid: 24317b369c54e2143af902331f595adf, - type: 3} - m_PrefabInstance: {fileID: 5931367441388064156} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4666713041352449235} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 422b3d1f0377a0d47acb782b4a7682ad, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!114 &8742905801970135246 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 3100017794379513170, guid: 24317b369c54e2143af902331f595adf, @@ -9039,39 +9002,57 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &2356435386368203710 stripped +--- !u!114 &7383090374177351392 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 8278687299762640418, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 3757817180409998204, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Script: {fileID: 11500000, guid: 365c0483be2f4425be4ad86611a43d47, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7383090374177351392 stripped +--- !u!1 &4666713041352449235 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1338428400787657039, guid: 24317b369c54e2143af902331f595adf, + type: 3} + m_PrefabInstance: {fileID: 5931367441388064156} + m_PrefabAsset: {fileID: 0} +--- !u!1 &3047925629568477781 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 8654822773299619785, guid: 24317b369c54e2143af902331f595adf, + type: 3} + m_PrefabInstance: {fileID: 5931367441388064156} + m_PrefabAsset: {fileID: 0} +--- !u!224 &7567846488276705717 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 4275630235739450409, guid: 24317b369c54e2143af902331f595adf, + type: 3} + m_PrefabInstance: {fileID: 5931367441388064156} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1099457508181913526 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 3757817180409998204, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 6706560802818712106, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 4666713041352449235} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 365c0483be2f4425be4ad86611a43d47, type: 3} + m_Script: {fileID: 11500000, guid: e64b2bbe094026a4299165af1a474ab1, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7519064917230829377 stripped +--- !u!114 &2356435386368203710 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4181986942095061725, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 8278687299762640418, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 2da0c512f12947e489f739169773d7ca, type: 3} + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index df680c00..62b0007d 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -8893,6 +8893,31 @@ PrefabInstance: propertyPath: m_Name value: PlayerBelongings objectReference: {fileID: 0} + - target: {fileID: 2356435387424043641, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356435387424043641, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356435387424043641, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2356435387424043641, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2356435387424043641, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} - target: {fileID: 4135858231327417772, guid: d5177fd664a14c0418bd57f76722b517, type: 3} propertyPath: questInteractables @@ -8913,6 +8938,26 @@ PrefabInstance: propertyPath: m_SizeDelta.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 6115537310667178606, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_Name + value: Player + objectReference: {fileID: 0} + - target: {fileID: 7099248684761739389, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7099248684761739389, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7099248684761739389, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8218561273732356039, guid: d5177fd664a14c0418bd57f76722b517, type: 3} propertyPath: m_AnchorMin.y diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs new file mode 100644 index 00000000..37831dd2 --- /dev/null +++ b/Assets/Scripts/Character/CharacterController.cs @@ -0,0 +1,154 @@ +using Character.Player; +using Sounds.Manager; +using UnityEngine; + +namespace Character +{ + [RequireComponent(typeof(Rigidbody))] + [RequireComponent(typeof(CharacterSounds))] + public class CharacterController : MonoBehaviour + + { + private GroundDetector _groundDetector; + private Rigidbody _rigidbody; + + [Header("State Attributes")] public JumpStatus isAirborne; + public bool isRunning; + public bool isSneaking; + + public CharacterSounds Sounds { get; set; } + + protected virtual void Start() + { + _rigidbody = GetComponent(); + _groundDetector = GetComponentInChildren(); + Sounds = GetComponent(); + } + + protected virtual void Update() + { + // check if the player in the Air or not + isAirborne = _groundDetector.currentCollisions.Count == 0 ? JumpStatus.InAir : JumpStatus.OnGround; + } + + public void Movement(float horizontal, float vertical, CharacterProperties properties) + { + float speed = properties.speed.Value; + float runMultiplier = properties.runMultiplier; + float sneakMultiplier = properties.sneakMultiplier; + float sidewaysMultiplier = properties.sidewaysMultiplier; + + // TODO: fully convert to StatAttribute + // get the actual speed with all modifications + if (isRunning) + speed *= runMultiplier; + if (isSneaking) + speed *= sneakMultiplier; + + // makes sure that sideways/backwards walking is slower than forward walking + if (Mathf.Abs(horizontal) > 0.01 || vertical < -0.01) + speed *= sidewaysMultiplier; + + Vector3 inputVelocity = (transform.forward * vertical) + (transform.right * horizontal); + Vector3 inputPlaneVelocity = new Vector3(inputVelocity.x, 0, inputVelocity.z).normalized; + + if (CheckWalkableTerrain(_groundDetector.transform.position, inputPlaneVelocity, 5f)) + { + // makes sure, that the total velocity is not higher while walking cross-ways + if (inputVelocity.magnitude > 1.01) + { + inputVelocity.x = inputPlaneVelocity.x; + inputVelocity.z = inputPlaneVelocity.z; + } + + inputVelocity *= speed; + + // manages movement depending on being airborne or not + if (isAirborne == JumpStatus.OnGround) + { + inputVelocity.y = _rigidbody.velocity.y; + _rigidbody.velocity = inputVelocity; + } + else + { + inputVelocity.y = 0; + + _rigidbody.AddForce(inputVelocity, ForceMode.Impulse); + + // make sure, that the player is not able to be faster then the momentarily speed level is allowing him to be + inputVelocity = _rigidbody.velocity; + inputVelocity.y = 0; + inputVelocity = inputVelocity.normalized * Mathf.Clamp(inputVelocity.magnitude, 0, speed); + inputVelocity.y = _rigidbody.velocity.y; + + _rigidbody.velocity = inputVelocity; + } + } + else + { + // stops the player at an instant if the terrain is not movable + _rigidbody.velocity = Vector3.zero; + } + + PlaySoundForMovement(inputVelocity); + } + + private void PlaySoundForMovement(Vector3 velocity) + { + if (isRunning && velocity.magnitude > 0.1f && isAirborne == JumpStatus.OnGround) + { + Sounds.Running(_groundDetector.GroundType); + } + else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == JumpStatus.OnGround) + { + Sounds.Sneaking(_groundDetector.GroundType); + } + //TODO: replace with isWalking flag + else if (isAirborne == 0 && velocity.magnitude > 0.1f) + { + Sounds.Walking(_groundDetector.GroundType); + } + else + { + Sounds.StopMovement(); + } + } + + public void Rotation(float rotationX, float sensitivity = 1f) + { + // get mouse Inputs + rotationX = Mathf.Clamp(rotationX, -10, 10); + + Vector3 bodyRotation = new Vector3(0, rotationX, 0); + transform.Rotate(bodyRotation * (sensitivity * Time.deltaTime), Space.Self); + } + + public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, float distance) + { + Ray slopeRay = new Ray(position, desiredDirection); + + if (!Physics.Raycast(slopeRay, out RaycastHit hit, distance)) + return true; + if (hit.collider.gameObject.tag is "Interactable") + return true; + + // get the angle between the up vector and the hit game object + float slopeAngle = Vector3.Angle(Vector3.up, hit.normal); + if (slopeAngle <= 45f) + return true; + return hit.distance >= 0.26f; + } + + public void Jump(float jumpPower) + { + if (isAirborne != JumpStatus.OnGround) + return; + + Vector3 vel = _rigidbody.velocity; + vel.y = 0; + _rigidbody.velocity = vel; + + _rigidbody.AddForce(jumpPower * Vector3.up, ForceMode.Impulse); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Character/CharacterController.cs.meta b/Assets/Scripts/Character/CharacterController.cs.meta new file mode 100644 index 00000000..b56dfcb5 --- /dev/null +++ b/Assets/Scripts/Character/CharacterController.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 57a3805a19784692a8bc8acc2d461818 +timeCreated: 1590175418 \ No newline at end of file diff --git a/Assets/Scripts/Character/CharacterProperties.cs b/Assets/Scripts/Character/CharacterProperties.cs index a28e4241..baa7c2b2 100644 --- a/Assets/Scripts/Character/CharacterProperties.cs +++ b/Assets/Scripts/Character/CharacterProperties.cs @@ -16,6 +16,7 @@ public abstract class CharacterProperties : AttributeHolder [Header("Speed values")] public StatAttribute speed; public float sneakMultiplier = 0.7f; public float runMultiplier = 2f; + public float sidewaysMultiplier = 0.7f; public float jumpPower = 450f; diff --git a/Assets/Scripts/Character/JumpStatus.cs b/Assets/Scripts/Character/JumpStatus.cs new file mode 100644 index 00000000..cbd95abd --- /dev/null +++ b/Assets/Scripts/Character/JumpStatus.cs @@ -0,0 +1,8 @@ +namespace Character +{ + public enum JumpStatus + { + OnGround, + InAir + } +} \ No newline at end of file diff --git a/Assets/Scripts/Character/JumpStatus.cs.meta b/Assets/Scripts/Character/JumpStatus.cs.meta new file mode 100644 index 00000000..fda05571 --- /dev/null +++ b/Assets/Scripts/Character/JumpStatus.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8a6b54182916459abd6e7c1ca3586c8e +timeCreated: 1590676262 \ No newline at end of file diff --git a/Assets/Scripts/Character/NPC/NPCProperties.cs.meta b/Assets/Scripts/Character/NPC/NPCProperties.cs.meta deleted file mode 100644 index aa299369..00000000 --- a/Assets/Scripts/Character/NPC/NPCProperties.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 209c8f3ff3934c418ad8995b27e49987 -timeCreated: 1589021642 \ No newline at end of file diff --git a/Assets/Scripts/Character/NPC/NpcProperties.cs.meta b/Assets/Scripts/Character/NPC/NpcProperties.cs.meta index aa299369..5ac0ff8d 100644 --- a/Assets/Scripts/Character/NPC/NpcProperties.cs.meta +++ b/Assets/Scripts/Character/NPC/NpcProperties.cs.meta @@ -1,3 +1,3 @@ fileFormatVersion: 2 -guid: 209c8f3ff3934c418ad8995b27e49987 +guid: 16c4e6d3ad9882bdf8abf766d5dbc7f2 timeCreated: 1589021642 \ No newline at end of file diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 0efe9392..0c4d7963 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -2,68 +2,44 @@ using System.Linq; using Interaction; using Sounds.Manager; -using TMPro; using UnityEngine; namespace Character.Player { - public class PlayerController : MonoBehaviour + public class PlayerController : CharacterController { - [Header("References")] public Transform body; + private MusicManager _musicManager; + private List _soundManagers; - public Inventory inventory; - public Transform playerCameraTransform; - public new Rigidbody rigidbody; - public GroundDetector groundDetector; + public GameObject dialogueInterface; public Interactor interactor; - public PlayerProperties playerProperties; - public Questlog questlog; - public QuestjournalDisplay questDisplay; - public TMP_InputField questjournalSearchbar; - - [Header("Menu References")] public PauseMenu pauseMenu; - [Header("Mouse settings")] public float mouseSensitivity; - - [Header("Player State Attributes")] public bool isRunning = false; + public Inventory inventory; - public bool isSneaking = false; - public float sneakSlow = 0.7f; - public float isAirborne = 0; // 0: on Ground; 1: on the way back down; 2: just jumped - public bool isSprinting = false; - public float sprintBoost = 1.3f; - private CharacterSounds _characterSounds; - private List _soundManagers; - private MusicManager _musicManager; + [Header("Mouse settings")] public float mouseSensitivity; - public GameObject dialogueInterface; + [Header("Menu References")] public PauseMenu pauseMenu; + public Transform playerCameraTransform; + public PlayerProperties playerProperties; + public QuestjournalDisplay questDisplay; private void Start() { - playerCameraTransform.rotation = Quaternion.identity; + base.Start(); + + playerCameraTransform = Camera.main.transform; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; - _characterSounds = GetComponent(); _musicManager = GetComponent(); _soundManagers = FindObjectsOfType().OfType().ToList(); } - private void Update() + protected override void Update() { - // the only input detection that needs to be outside of the menu detection - if (Input.GetKeyDown(KeyCode.O)) - { - Cursor.visible = true; - Cursor.lockState = CursorLockMode.None; - } - - if (Input.GetKeyDown(KeyCode.J) && !questjournalSearchbar.isFocused) - { - questDisplay.Toggle(); - } + base.Update(); if (Input.GetKeyDown(KeyCode.Escape)) { @@ -82,25 +58,46 @@ private void Update() // menu detection: If no menu is active, enable input if (Input.GetKeyDown(KeyCode.I)) inventory.inventoryDisplay.Toggle(); - if (CloseableMenu.openMenues.Count == 0 && dialogueInterface.activeSelf == false) - { - // get all Inputs and calls the methods - if (Input.GetButtonDown("Walk/Run")) - isRunning = !isRunning; - if (Input.GetButtonDown("Jump")) - Jump(); - if (Input.GetButtonDown("Interact")) - interactor.KeyDown(); - if (Input.GetButtonDown("Sneak")) - ToggleSneak(); - Movement(); - Rotation(); + if (Input.GetKeyDown(KeyCode.J)) + questDisplay.Toggle(); + + if (CloseableMenu.openMenues.Count != 0 || dialogueInterface.activeSelf) + return; + + if (Input.GetKeyDown(KeyCode.O)) + { + if (Cursor.visible) + { + Cursor.visible = false; + Cursor.lockState = CursorLockMode.Locked; + } + else + { + Cursor.visible = true; + Cursor.lockState = CursorLockMode.None; + } } - // check if the player in the Air or not - if (groundDetector.currentCollisions.Count == 0) isAirborne = 1; - if (groundDetector.currentCollisions.Count > 0) isAirborne = 0; + // get all Inputs and calls the methods + if (Input.GetButtonDown("Walk/Run")) + isRunning = !isRunning; + if (Input.GetButtonDown("Jump")) + Jump(playerProperties.jumpPower); + if (Input.GetButtonDown("Interact")) + interactor.KeyDown(); + if (Input.GetButtonDown("Sneak")) + ToggleSneak(); + + float horizontal = Input.GetAxis("Horizontal"); + float vertical = Input.GetAxis("Vertical"); + Movement(horizontal, vertical, playerProperties); + + float rotationX = Input.GetAxis("Mouse X"); + Rotation(rotationX, mouseSensitivity); + + float rotationY = Input.GetAxis("Mouse Y"); + RotateCamera(rotationY); } private void FindAndPauseSounds() @@ -120,153 +117,28 @@ private void FindAndPauseSounds() }); } - private void Jump() - { - if (groundDetector.currentCollisions.Count != 0) - { - Vector3 vel = new Vector3(rigidbody.velocity.x, 0, rigidbody.velocity.z); - rigidbody.velocity = vel; - Vector3 jumpForce = new Vector3(0, playerProperties.jumpPower, 0); - rigidbody.AddForce(jumpForce, ForceMode.Impulse); - } - } - private void ToggleSneak() { - isSneaking = !isSneaking; if (isSneaking) { + isSneaking = false; playerCameraTransform.position -= new Vector3(0f, 0.5f, 0f); } else { + isSneaking = true; playerCameraTransform.position += new Vector3(0f, 0.5f, 0f); } } - private void Movement() + private void RotateCamera(float rotationY) { - // TODO: fully convert to StatAttribute - // get the actual speed with all modificators - float speed = playerProperties.speed.Value; - if (isRunning) - speed *= playerProperties.runMultiplier; - if (isSneaking) - speed *= playerProperties.sneakMultiplier; - - // get the inputs - float horizontal = Input.GetAxis("Horizontal"); - float vertical = Input.GetAxis("Vertical"); - - // makes sure that sideway walking is slower than forward walking - if (vertical < -0.01) speed *= 0.7f; - - Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); - - if (CheckMoveableTerrain( - new Vector3(playerCameraTransform.position.x, playerCameraTransform.position.y - 1.7f, - playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) - { - // makes sure, that the total veloctity is not higher while walking cross-ways - if (velocity.magnitude > 1.01) - { - float ySaver = velocity.y; - velocity.y = 0; - velocity = velocity.normalized; - velocity.y = ySaver; - } - - // manages movement depending on being airborne or not - if (isAirborne == 0) - { - velocity *= speed; - velocity.y = rigidbody.velocity.y; - rigidbody.velocity = velocity; - } - else - { - velocity *= speed; - velocity.y = 0; - - rigidbody.AddForce(velocity, ForceMode.Impulse); - - // make sure, that the player is not able to be faster then the momentarily speed level is allowing him to be - velocity = rigidbody.velocity; - velocity.y = 0; - velocity = velocity.normalized * Mathf.Clamp(velocity.magnitude, 0, speed); - velocity.y = rigidbody.velocity.y; - - rigidbody.velocity = velocity; - } - } - else - { - rigidbody.velocity = - new Vector3(0f, 0f, 0f); // stops the player at an instant if the terrain is not movable - } - - if (isRunning && velocity.magnitude > 0.1f && isAirborne == 0) + Vector3 cameraRotation = new Vector3(-rotationY, 0, 0) * (mouseSensitivity * Time.deltaTime); + float x = (playerCameraTransform.eulerAngles + cameraRotation).x; + if (x >= -90 && x <= 90 || x >= 270 && x <= 450) { - _characterSounds.Running(groundDetector.GroundType); + playerCameraTransform.Rotate(cameraRotation, Space.Self); } - else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == 0) - { - _characterSounds.Sneaking(groundDetector.GroundType); - } - //TODO: replace with isWalking flag - else if (isAirborne == 0 && velocity.magnitude > 0.1f) - { - _characterSounds.Walking(groundDetector.GroundType); - } - else - { - _characterSounds.StopMovement(); - } - } - - private void Rotation() - { - // get mouse Inputs - float mouseX = Input.GetAxis("Mouse X"); - float mouseY = Input.GetAxis("Mouse Y"); - mouseX = Mathf.Clamp(mouseX, -10, 10); - mouseY = Mathf.Clamp(mouseY, -10, 10); - - Vector3 bodyRotation = new Vector3(0, mouseX, 0); - body.Rotate(bodyRotation * mouseSensitivity * Time.deltaTime, Space.Self); - - Vector3 cameraRotation = new Vector3(-mouseY, 0, 0); - if (((playerCameraTransform.eulerAngles + cameraRotation * mouseSensitivity * Time.deltaTime).x >= -90 && - (playerCameraTransform.eulerAngles + cameraRotation * mouseSensitivity * Time.deltaTime).x <= 90) || - ((playerCameraTransform.eulerAngles + cameraRotation * mouseSensitivity * Time.deltaTime).x >= 270 && - (playerCameraTransform.eulerAngles + cameraRotation * mouseSensitivity * Time.deltaTime).x <= 450)) - { - playerCameraTransform.Rotate(cameraRotation * mouseSensitivity * Time.deltaTime, Space.Self); - } - } - - private bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, float distance) - { - Ray slopeRay = new Ray(position, desiredDirection); - RaycastHit hit; - - if (Physics.Raycast(slopeRay, out hit, distance)) - { - if (!(hit.collider.gameObject.tag is "Interactable")) - { - float slopeAngle = - Vector3.Angle(Vector3.up, hit.normal); // get the angle between the up vector and the hit gameobject - if (slopeAngle > 45f) // check if the slope angle if above a certain degree - { - if (hit.distance < 0.26f) // check if the hit gameobject is close - { - return false; - } - } - } - } - - return true; } } } \ No newline at end of file diff --git a/Assets/Scripts/Quest/QuestjournalDisplay.cs b/Assets/Scripts/Quest/QuestjournalDisplay.cs index 135d5bfb..0082bff5 100644 --- a/Assets/Scripts/Quest/QuestjournalDisplay.cs +++ b/Assets/Scripts/Quest/QuestjournalDisplay.cs @@ -1,5 +1,4 @@ -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -31,20 +30,27 @@ public class QuestjournalDisplay : CloseableMenu public string searchInput = ""; public string activeTab = "In Progress"; + public override void Show() { base.Show(); ShowQuests("In Progress", searchInput); FilterActiveQuests(); - + } + + public override void Toggle() + { + if (!searchFor.isFocused) + { + base.Toggle(); + } } public void TargetQuest(Quest quest) { quest.isTargetted = !quest.isTargetted; - Logger.log(""+quest.isTargetted); + Logger.log("" + quest.isTargetted); ManageMarker(quest); - } public void ManageMarker(Quest quest) @@ -67,7 +73,7 @@ public void ShowQuests(string status, string searchFilter) foreach (Quest quest in quests) { Logger.log("" + quest.questName); - GameObject instance = Instantiate(questObject, questobjectParent); + GameObject instance = Instantiate(questObject, questobjectParent); instance.GetComponent().Display(quest); instance.GetComponent