From 3c7772f35e2a6a110e7dc832be7460b074d20519 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:28:43 +0200 Subject: [PATCH 01/46] REFACTOR: move movement to CharacterController --- .../Scripts/Character/CharacterController.cs | 90 ++++++++++++ .../Character/CharacterController.cs.meta | 3 + .../Character/Player/PlayerController.cs | 131 +++++------------- 3 files changed, 124 insertions(+), 100 deletions(-) create mode 100644 Assets/Scripts/Character/CharacterController.cs create mode 100644 Assets/Scripts/Character/CharacterController.cs.meta diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs new file mode 100644 index 00000000..50c92df3 --- /dev/null +++ b/Assets/Scripts/Character/CharacterController.cs @@ -0,0 +1,90 @@ +using Character.Player; +using UnityEngine; + +namespace Character +{ + public class CharacterController : MonoBehaviour + + { + public void Movement(PlayerController playerController) + { + // TODO: fully convert to StatAttribute + // get the actual speed with all modificators + float speed = playerController.playerProperties.speed.Value; + if (playerController.isRunning) + speed *= playerController.playerProperties.runMultiplier; + if (playerController.isSneaking) + speed *= playerController.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 (playerController.CheckMoveableTerrain( + new Vector3(playerController.playerCameraTransform.position.x, + playerController.playerCameraTransform.position.y - 1.7f, + playerController.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 (playerController.isAirborne == 0) + { + velocity *= speed; + velocity.y = playerController.rigidbody.velocity.y; + playerController.rigidbody.velocity = velocity; + } + else + { + velocity *= speed; + velocity.y = 0; + + playerController.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 = playerController.rigidbody.velocity; + velocity.y = 0; + velocity = velocity.normalized * Mathf.Clamp(velocity.magnitude, 0, speed); + velocity.y = playerController.rigidbody.velocity.y; + + playerController.rigidbody.velocity = velocity; + } + } + else + { + playerController.rigidbody.velocity = + new Vector3(0f, 0f, 0f); // stops the player at an instant if the terrain is not movable + } + + if (playerController.isRunning && velocity.magnitude > 0.1f && playerController.isAirborne == 0) + { + playerController.CharacterSounds.Running(playerController.groundDetector.GroundType); + } + else if (playerController.isSneaking && velocity.magnitude > 0.1f && playerController.isAirborne == 0) + { + playerController.CharacterSounds.Sneaking(playerController.groundDetector.GroundType); + } + //TODO: replace with isWalking flag + else if (playerController.isAirborne == 0 && velocity.magnitude > 0.1f) + { + playerController.CharacterSounds.Walking(playerController.groundDetector.GroundType); + } + else + { + playerController.CharacterSounds.StopMovement(); + } + } + } +} \ 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/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 0efe9392..2563cae3 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -7,37 +7,45 @@ namespace Character.Player { + [RequireComponent(typeof(CharacterController))] public class PlayerController : MonoBehaviour { + private CharacterController _characterController; + + private CharacterSounds _characterSounds; + private MusicManager _musicManager; + private List _soundManagers; [Header("References")] public Transform body; - public Inventory inventory; - public Transform playerCameraTransform; - public new Rigidbody rigidbody; + public GameObject dialogueInterface; public GroundDetector groundDetector; 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; + public Inventory inventory; + public float isAirborne = 0; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning = false; 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; + public TMP_InputField questjournalSearchbar; + public Questlog questlog; + public new Rigidbody rigidbody; + public float sneakSlow = 0.7f; + public float sprintBoost = 1.3f; + + public CharacterSounds CharacterSounds + { + set { _characterSounds = value; } + get { return _characterSounds; } + } private void Start() { @@ -45,6 +53,8 @@ private void Start() Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; + _characterController = GetComponent(); + _characterSounds = GetComponent(); _musicManager = GetComponent(); @@ -94,7 +104,7 @@ private void Update() if (Input.GetButtonDown("Sneak")) ToggleSneak(); - Movement(); + _characterController.Movement(this); Rotation(); } @@ -144,86 +154,6 @@ private void ToggleSneak() } } - private void Movement() - { - // 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) - { - _characterSounds.Running(groundDetector.GroundType); - } - 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 @@ -245,7 +175,7 @@ private void Rotation() } } - private bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, float distance) + public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, float distance) { Ray slopeRay = new Ray(position, desiredDirection); RaycastHit hit; @@ -255,7 +185,8 @@ private bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, fl 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 + 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 From a15b7e51496027eb88a769784a1670dd480ca06e Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:30:27 +0200 Subject: [PATCH 02/46] REFACTOR: rotation so input method is not relevant --- .../Scripts/Character/Player/PlayerController.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 2563cae3..643b16bb 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -105,7 +105,7 @@ private void Update() ToggleSneak(); _characterController.Movement(this); - Rotation(); + Rotation(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); } // check if the player in the Air or not @@ -154,18 +154,16 @@ private void ToggleSneak() } } - private void Rotation() + private void Rotation(float rotationX, float rotationY) { // 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); + rotationX = Mathf.Clamp(rotationX, -10, 10); + rotationY = Mathf.Clamp(rotationY, -10, 10); - Vector3 bodyRotation = new Vector3(0, mouseX, 0); + Vector3 bodyRotation = new Vector3(0, rotationX, 0); body.Rotate(bodyRotation * mouseSensitivity * Time.deltaTime, Space.Self); - Vector3 cameraRotation = new Vector3(-mouseY, 0, 0); + Vector3 cameraRotation = new Vector3(-rotationY, 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 && From 53c6fe97b248388e2d2b62e85b171514943c58b4 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:31:08 +0200 Subject: [PATCH 03/46] REFACTOR: move rotation to character controller --- .../Scripts/Character/CharacterController.cs | 24 +++++++++++++++++++ .../Character/Player/PlayerController.cs | 21 +--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 50c92df3..947a6c6f 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -86,5 +86,29 @@ public void Movement(PlayerController playerController) playerController.CharacterSounds.StopMovement(); } } + + public void Rotation(float rotationX, float rotationY, PlayerController playerController) + { + // get mouse Inputs + rotationX = Mathf.Clamp(rotationX, -10, 10); + rotationY = Mathf.Clamp(rotationY, -10, 10); + + Vector3 bodyRotation = new Vector3(0, rotationX, 0); + playerController.body.Rotate(bodyRotation * playerController.mouseSensitivity * Time.deltaTime, Space.Self); + + Vector3 cameraRotation = new Vector3(-rotationY, 0, 0); + if (((playerController.playerCameraTransform.eulerAngles + + cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x >= -90 && + (playerController.playerCameraTransform.eulerAngles + + cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x <= 90) || + ((playerController.playerCameraTransform.eulerAngles + + cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x >= 270 && + (playerController.playerCameraTransform.eulerAngles + + cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x <= 450)) + { + playerController.playerCameraTransform.Rotate( + cameraRotation * playerController.mouseSensitivity * Time.deltaTime, Space.Self); + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 643b16bb..98829c04 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -105,7 +105,7 @@ private void Update() ToggleSneak(); _characterController.Movement(this); - Rotation(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); + _characterController.Rotation(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), this); } // check if the player in the Air or not @@ -154,25 +154,6 @@ private void ToggleSneak() } } - private void Rotation(float rotationX, float rotationY) - { - // get mouse Inputs - rotationX = Mathf.Clamp(rotationX, -10, 10); - rotationY = Mathf.Clamp(rotationY, -10, 10); - - Vector3 bodyRotation = new Vector3(0, rotationX, 0); - body.Rotate(bodyRotation * mouseSensitivity * Time.deltaTime, Space.Self); - - Vector3 cameraRotation = new Vector3(-rotationY, 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); - } - } - public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, float distance) { Ray slopeRay = new Ray(position, desiredDirection); From 19077d4efb44546ed942253558b68eb049b4e7ce Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:33:09 +0200 Subject: [PATCH 04/46] REFACTOR: extract method for playing sounds --- Assets/Scripts/Character/CharacterController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 947a6c6f..80d40fe5 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -68,6 +68,11 @@ public void Movement(PlayerController playerController) new Vector3(0f, 0f, 0f); // stops the player at an instant if the terrain is not movable } + PlaySoundForMovement(playerController, velocity); + } + + private static void PlaySoundForMovement(PlayerController playerController, Vector3 velocity) + { if (playerController.isRunning && velocity.magnitude > 0.1f && playerController.isAirborne == 0) { playerController.CharacterSounds.Running(playerController.groundDetector.GroundType); From 8950a7c8390fbe4c9c36cfb3f38d2cb684e12faa Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:37:20 +0200 Subject: [PATCH 05/46] REFACTOR: move character sounds to character controller --- .../Scripts/Character/CharacterController.cs | 20 ++++++++++++++----- .../Character/Player/PlayerController.cs | 7 ------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 80d40fe5..4c943c1b 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -1,11 +1,21 @@ using Character.Player; +using Sounds.Manager; using UnityEngine; namespace Character { + [RequireComponent(typeof(CharacterSounds))] public class CharacterController : MonoBehaviour { + public CharacterSounds CharacterSounds { get; set; } + + + private void Start() + { + CharacterSounds = GetComponent(); + } + public void Movement(PlayerController playerController) { // TODO: fully convert to StatAttribute @@ -71,24 +81,24 @@ public void Movement(PlayerController playerController) PlaySoundForMovement(playerController, velocity); } - private static void PlaySoundForMovement(PlayerController playerController, Vector3 velocity) + private void PlaySoundForMovement(PlayerController playerController, Vector3 velocity) { if (playerController.isRunning && velocity.magnitude > 0.1f && playerController.isAirborne == 0) { - playerController.CharacterSounds.Running(playerController.groundDetector.GroundType); + CharacterSounds.Running(playerController.groundDetector.GroundType); } else if (playerController.isSneaking && velocity.magnitude > 0.1f && playerController.isAirborne == 0) { - playerController.CharacterSounds.Sneaking(playerController.groundDetector.GroundType); + CharacterSounds.Sneaking(playerController.groundDetector.GroundType); } //TODO: replace with isWalking flag else if (playerController.isAirborne == 0 && velocity.magnitude > 0.1f) { - playerController.CharacterSounds.Walking(playerController.groundDetector.GroundType); + CharacterSounds.Walking(playerController.groundDetector.GroundType); } else { - playerController.CharacterSounds.StopMovement(); + CharacterSounds.StopMovement(); } } diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 98829c04..3917bb62 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -12,7 +12,6 @@ public class PlayerController : MonoBehaviour { private CharacterController _characterController; - private CharacterSounds _characterSounds; private MusicManager _musicManager; private List _soundManagers; [Header("References")] public Transform body; @@ -41,11 +40,6 @@ public class PlayerController : MonoBehaviour public float sneakSlow = 0.7f; public float sprintBoost = 1.3f; - public CharacterSounds CharacterSounds - { - set { _characterSounds = value; } - get { return _characterSounds; } - } private void Start() { @@ -55,7 +49,6 @@ private void Start() _characterController = GetComponent(); - _characterSounds = GetComponent(); _musicManager = GetComponent(); _soundManagers = FindObjectsOfType().OfType().ToList(); From 37d0470ff5db5a65b0f053d43fa039496d36356f Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:41:40 +0200 Subject: [PATCH 06/46] REFACTOR: move check moveable terrain --- .../Scripts/Character/CharacterController.cs | 27 +++++++++++++++- .../Character/Player/PlayerController.cs | 31 ++++--------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 4c943c1b..a654c549 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -35,7 +35,7 @@ public void Movement(PlayerController playerController) Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); - if (playerController.CheckMoveableTerrain( + if (playerController.CharacterController.CheckMoveableTerrain( new Vector3(playerController.playerCameraTransform.position.x, playerController.playerCameraTransform.position.y - 1.7f, playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) @@ -125,5 +125,30 @@ public void Rotation(float rotationX, float rotationY, PlayerController playerCo cameraRotation * playerController.mouseSensitivity * Time.deltaTime, Space.Self); } } + + public 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/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 3917bb62..678c0558 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -40,6 +40,12 @@ public class PlayerController : MonoBehaviour public float sneakSlow = 0.7f; public float sprintBoost = 1.3f; + public CharacterController CharacterController + { + set { _characterController = value; } + get { return _characterController; } + } + private void Start() { @@ -146,30 +152,5 @@ private void ToggleSneak() playerCameraTransform.position += new Vector3(0f, 0.5f, 0f); } } - - public 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 From 541f1563ced9310e4a4715ada5090cad5672b02f Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:43:21 +0200 Subject: [PATCH 07/46] FIX: automatic added loop dependency --- Assets/Scripts/Character/CharacterController.cs | 2 +- Assets/Scripts/Character/Player/PlayerController.cs | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index a654c549..d8ffec1e 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -35,7 +35,7 @@ public void Movement(PlayerController playerController) Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); - if (playerController.CharacterController.CheckMoveableTerrain( + if (CheckMoveableTerrain( new Vector3(playerController.playerCameraTransform.position.x, playerController.playerCameraTransform.position.y - 1.7f, playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 678c0558..28d85f7d 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -40,12 +40,6 @@ public class PlayerController : MonoBehaviour public float sneakSlow = 0.7f; public float sprintBoost = 1.3f; - public CharacterController CharacterController - { - set { _characterController = value; } - get { return _characterController; } - } - private void Start() { From 6c56d97bbace8e59b6f97caa33f46e2bed1b4a40 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:44:21 +0200 Subject: [PATCH 08/46] REFACTOR: move jump --- Assets/Scripts/Character/CharacterController.cs | 12 ++++++++++++ .../Scripts/Character/Player/PlayerController.cs | 14 +------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index d8ffec1e..df749b74 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -150,5 +150,17 @@ public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, flo return true; } + + public void Jump(PlayerController playerController) + { + if (playerController.groundDetector.currentCollisions.Count != 0) + { + Vector3 vel = new Vector3(playerController.rigidbody.velocity.x, 0, + playerController.rigidbody.velocity.z); + playerController.rigidbody.velocity = vel; + Vector3 jumpForce = new Vector3(0, playerController.playerProperties.jumpPower, 0); + playerController.rigidbody.AddForce(jumpForce, ForceMode.Impulse); + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 28d85f7d..c1d52d14 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -90,8 +90,7 @@ private void Update() // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) isRunning = !isRunning; - if (Input.GetButtonDown("Jump")) - Jump(); + if (Input.GetButtonDown("Jump")) _characterController.Jump(this); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); if (Input.GetButtonDown("Sneak")) @@ -123,17 +122,6 @@ 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; From 84d0cf92f50fa5e35cb46aa7b355bcf6abd3021f Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:45:05 +0200 Subject: [PATCH 09/46] FIX: typo --- Assets/Scripts/Character/CharacterController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index df749b74..8c0faab7 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -40,7 +40,7 @@ public void Movement(PlayerController playerController) playerController.playerCameraTransform.position.y - 1.7f, playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) { - // makes sure, that the total veloctity is not higher while walking cross-ways + // makes sure, that the total velocity is not higher while walking cross-ways if (velocity.magnitude > 1.01) { float ySaver = velocity.y; From a15e16f2a80a86ee6da59ee35265c39ecab1e6bc Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:45:44 +0200 Subject: [PATCH 10/46] REFACTOR: use proper out variable --- Assets/Scripts/Character/CharacterController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 8c0faab7..39ea6378 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -129,9 +129,8 @@ public void Rotation(float rotationX, float rotationY, PlayerController playerCo public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, float distance) { Ray slopeRay = new Ray(position, desiredDirection); - RaycastHit hit; - if (Physics.Raycast(slopeRay, out hit, distance)) + if (Physics.Raycast(slopeRay, out RaycastHit hit, distance)) { if (!(hit.collider.gameObject.tag is "Interactable")) { From 69d4abfbe876ad1be93e2e20257619edb6fe37b1 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:46:47 +0200 Subject: [PATCH 11/46] REFACTOR: simplify ifs --- .../Scripts/Character/CharacterController.cs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 39ea6378..9d5b32a5 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -130,24 +130,12 @@ public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, flo { Ray slopeRay = new Ray(position, desiredDirection); - if (Physics.Raycast(slopeRay, out RaycastHit 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; + 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(PlayerController playerController) From c180f5214eeccc69388e1f33043a4b8123290a1f Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:47:06 +0200 Subject: [PATCH 12/46] REFACTOR: simplify another if --- Assets/Scripts/Character/CharacterController.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 9d5b32a5..0fda1298 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -140,14 +140,12 @@ public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, flo public void Jump(PlayerController playerController) { - if (playerController.groundDetector.currentCollisions.Count != 0) - { - Vector3 vel = new Vector3(playerController.rigidbody.velocity.x, 0, - playerController.rigidbody.velocity.z); - playerController.rigidbody.velocity = vel; - Vector3 jumpForce = new Vector3(0, playerController.playerProperties.jumpPower, 0); - playerController.rigidbody.AddForce(jumpForce, ForceMode.Impulse); - } + if (playerController.groundDetector.currentCollisions.Count == 0) return; + Vector3 vel = new Vector3(playerController.rigidbody.velocity.x, 0, + playerController.rigidbody.velocity.z); + playerController.rigidbody.velocity = vel; + Vector3 jumpForce = new Vector3(0, playerController.playerProperties.jumpPower, 0); + playerController.rigidbody.AddForce(jumpForce, ForceMode.Impulse); } } } \ No newline at end of file From ba6f5c590a58d9d7b6dcff9ec1eb2254c94c03ae Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:47:49 +0200 Subject: [PATCH 13/46] FIX: use correct verb for method name --- Assets/Scripts/Character/CharacterController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 0fda1298..03698fe8 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -35,7 +35,7 @@ public void Movement(PlayerController playerController) Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); - if (CheckMoveableTerrain( + if (CheckWalkableTerrain( new Vector3(playerController.playerCameraTransform.position.x, playerController.playerCameraTransform.position.y - 1.7f, playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) @@ -126,7 +126,7 @@ public void Rotation(float rotationX, float rotationY, PlayerController playerCo } } - public bool CheckMoveableTerrain(Vector3 position, Vector3 desiredDirection, float distance) + public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, float distance) { Ray slopeRay = new Ray(position, desiredDirection); From 94dfb97b0f5aeaca2793684d7cca6de7f7bdf044 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:49:26 +0200 Subject: [PATCH 14/46] REFACTOR: move sensitivity to outer scope --- Assets/Scripts/Character/CharacterController.cs | 5 +++-- Assets/Scripts/Character/Player/PlayerController.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 03698fe8..de27d20b 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -102,14 +102,15 @@ private void PlaySoundForMovement(PlayerController playerController, Vector3 vel } } - public void Rotation(float rotationX, float rotationY, PlayerController playerController) + public void Rotation(float rotationX, float rotationY, PlayerController playerController, + float sensitivity = 1f) { // get mouse Inputs rotationX = Mathf.Clamp(rotationX, -10, 10); rotationY = Mathf.Clamp(rotationY, -10, 10); Vector3 bodyRotation = new Vector3(0, rotationX, 0); - playerController.body.Rotate(bodyRotation * playerController.mouseSensitivity * Time.deltaTime, Space.Self); + playerController.body.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); Vector3 cameraRotation = new Vector3(-rotationY, 0, 0); if (((playerController.playerCameraTransform.eulerAngles + diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index c1d52d14..af39c607 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -97,7 +97,8 @@ private void Update() ToggleSneak(); _characterController.Movement(this); - _characterController.Rotation(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), this); + _characterController.Rotation(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), this, + this.mouseSensitivity); } // check if the player in the Air or not From 3f672f219af22cc3682d309392d88c5d535e2e25 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:52:30 +0200 Subject: [PATCH 15/46] REFACTOR: move camera movement back to player controller --- .../Scripts/Character/CharacterController.cs | 17 +---------- .../Character/Player/PlayerController.cs | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index de27d20b..a884eace 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -102,29 +102,14 @@ private void PlaySoundForMovement(PlayerController playerController, Vector3 vel } } - public void Rotation(float rotationX, float rotationY, PlayerController playerController, + public void Rotation(float rotationX, PlayerController playerController, float sensitivity = 1f) { // get mouse Inputs rotationX = Mathf.Clamp(rotationX, -10, 10); - rotationY = Mathf.Clamp(rotationY, -10, 10); Vector3 bodyRotation = new Vector3(0, rotationX, 0); playerController.body.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); - - Vector3 cameraRotation = new Vector3(-rotationY, 0, 0); - if (((playerController.playerCameraTransform.eulerAngles + - cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x >= -90 && - (playerController.playerCameraTransform.eulerAngles + - cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x <= 90) || - ((playerController.playerCameraTransform.eulerAngles + - cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x >= 270 && - (playerController.playerCameraTransform.eulerAngles + - cameraRotation * playerController.mouseSensitivity * Time.deltaTime).x <= 450)) - { - playerController.playerCameraTransform.Rotate( - cameraRotation * playerController.mouseSensitivity * Time.deltaTime, Space.Self); - } } public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, float distance) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index af39c607..be0be0e4 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -21,12 +21,12 @@ public class PlayerController : MonoBehaviour public Interactor interactor; public Inventory inventory; - public float isAirborne = 0; // 0: on Ground; 1: on the way back down; 2: just jumped + public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped - [Header("Player State Attributes")] public bool isRunning = false; + [Header("Player State Attributes")] public bool isRunning; - public bool isSneaking = false; - public bool isSprinting = false; + public bool isSneaking; + public bool isSprinting; [Header("Mouse settings")] public float mouseSensitivity; @@ -97,8 +97,9 @@ private void Update() ToggleSneak(); _characterController.Movement(this); - _characterController.Rotation(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), this, - this.mouseSensitivity); + float rotationY = Input.GetAxis("Mouse Y"); + _characterController.Rotation(Input.GetAxis("Mouse X"), this, mouseSensitivity); + RotateCamera(rotationY); } // check if the player in the Air or not @@ -135,5 +136,22 @@ private void ToggleSneak() playerCameraTransform.position += new Vector3(0f, 0.5f, 0f); } } + + public void RotateCamera(float rotationY) + { + Vector3 cameraRotation = new Vector3(-rotationY, 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); + } + } } } \ No newline at end of file From 20691b30c29c5aae346d956069e5eeb106e7d06e Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:54:50 +0200 Subject: [PATCH 16/46] REFACTOR: move is running flag --- Assets/Scripts/Character/CharacterController.cs | 5 +++-- Assets/Scripts/Character/Player/PlayerController.cs | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index a884eace..42244710 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -8,6 +8,7 @@ namespace Character public class CharacterController : MonoBehaviour { + [Header("Player State Attributes")] public bool isRunning; public CharacterSounds CharacterSounds { get; set; } @@ -21,7 +22,7 @@ public void Movement(PlayerController playerController) // TODO: fully convert to StatAttribute // get the actual speed with all modificators float speed = playerController.playerProperties.speed.Value; - if (playerController.isRunning) + if (isRunning) speed *= playerController.playerProperties.runMultiplier; if (playerController.isSneaking) speed *= playerController.playerProperties.sneakMultiplier; @@ -83,7 +84,7 @@ public void Movement(PlayerController playerController) private void PlaySoundForMovement(PlayerController playerController, Vector3 velocity) { - if (playerController.isRunning && velocity.magnitude > 0.1f && playerController.isAirborne == 0) + if (isRunning && velocity.magnitude > 0.1f && playerController.isAirborne == 0) { CharacterSounds.Running(playerController.groundDetector.GroundType); } diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index be0be0e4..deda07eb 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -23,7 +23,6 @@ public class PlayerController : MonoBehaviour public Inventory inventory; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped - [Header("Player State Attributes")] public bool isRunning; public bool isSneaking; public bool isSprinting; @@ -89,7 +88,7 @@ private void Update() { // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) - isRunning = !isRunning; + _characterController.isRunning = !_characterController.isRunning; if (Input.GetButtonDown("Jump")) _characterController.Jump(this); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); From dfd4d4ca66c5524d1c80dedf33fed2ee3436142a Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:56:55 +0200 Subject: [PATCH 17/46] REFACTOR: move properties to outer scope --- Assets/Scripts/Character/CharacterController.cs | 7 +++---- Assets/Scripts/Character/Player/PlayerController.cs | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 42244710..f7467477 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -17,15 +17,14 @@ private void Start() CharacterSounds = GetComponent(); } - public void Movement(PlayerController playerController) + public void Movement(PlayerController playerController, float speed, float runMultiplier, float sneakMultiplier) { // TODO: fully convert to StatAttribute // get the actual speed with all modificators - float speed = playerController.playerProperties.speed.Value; if (isRunning) - speed *= playerController.playerProperties.runMultiplier; + speed *= runMultiplier; if (playerController.isSneaking) - speed *= playerController.playerProperties.sneakMultiplier; + speed *= sneakMultiplier; // get the inputs float horizontal = Input.GetAxis("Horizontal"); diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index deda07eb..caf15293 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -95,7 +95,8 @@ private void Update() if (Input.GetButtonDown("Sneak")) ToggleSneak(); - _characterController.Movement(this); + _characterController.Movement(this, this.playerProperties.speed.Value, + this.playerProperties.runMultiplier, this.playerProperties.sneakMultiplier); float rotationY = Input.GetAxis("Mouse Y"); _characterController.Rotation(Input.GetAxis("Mouse X"), this, mouseSensitivity); RotateCamera(rotationY); From a6610d3ff86532ec69928989380916ff640bf2d7 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:57:35 +0200 Subject: [PATCH 18/46] REFACTOR: remove redundant code --- Assets/Scripts/Character/Player/PlayerController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index caf15293..53eea082 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -95,8 +95,8 @@ private void Update() if (Input.GetButtonDown("Sneak")) ToggleSneak(); - _characterController.Movement(this, this.playerProperties.speed.Value, - this.playerProperties.runMultiplier, this.playerProperties.sneakMultiplier); + _characterController.Movement(this, playerProperties.speed.Value, + playerProperties.runMultiplier, playerProperties.sneakMultiplier); float rotationY = Input.GetAxis("Mouse Y"); _characterController.Rotation(Input.GetAxis("Mouse X"), this, mouseSensitivity); RotateCamera(rotationY); From 8926847fed0f5ce851e05af6f32e368d5e925129 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 21:59:04 +0200 Subject: [PATCH 19/46] REFACTOR: move is airborne flag --- Assets/Scripts/Character/CharacterController.cs | 10 ++++++---- Assets/Scripts/Character/Player/PlayerController.cs | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index f7467477..404d9e02 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -8,7 +8,9 @@ namespace Character public class CharacterController : MonoBehaviour { + public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; + public CharacterSounds CharacterSounds { get; set; } @@ -50,7 +52,7 @@ public void Movement(PlayerController playerController, float speed, float runMu } // manages movement depending on being airborne or not - if (playerController.isAirborne == 0) + if (isAirborne == 0) { velocity *= speed; velocity.y = playerController.rigidbody.velocity.y; @@ -83,16 +85,16 @@ public void Movement(PlayerController playerController, float speed, float runMu private void PlaySoundForMovement(PlayerController playerController, Vector3 velocity) { - if (isRunning && velocity.magnitude > 0.1f && playerController.isAirborne == 0) + if (isRunning && velocity.magnitude > 0.1f && isAirborne == 0) { CharacterSounds.Running(playerController.groundDetector.GroundType); } - else if (playerController.isSneaking && velocity.magnitude > 0.1f && playerController.isAirborne == 0) + else if (playerController.isSneaking && velocity.magnitude > 0.1f && isAirborne == 0) { CharacterSounds.Sneaking(playerController.groundDetector.GroundType); } //TODO: replace with isWalking flag - else if (playerController.isAirborne == 0 && velocity.magnitude > 0.1f) + else if (isAirborne == 0 && velocity.magnitude > 0.1f) { CharacterSounds.Walking(playerController.groundDetector.GroundType); } diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 53eea082..8596641d 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -21,7 +21,6 @@ public class PlayerController : MonoBehaviour public Interactor interactor; public Inventory inventory; - public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped public bool isSneaking; @@ -103,8 +102,8 @@ private void Update() } // check if the player in the Air or not - if (groundDetector.currentCollisions.Count == 0) isAirborne = 1; - if (groundDetector.currentCollisions.Count > 0) isAirborne = 0; + if (groundDetector.currentCollisions.Count == 0) _characterController.isAirborne = 1; + if (groundDetector.currentCollisions.Count > 0) _characterController.isAirborne = 0; } private void FindAndPauseSounds() From a8e661155f4d59d054d92fc42c473423be00f2e2 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:01:29 +0200 Subject: [PATCH 20/46] REFACTOR: move rigid body to character controller --- .../Scripts/Character/CharacterController.cs | 24 +++++++++---------- .../Character/Player/PlayerController.cs | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 404d9e02..0a61e313 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -8,12 +8,12 @@ namespace Character public class CharacterController : MonoBehaviour { + private Rigidbody _rigidbody; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; public CharacterSounds CharacterSounds { get; set; } - private void Start() { CharacterSounds = GetComponent(); @@ -55,28 +55,28 @@ public void Movement(PlayerController playerController, float speed, float runMu if (isAirborne == 0) { velocity *= speed; - velocity.y = playerController.rigidbody.velocity.y; - playerController.rigidbody.velocity = velocity; + velocity.y = _rigidbody.velocity.y; + _rigidbody.velocity = velocity; } else { velocity *= speed; velocity.y = 0; - playerController.rigidbody.AddForce(velocity, ForceMode.Impulse); + _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 = playerController.rigidbody.velocity; + velocity = _rigidbody.velocity; velocity.y = 0; velocity = velocity.normalized * Mathf.Clamp(velocity.magnitude, 0, speed); - velocity.y = playerController.rigidbody.velocity.y; + velocity.y = _rigidbody.velocity.y; - playerController.rigidbody.velocity = velocity; + _rigidbody.velocity = velocity; } } else { - playerController.rigidbody.velocity = + _rigidbody.velocity = new Vector3(0f, 0f, 0f); // stops the player at an instant if the terrain is not movable } @@ -129,11 +129,11 @@ public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, flo public void Jump(PlayerController playerController) { if (playerController.groundDetector.currentCollisions.Count == 0) return; - Vector3 vel = new Vector3(playerController.rigidbody.velocity.x, 0, - playerController.rigidbody.velocity.z); - playerController.rigidbody.velocity = vel; + Vector3 vel = new Vector3(_rigidbody.velocity.x, 0, + _rigidbody.velocity.z); + _rigidbody.velocity = vel; Vector3 jumpForce = new Vector3(0, playerController.playerProperties.jumpPower, 0); - playerController.rigidbody.AddForce(jumpForce, ForceMode.Impulse); + _rigidbody.AddForce(jumpForce, ForceMode.Impulse); } } } \ No newline at end of file diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 8596641d..374f6918 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -34,7 +34,6 @@ public class PlayerController : MonoBehaviour public QuestjournalDisplay questDisplay; public TMP_InputField questjournalSearchbar; public Questlog questlog; - public new Rigidbody rigidbody; public float sneakSlow = 0.7f; public float sprintBoost = 1.3f; From 587d1400a279687048d36e176012280e8c956f2e Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:01:46 +0200 Subject: [PATCH 21/46] ADD: rigid body requirement --- Assets/Scripts/Character/CharacterController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 0a61e313..fdf74b09 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -4,6 +4,7 @@ namespace Character { + [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(CharacterSounds))] public class CharacterController : MonoBehaviour From d8caac806ce8f3363eb3fffa571de1f389c44d4a Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:07:41 +0200 Subject: [PATCH 22/46] FIX: typo --- Assets/Scripts/Character/CharacterController.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index fdf74b09..fe7221a0 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -33,15 +33,14 @@ public void Movement(PlayerController playerController, float speed, float runMu float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); - // makes sure that sideway walking is slower than forward walking + // makes sure that sideways walking is slower than forward walking if (vertical < -0.01) speed *= 0.7f; Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); - if (CheckWalkableTerrain( - new Vector3(playerController.playerCameraTransform.position.x, - playerController.playerCameraTransform.position.y - 1.7f, - playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) + if (CheckWalkableTerrain(new Vector3(playerController.playerCameraTransform.position.x, + playerController.playerCameraTransform.position.y - 1.7f, + playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) { // makes sure, that the total velocity is not higher while walking cross-ways if (velocity.magnitude > 1.01) From b110ef4b3caba909f91fe2e15521f4bd127ea2fb Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:09:46 +0200 Subject: [PATCH 23/46] REFACTOR: move is sneaking flag --- Assets/Scripts/Character/CharacterController.cs | 6 ++++-- Assets/Scripts/Character/Player/PlayerController.cs | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index fe7221a0..924389ab 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -12,6 +12,8 @@ public class CharacterController : MonoBehaviour private Rigidbody _rigidbody; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; + public bool isSneaking; + public CharacterSounds CharacterSounds { get; set; } @@ -26,7 +28,7 @@ public void Movement(PlayerController playerController, float speed, float runMu // get the actual speed with all modificators if (isRunning) speed *= runMultiplier; - if (playerController.isSneaking) + if (isSneaking) speed *= sneakMultiplier; // get the inputs @@ -89,7 +91,7 @@ private void PlaySoundForMovement(PlayerController playerController, Vector3 vel { CharacterSounds.Running(playerController.groundDetector.GroundType); } - else if (playerController.isSneaking && velocity.magnitude > 0.1f && isAirborne == 0) + else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == 0) { CharacterSounds.Sneaking(playerController.groundDetector.GroundType); } diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 374f6918..00a84bab 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -23,7 +23,6 @@ public class PlayerController : MonoBehaviour public Inventory inventory; - public bool isSneaking; public bool isSprinting; [Header("Mouse settings")] public float mouseSensitivity; @@ -124,8 +123,8 @@ private void FindAndPauseSounds() private void ToggleSneak() { - isSneaking = !isSneaking; - if (isSneaking) + _characterController.isSneaking = !_characterController.isSneaking; + if (_characterController.isSneaking) { playerCameraTransform.position -= new Vector3(0f, 0.5f, 0f); } From 6ceebbc5a57f13dfc0f49065b4e0c665aee38326 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:10:32 +0200 Subject: [PATCH 24/46] REMOVE: unused flag --- Assets/Scripts/Character/CharacterController.cs | 1 - Assets/Scripts/Character/Player/PlayerController.cs | 2 -- 2 files changed, 3 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 924389ab..b592d70e 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -14,7 +14,6 @@ public class CharacterController : MonoBehaviour [Header("Player State Attributes")] public bool isRunning; public bool isSneaking; - public CharacterSounds CharacterSounds { get; set; } private void Start() diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 00a84bab..2285f0b1 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -23,8 +23,6 @@ public class PlayerController : MonoBehaviour public Inventory inventory; - public bool isSprinting; - [Header("Mouse settings")] public float mouseSensitivity; [Header("Menu References")] public PauseMenu pauseMenu; From 7ecc106f86104ea2edfcb7f6a583054968451d1a Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:11:44 +0200 Subject: [PATCH 25/46] REMOVE: more unused fields --- Assets/Scripts/Character/Player/PlayerController.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 2285f0b1..4a2a7aff 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -31,8 +31,6 @@ public class PlayerController : MonoBehaviour public QuestjournalDisplay questDisplay; public TMP_InputField questjournalSearchbar; public Questlog questlog; - public float sneakSlow = 0.7f; - public float sprintBoost = 1.3f; private void Start() From 9fa7fae48335fdc2089eda7ba09682c28f60dc33 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:14:21 +0200 Subject: [PATCH 26/46] REFACTOR: move ground detector --- .../Scripts/Character/CharacterController.cs | 20 +++++++++++++------ .../Character/Player/PlayerController.cs | 5 ----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index b592d70e..67e37abb 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -10,6 +10,7 @@ public class CharacterController : MonoBehaviour { private Rigidbody _rigidbody; + public GroundDetector groundDetector; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; public bool isSneaking; @@ -21,6 +22,13 @@ private void Start() CharacterSounds = GetComponent(); } + private void Update() + { + // check if the player in the Air or not + if (groundDetector.currentCollisions.Count == 0) isAirborne = 1; + if (groundDetector.currentCollisions.Count > 0) isAirborne = 0; + } + public void Movement(PlayerController playerController, float speed, float runMultiplier, float sneakMultiplier) { // TODO: fully convert to StatAttribute @@ -81,23 +89,23 @@ public void Movement(PlayerController playerController, float speed, float runMu new Vector3(0f, 0f, 0f); // stops the player at an instant if the terrain is not movable } - PlaySoundForMovement(playerController, velocity); + PlaySoundForMovement(velocity); } - private void PlaySoundForMovement(PlayerController playerController, Vector3 velocity) + private void PlaySoundForMovement(Vector3 velocity) { if (isRunning && velocity.magnitude > 0.1f && isAirborne == 0) { - CharacterSounds.Running(playerController.groundDetector.GroundType); + CharacterSounds.Running(groundDetector.GroundType); } else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == 0) { - CharacterSounds.Sneaking(playerController.groundDetector.GroundType); + CharacterSounds.Sneaking(groundDetector.GroundType); } //TODO: replace with isWalking flag else if (isAirborne == 0 && velocity.magnitude > 0.1f) { - CharacterSounds.Walking(playerController.groundDetector.GroundType); + CharacterSounds.Walking(groundDetector.GroundType); } else { @@ -129,7 +137,7 @@ public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, flo public void Jump(PlayerController playerController) { - if (playerController.groundDetector.currentCollisions.Count == 0) return; + if (groundDetector.currentCollisions.Count == 0) return; Vector3 vel = new Vector3(_rigidbody.velocity.x, 0, _rigidbody.velocity.z); _rigidbody.velocity = vel; diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 4a2a7aff..8cb12bc2 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -17,7 +17,6 @@ public class PlayerController : MonoBehaviour [Header("References")] public Transform body; public GameObject dialogueInterface; - public GroundDetector groundDetector; public Interactor interactor; public Inventory inventory; @@ -94,10 +93,6 @@ private void Update() _characterController.Rotation(Input.GetAxis("Mouse X"), this, mouseSensitivity); RotateCamera(rotationY); } - - // check if the player in the Air or not - if (groundDetector.currentCollisions.Count == 0) _characterController.isAirborne = 1; - if (groundDetector.currentCollisions.Count > 0) _characterController.isAirborne = 0; } private void FindAndPauseSounds() From eaffd559d05e3b0ebce0acea384a665ce672f04d Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:15:23 +0200 Subject: [PATCH 27/46] REFACTOR: move jump power to outer scope --- Assets/Scripts/Character/CharacterController.cs | 4 ++-- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 67e37abb..d20208d6 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -135,13 +135,13 @@ public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, flo return !(hit.distance < 0.26f); } - public void Jump(PlayerController playerController) + public void Jump(PlayerController playerController, float jumpPower) { if (groundDetector.currentCollisions.Count == 0) return; Vector3 vel = new Vector3(_rigidbody.velocity.x, 0, _rigidbody.velocity.z); _rigidbody.velocity = vel; - Vector3 jumpForce = new Vector3(0, playerController.playerProperties.jumpPower, 0); + Vector3 jumpForce = new Vector3(0, jumpPower, 0); _rigidbody.AddForce(jumpForce, ForceMode.Impulse); } } diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 8cb12bc2..a75d2649 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -81,7 +81,7 @@ private void Update() // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) _characterController.isRunning = !_characterController.isRunning; - if (Input.GetButtonDown("Jump")) _characterController.Jump(this); + if (Input.GetButtonDown("Jump")) _characterController.Jump(this, this.playerProperties.jumpPower); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); if (Input.GetButtonDown("Sneak")) From fc9bb412d3fb5b6141c21927cc1b13f410b899f5 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:18:40 +0200 Subject: [PATCH 28/46] REMOVE: unused parameter --- Assets/Scripts/Character/CharacterController.cs | 2 +- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index d20208d6..ee5b0fb2 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -135,7 +135,7 @@ public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, flo return !(hit.distance < 0.26f); } - public void Jump(PlayerController playerController, float jumpPower) + public void Jump(float jumpPower) { if (groundDetector.currentCollisions.Count == 0) return; Vector3 vel = new Vector3(_rigidbody.velocity.x, 0, diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index a75d2649..d6ebea12 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -81,7 +81,7 @@ private void Update() // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) _characterController.isRunning = !_characterController.isRunning; - if (Input.GetButtonDown("Jump")) _characterController.Jump(this, this.playerProperties.jumpPower); + if (Input.GetButtonDown("Jump")) _characterController.Jump(this.playerProperties.jumpPower); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); if (Input.GetButtonDown("Sneak")) From 20fc2ea7da6bf6a4f11792144b3258f9297545d8 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:19:00 +0200 Subject: [PATCH 29/46] REMOVE: unused code --- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index d6ebea12..28ac65bd 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -81,7 +81,7 @@ private void Update() // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) _characterController.isRunning = !_characterController.isRunning; - if (Input.GetButtonDown("Jump")) _characterController.Jump(this.playerProperties.jumpPower); + if (Input.GetButtonDown("Jump")) _characterController.Jump(playerProperties.jumpPower); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); if (Input.GetButtonDown("Sneak")) From decf698ad6a12f4d9ce0fc1ef27907c9bd57b9d5 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:20:12 +0200 Subject: [PATCH 30/46] REFACTOR: move body field --- Assets/Scripts/Character/CharacterController.cs | 3 ++- Assets/Scripts/Character/Player/PlayerController.cs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index ee5b0fb2..226e7f51 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -10,6 +10,7 @@ public class CharacterController : MonoBehaviour { private Rigidbody _rigidbody; + [Header("References")] public Transform body; public GroundDetector groundDetector; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; @@ -120,7 +121,7 @@ public void Rotation(float rotationX, PlayerController playerController, rotationX = Mathf.Clamp(rotationX, -10, 10); Vector3 bodyRotation = new Vector3(0, rotationX, 0); - playerController.body.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); + body.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); } public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, float distance) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 28ac65bd..5c568c10 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -14,7 +14,6 @@ public class PlayerController : MonoBehaviour private MusicManager _musicManager; private List _soundManagers; - [Header("References")] public Transform body; public GameObject dialogueInterface; public Interactor interactor; From 911208e1714f65a9d4b7eb7a0b1aa1a82221cc12 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:21:11 +0200 Subject: [PATCH 31/46] REMOVE: unused parameter --- Assets/Scripts/Character/CharacterController.cs | 3 +-- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 226e7f51..dea858ef 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -114,8 +114,7 @@ private void PlaySoundForMovement(Vector3 velocity) } } - public void Rotation(float rotationX, PlayerController playerController, - float sensitivity = 1f) + public void Rotation(float rotationX, float sensitivity = 1f) { // get mouse Inputs rotationX = Mathf.Clamp(rotationX, -10, 10); diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 5c568c10..8f01e4e8 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -89,7 +89,7 @@ private void Update() _characterController.Movement(this, playerProperties.speed.Value, playerProperties.runMultiplier, playerProperties.sneakMultiplier); float rotationY = Input.GetAxis("Mouse Y"); - _characterController.Rotation(Input.GetAxis("Mouse X"), this, mouseSensitivity); + _characterController.Rotation(Input.GetAxis("Mouse X"), mouseSensitivity); RotateCamera(rotationY); } } From 10523085076508f47ab2a54ae4ed900e430c4788 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:26:14 +0200 Subject: [PATCH 32/46] UPDATE: use ground detector for feet position --- Assets/Scripts/Character/CharacterController.cs | 6 ++---- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index dea858ef..919d43bc 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -30,7 +30,7 @@ private void Update() if (groundDetector.currentCollisions.Count > 0) isAirborne = 0; } - public void Movement(PlayerController playerController, float speed, float runMultiplier, float sneakMultiplier) + public void Movement(float speed, float runMultiplier, float sneakMultiplier) { // TODO: fully convert to StatAttribute // get the actual speed with all modificators @@ -48,9 +48,7 @@ public void Movement(PlayerController playerController, float speed, float runMu Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); - if (CheckWalkableTerrain(new Vector3(playerController.playerCameraTransform.position.x, - playerController.playerCameraTransform.position.y - 1.7f, - playerController.playerCameraTransform.position.z), new Vector3(velocity.x, 0, velocity.z), 5f)) + if (CheckWalkableTerrain(groundDetector.transform.position, new Vector3(velocity.x, 0, velocity.z), 5f)) { // makes sure, that the total velocity is not higher while walking cross-ways if (velocity.magnitude > 1.01) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 8f01e4e8..c3bb341e 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -86,7 +86,7 @@ private void Update() if (Input.GetButtonDown("Sneak")) ToggleSneak(); - _characterController.Movement(this, playerProperties.speed.Value, + _characterController.Movement(playerProperties.speed.Value, playerProperties.runMultiplier, playerProperties.sneakMultiplier); float rotationY = Input.GetAxis("Mouse Y"); _characterController.Rotation(Input.GetAxis("Mouse X"), mouseSensitivity); From 122b89b83266652861f465fb3245e2df3b95512a Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:38:12 +0200 Subject: [PATCH 33/46] UPDATE: fields can be private --- Assets/Scripts/Character/CharacterController.cs | 4 ++-- Assets/Scripts/Character/NPC/NPCProperties.cs.meta | 3 --- Assets/Scripts/Character/NPC/NpcProperties.cs.meta | 2 +- Assets/Scripts/Character/Player/PlayerController.cs | 1 + 4 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 Assets/Scripts/Character/NPC/NPCProperties.cs.meta diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 919d43bc..baed6abd 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -10,8 +10,8 @@ public class CharacterController : MonoBehaviour { private Rigidbody _rigidbody; - [Header("References")] public Transform body; - public GroundDetector groundDetector; + [Header("References")] private Transform body; + private GroundDetector groundDetector; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; public bool isSneaking; 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 c3bb341e..247e6768 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -86,6 +86,7 @@ private void Update() if (Input.GetButtonDown("Sneak")) ToggleSneak(); + if (_characterController == null) Debug.Log("cc is null."); _characterController.Movement(playerProperties.speed.Value, playerProperties.runMultiplier, playerProperties.sneakMultiplier); float rotationY = Input.GetAxis("Mouse Y"); From 210e335d250d8682cf096bfc71ec3b15ed478857 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:39:32 +0200 Subject: [PATCH 34/46] FIX: get ground detector --- Assets/Scripts/Character/CharacterController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index baed6abd..7ed971a9 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -20,6 +20,7 @@ public class CharacterController : MonoBehaviour private void Start() { + groundDetector = GetComponentInChildren(); CharacterSounds = GetComponent(); } From 93252c99268bddab2c06439af61a5130953b3bab Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:42:13 +0200 Subject: [PATCH 35/46] REMOVE: debug log --- Assets/Scripts/Character/Player/PlayerController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 247e6768..c3bb341e 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -86,7 +86,6 @@ private void Update() if (Input.GetButtonDown("Sneak")) ToggleSneak(); - if (_characterController == null) Debug.Log("cc is null."); _characterController.Movement(playerProperties.speed.Value, playerProperties.runMultiplier, playerProperties.sneakMultiplier); float rotationY = Input.GetAxis("Mouse Y"); From d75d29f3f47b654a466ab443278ffaba030ca701 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:44:58 +0200 Subject: [PATCH 36/46] FIX: get rigid body --- Assets/Scripts/Character/CharacterController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 7ed971a9..f6c34b60 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -20,6 +20,7 @@ public class CharacterController : MonoBehaviour private void Start() { + _rigidbody = GetComponent(); groundDetector = GetComponentInChildren(); CharacterSounds = GetComponent(); } From 9fe4cb7fbfb3e623307542f039fee7c20fe2633b Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 22:53:46 +0200 Subject: [PATCH 37/46] FIX: body get dynamically --- Assets/Scenes/TestScene.unity | 53 ++++++++++++++++++- .../Scripts/Character/CharacterController.cs | 1 + 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index df680c00..977d06ce 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -4622,6 +4622,27 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1223282233 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2356435387424043639, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + m_PrefabInstance: {fileID: 2356435385448576721} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1223282234 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1223282233} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 57a3805a19784692a8bc8acc2d461818, type: 3} + m_Name: + m_EditorClassIdentifier: + isAirborne: 0 + isRunning: 0 + isSneaking: 0 --- !u!1 &1230076382 GameObject: m_ObjectHideFlags: 0 @@ -8893,6 +8914,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 +8959,11 @@ PrefabInstance: propertyPath: m_SizeDelta.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 6115537310667178606, guid: d5177fd664a14c0418bd57f76722b517, + type: 3} + propertyPath: m_Name + value: Body + objectReference: {fileID: 0} - target: {fileID: 8218561273732356039, guid: d5177fd664a14c0418bd57f76722b517, type: 3} propertyPath: m_AnchorMin.y @@ -8976,7 +9027,7 @@ MonoBehaviour: type: 3} m_PrefabInstance: {fileID: 2356435385448576721} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 1223282233} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 8580b4febb2e6064098d87aff900dff0, type: 3} diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index f6c34b60..fbdf818f 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -20,6 +20,7 @@ public class CharacterController : MonoBehaviour private void Start() { + body = gameObject.transform.Find("Body").transform; _rigidbody = GetComponent(); groundDetector = GetComponentInChildren(); CharacterSounds = GetComponent(); From af87ab3287e84cbb741d44aeaf8d162025bc5252 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 23:11:58 +0200 Subject: [PATCH 38/46] FIX: rotation --- Assets/Scripts/Character/CharacterController.cs | 4 +--- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index fbdf818f..35de287f 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -10,7 +10,6 @@ public class CharacterController : MonoBehaviour { private Rigidbody _rigidbody; - [Header("References")] private Transform body; private GroundDetector groundDetector; public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped [Header("Player State Attributes")] public bool isRunning; @@ -20,7 +19,6 @@ public class CharacterController : MonoBehaviour private void Start() { - body = gameObject.transform.Find("Body").transform; _rigidbody = GetComponent(); groundDetector = GetComponentInChildren(); CharacterSounds = GetComponent(); @@ -121,7 +119,7 @@ public void Rotation(float rotationX, float sensitivity = 1f) rotationX = Mathf.Clamp(rotationX, -10, 10); Vector3 bodyRotation = new Vector3(0, rotationX, 0); - body.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); + transform.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); } public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, float distance) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index c3bb341e..9e853e01 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -33,7 +33,7 @@ public class PlayerController : MonoBehaviour private void Start() { - playerCameraTransform.rotation = Quaternion.identity; + playerCameraTransform = Camera.main.transform; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; From 536d9c476fcb69cdcb1bd56c7052971ae8793f89 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 23:14:01 +0200 Subject: [PATCH 39/46] UPDATE: prefab to changes --- Assets/Prefabs/PlayerBelongings.prefab | 107 +++++++++++++------------ Assets/Scenes/TestScene.unity | 40 ++++----- 2 files changed, 74 insertions(+), 73 deletions(-) diff --git a/Assets/Prefabs/PlayerBelongings.prefab b/Assets/Prefabs/PlayerBelongings.prefab index 0a7003c2..d0cb5b6a 100644 --- a/Assets/Prefabs/PlayerBelongings.prefab +++ b/Assets/Prefabs/PlayerBelongings.prefab @@ -2592,6 +2592,7 @@ GameObject: - component: {fileID: 6861683640419936113} - component: {fileID: 988211132925470496} - component: {fileID: 4961087159837797443} + - component: {fileID: 8916387727230309629} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -2629,25 +2630,16 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 23851ed43df78d3489915c8a195d9036, type: 3} m_Name: m_EditorClassIdentifier: - body: {fileID: 2356435387424043641} + 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} + questlog: {fileID: 0} --- !u!65 &2356435387424043643 BoxCollider: m_ObjectHideFlags: 0 @@ -2794,6 +2786,21 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8580b4febb2e6064098d87aff900dff0, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &8916387727230309629 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2356435387424043639} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 57a3805a19784692a8bc8acc2d461818, type: 3} + m_Name: + m_EditorClassIdentifier: + isAirborne: 0 + isRunning: 0 + isSneaking: 0 --- !u!1 &2356435387426104361 GameObject: m_ObjectHideFlags: 0 @@ -8973,58 +8980,46 @@ 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 &7519064917230829377 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 6706560802818712106, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 4181986942095061725, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4666713041352449235} + m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e64b2bbe094026a4299165af1a474ab1, type: 3} + m_Script: {fileID: 11500000, guid: 2da0c512f12947e489f739169773d7ca, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &4135858231327417772 stripped +--- !u!114 &7383090374177351392 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 7725351650279663664, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 3757817180409998204, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4666713041352449235} + m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f4e3ec7d8aceeb94c84f0b3d14916afd, type: 3} + m_Script: {fileID: 11500000, guid: 365c0483be2f4425be4ad86611a43d47, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7585652203083821388 stripped +--- !u!114 &2356435386368203710 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4257543492969479376, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 8278687299762640418, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4666713041352449235} + m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 422b3d1f0377a0d47acb782b4a7682ad, type: 3} + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: --- !u!114 &8742905801970135246 stripped @@ -9039,39 +9034,51 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &2356435386368203710 stripped +--- !u!114 &7585652203083821388 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 8278687299762640418, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 4257543492969479376, 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: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Script: {fileID: 11500000, guid: 422b3d1f0377a0d47acb782b4a7682ad, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7383090374177351392 stripped +--- !u!114 &4135858231327417772 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 3757817180409998204, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 7725351650279663664, 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: f4e3ec7d8aceeb94c84f0b3d14916afd, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7519064917230829377 stripped +--- !u!114 &1099457508181913526 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4181986942095061725, 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: 2da0c512f12947e489f739169773d7ca, type: 3} + m_Script: {fileID: 11500000, guid: e64b2bbe094026a4299165af1a474ab1, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!224 &7567846488276705717 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 4275630235739450409, guid: 24317b369c54e2143af902331f595adf, + type: 3} + m_PrefabInstance: {fileID: 5931367441388064156} + m_PrefabAsset: {fileID: 0} +--- !u!1 &4666713041352449235 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1338428400787657039, guid: 24317b369c54e2143af902331f595adf, + type: 3} + m_PrefabInstance: {fileID: 5931367441388064156} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index 977d06ce..62b0007d 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -4622,27 +4622,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1223282233 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 2356435387424043639, guid: d5177fd664a14c0418bd57f76722b517, - type: 3} - m_PrefabInstance: {fileID: 2356435385448576721} - m_PrefabAsset: {fileID: 0} ---- !u!114 &1223282234 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1223282233} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 57a3805a19784692a8bc8acc2d461818, type: 3} - m_Name: - m_EditorClassIdentifier: - isAirborne: 0 - isRunning: 0 - isSneaking: 0 --- !u!1 &1230076382 GameObject: m_ObjectHideFlags: 0 @@ -8962,7 +8941,22 @@ PrefabInstance: - target: {fileID: 6115537310667178606, guid: d5177fd664a14c0418bd57f76722b517, type: 3} propertyPath: m_Name - value: Body + 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} @@ -9027,7 +9021,7 @@ MonoBehaviour: type: 3} m_PrefabInstance: {fileID: 2356435385448576721} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1223282233} + m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 8580b4febb2e6064098d87aff900dff0, type: 3} From b6331d0b22992b1a6fcac9ff83ef55d5d08299a2 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 23:17:27 +0200 Subject: [PATCH 40/46] REFACTOR: simplify if --- .../Character/Player/PlayerController.cs | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 9e853e01..e3826cc4 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -75,23 +75,21 @@ 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")) - _characterController.isRunning = !_characterController.isRunning; - if (Input.GetButtonDown("Jump")) _characterController.Jump(playerProperties.jumpPower); - if (Input.GetButtonDown("Interact")) - interactor.KeyDown(); - if (Input.GetButtonDown("Sneak")) - ToggleSneak(); - - _characterController.Movement(playerProperties.speed.Value, - playerProperties.runMultiplier, playerProperties.sneakMultiplier); - float rotationY = Input.GetAxis("Mouse Y"); - _characterController.Rotation(Input.GetAxis("Mouse X"), mouseSensitivity); - RotateCamera(rotationY); - } + if (CloseableMenu.openMenues.Count != 0 || dialogueInterface.activeSelf) return; + // get all Inputs and calls the methods + if (Input.GetButtonDown("Walk/Run")) + _characterController.isRunning = !_characterController.isRunning; + if (Input.GetButtonDown("Jump")) _characterController.Jump(playerProperties.jumpPower); + if (Input.GetButtonDown("Interact")) + interactor.KeyDown(); + if (Input.GetButtonDown("Sneak")) + ToggleSneak(); + + _characterController.Movement(playerProperties.speed.Value, + playerProperties.runMultiplier, playerProperties.sneakMultiplier); + float rotationY = Input.GetAxis("Mouse Y"); + _characterController.Rotation(Input.GetAxis("Mouse X"), mouseSensitivity); + RotateCamera(rotationY); } private void FindAndPauseSounds() From 0e5b3c3798257a00bc0ca6a2603daafd3fa26dd1 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 23:18:20 +0200 Subject: [PATCH 41/46] UPDATE: method can be private --- Assets/Scripts/Character/Player/PlayerController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index e3826cc4..35c93084 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -122,7 +122,7 @@ private void ToggleSneak() } } - public void RotateCamera(float rotationY) + private void RotateCamera(float rotationY) { Vector3 cameraRotation = new Vector3(-rotationY, 0, 0); if (((playerCameraTransform.eulerAngles + From a60d35890699d4a4b9addb6c8d5f98abcaba6252 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 23:19:42 +0200 Subject: [PATCH 42/46] REMOVE: white space --- Assets/Scripts/Character/Player/PlayerController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/Scripts/Character/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 35c93084..255c28ab 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -38,7 +38,6 @@ private void Start() Cursor.visible = false; _characterController = GetComponent(); - _musicManager = GetComponent(); _soundManagers = FindObjectsOfType().OfType().ToList(); From bdcecb5ee8e80a4b774b1127663dc21ea988b696 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Fri, 22 May 2020 23:24:25 +0200 Subject: [PATCH 43/46] REFACTOR: shorten code for diagonal walking --- Assets/Scripts/Character/CharacterController.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 35de287f..7d6e915d 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -54,10 +54,9 @@ public void Movement(float speed, float runMultiplier, float sneakMultiplier) // makes sure, that the total velocity 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; + Vector2 planeVelocity = new Vector2(velocity.x, velocity.z).normalized; + velocity.x = planeVelocity.x; + velocity.z = planeVelocity.y; } // manages movement depending on being airborne or not From 0e552042da24920be7f3c1e0d85748afd95838ac Mon Sep 17 00:00:00 2001 From: iTitus Date: Thu, 28 May 2020 17:06:34 +0200 Subject: [PATCH 44/46] FIX: minor readability issues --- .../Scripts/Character/CharacterController.cs | 73 ++++++++++--------- Assets/Scripts/Character/JumpStatus.cs | 8 ++ Assets/Scripts/Character/JumpStatus.cs.meta | 3 + .../Character/Player/PlayerController.cs | 15 ++-- 4 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 Assets/Scripts/Character/JumpStatus.cs create mode 100644 Assets/Scripts/Character/JumpStatus.cs.meta diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 7d6e915d..177eb339 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -11,7 +11,7 @@ public class CharacterController : MonoBehaviour { private Rigidbody _rigidbody; private GroundDetector groundDetector; - public float isAirborne; // 0: on Ground; 1: on the way back down; 2: just jumped + public JumpStatus isAirborne; [Header("Player State Attributes")] public bool isRunning; public bool isSneaking; @@ -27,12 +27,16 @@ private void Start() private void Update() { // check if the player in the Air or not - if (groundDetector.currentCollisions.Count == 0) isAirborne = 1; - if (groundDetector.currentCollisions.Count > 0) isAirborne = 0; + if (groundDetector.currentCollisions.Count == 0) isAirborne = JumpStatus.InAir; + if (groundDetector.currentCollisions.Count > 0) isAirborne = JumpStatus.OnGround; } - public void Movement(float speed, float runMultiplier, float sneakMultiplier) + public void Movement(CharacterProperties properties) { + float speed = properties.speed.Value; + float runMultiplier = properties.runMultiplier; + float sneakMultiplier = properties.sneakMultiplier; + // TODO: fully convert to StatAttribute // get the actual speed with all modificators if (isRunning) @@ -47,57 +51,58 @@ public void Movement(float speed, float runMultiplier, float sneakMultiplier) // makes sure that sideways walking is slower than forward walking if (vertical < -0.01) speed *= 0.7f; - Vector3 velocity = ((transform.forward * vertical) + (transform.right * horizontal)); + Vector3 inputVelocity = ((transform.forward * vertical) + (transform.right * horizontal)); + Vector3 inputPlaneVelocity = new Vector3(inputVelocity.x, 0, inputVelocity.z).normalized; - if (CheckWalkableTerrain(groundDetector.transform.position, new Vector3(velocity.x, 0, velocity.z), 5f)) + if (CheckWalkableTerrain(groundDetector.transform.position, inputPlaneVelocity, 5f)) { // makes sure, that the total velocity is not higher while walking cross-ways - if (velocity.magnitude > 1.01) + if (inputVelocity.magnitude > 1.01) { - Vector2 planeVelocity = new Vector2(velocity.x, velocity.z).normalized; - velocity.x = planeVelocity.x; - velocity.z = planeVelocity.y; + Vector2 planeVelocityNorm = inputPlaneVelocity.normalized; + inputVelocity.x = planeVelocityNorm.x; + inputVelocity.z = planeVelocityNorm.y; } + inputVelocity *= speed; + // manages movement depending on being airborne or not - if (isAirborne == 0) + if (isAirborne == JumpStatus.OnGround) { - velocity *= speed; - velocity.y = _rigidbody.velocity.y; - _rigidbody.velocity = velocity; + inputVelocity.y = _rigidbody.velocity.y; + _rigidbody.velocity = inputVelocity; } else { - velocity *= speed; - velocity.y = 0; + inputVelocity.y = 0; - _rigidbody.AddForce(velocity, ForceMode.Impulse); + _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 - velocity = _rigidbody.velocity; - velocity.y = 0; - velocity = velocity.normalized * Mathf.Clamp(velocity.magnitude, 0, speed); - velocity.y = _rigidbody.velocity.y; + inputVelocity = _rigidbody.velocity; + inputVelocity.y = 0; + inputVelocity = inputVelocity.normalized * Mathf.Clamp(inputVelocity.magnitude, 0, speed); + inputVelocity.y = _rigidbody.velocity.y; - _rigidbody.velocity = velocity; + _rigidbody.velocity = inputVelocity; } } else { - _rigidbody.velocity = - new Vector3(0f, 0f, 0f); // stops the player at an instant if the terrain is not movable + // stops the player at an instant if the terrain is not movable + _rigidbody.velocity = Vector3.zero; } - PlaySoundForMovement(velocity); + PlaySoundForMovement(inputVelocity); } private void PlaySoundForMovement(Vector3 velocity) { - if (isRunning && velocity.magnitude > 0.1f && isAirborne == 0) + if (isRunning && velocity.magnitude > 0.1f && isAirborne == JumpStatus.OnGround) { CharacterSounds.Running(groundDetector.GroundType); } - else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == 0) + else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == JumpStatus.OnGround) { CharacterSounds.Sneaking(groundDetector.GroundType); } @@ -118,7 +123,7 @@ public void Rotation(float rotationX, float sensitivity = 1f) rotationX = Mathf.Clamp(rotationX, -10, 10); Vector3 bodyRotation = new Vector3(0, rotationX, 0); - transform.Rotate(bodyRotation * sensitivity * Time.deltaTime, Space.Self); + transform.Rotate(bodyRotation * (sensitivity * Time.deltaTime), Space.Self); } public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, float distance) @@ -135,12 +140,14 @@ public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, flo public void Jump(float jumpPower) { - if (groundDetector.currentCollisions.Count == 0) return; - Vector3 vel = new Vector3(_rigidbody.velocity.x, 0, - _rigidbody.velocity.z); + if (groundDetector.currentCollisions.Count == 0) + return; + + Vector3 vel = _rigidbody.velocity; + vel.y = 0; _rigidbody.velocity = vel; - Vector3 jumpForce = new Vector3(0, jumpPower, 0); - _rigidbody.AddForce(jumpForce, ForceMode.Impulse); + + _rigidbody.AddForce(jumpPower * Vector3.up, ForceMode.Impulse); } } } \ No newline at end of file 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/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index 255c28ab..bfe328f4 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -74,20 +74,25 @@ 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) return; + + if (CloseableMenu.openMenues.Count != 0 || dialogueInterface.activeSelf) + return; + // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) _characterController.isRunning = !_characterController.isRunning; - if (Input.GetButtonDown("Jump")) _characterController.Jump(playerProperties.jumpPower); + if (Input.GetButtonDown("Jump")) + _characterController.Jump(playerProperties.jumpPower); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); if (Input.GetButtonDown("Sneak")) ToggleSneak(); - _characterController.Movement(playerProperties.speed.Value, - playerProperties.runMultiplier, playerProperties.sneakMultiplier); + _characterController.Movement(playerProperties); + + float rotationX = Input.GetAxis("Mouse X"); float rotationY = Input.GetAxis("Mouse Y"); - _characterController.Rotation(Input.GetAxis("Mouse X"), mouseSensitivity); + _characterController.Rotation(rotationX, mouseSensitivity); RotateCamera(rotationY); } From b26ad430200b4bb713c9f2e9df4d3ecb4877bead Mon Sep 17 00:00:00 2001 From: iTitus Date: Thu, 28 May 2020 18:59:15 +0200 Subject: [PATCH 45/46] REFACtor: another minor --- Assets/Prefabs/PlayerBelongings.prefab | 102 +++++++----------- .../Scripts/Character/CharacterController.cs | 65 +++++------ .../Scripts/Character/CharacterProperties.cs | 1 + .../Character/Player/PlayerController.cs | 78 +++++++------- Assets/Scripts/Quest/QuestjournalDisplay.cs | 48 ++++++--- 5 files changed, 141 insertions(+), 153 deletions(-) diff --git a/Assets/Prefabs/PlayerBelongings.prefab b/Assets/Prefabs/PlayerBelongings.prefab index d0cb5b6a..28493f2b 100644 --- a/Assets/Prefabs/PlayerBelongings.prefab +++ b/Assets/Prefabs/PlayerBelongings.prefab @@ -2592,7 +2592,6 @@ GameObject: - component: {fileID: 6861683640419936113} - component: {fileID: 988211132925470496} - component: {fileID: 4961087159837797443} - - component: {fileID: 8916387727230309629} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -2630,6 +2629,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 23851ed43df78d3489915c8a195d9036, type: 3} m_Name: m_EditorClassIdentifier: + isAirborne: 0 + isRunning: 0 + isSneaking: 0 dialogueInterface: {fileID: 7994511833790087655} interactor: {fileID: 2356435387424043642} inventory: {fileID: 5251964727823270906} @@ -2638,8 +2640,6 @@ MonoBehaviour: playerCameraTransform: {fileID: 5496631978485877498} playerProperties: {fileID: 2356435387424043644} questDisplay: {fileID: 7585652203083821388} - questjournalSearchbar: {fileID: 7519064917230829377} - questlog: {fileID: 0} --- !u!65 &2356435387424043643 BoxCollider: m_ObjectHideFlags: 0 @@ -2704,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} @@ -2786,21 +2787,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8580b4febb2e6064098d87aff900dff0, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &8916387727230309629 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2356435387424043639} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 57a3805a19784692a8bc8acc2d461818, type: 3} - m_Name: - m_EditorClassIdentifier: - isAirborne: 0 - isRunning: 0 - isSneaking: 0 --- !u!1 &2356435387426104361 GameObject: m_ObjectHideFlags: 0 @@ -8980,39 +8966,33 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 24317b369c54e2143af902331f595adf, type: 3} ---- !u!1 &3047925629568477781 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8654822773299619785, guid: 24317b369c54e2143af902331f595adf, - type: 3} - m_PrefabInstance: {fileID: 5931367441388064156} - m_PrefabAsset: {fileID: 0} ---- !u!114 &7519064917230829377 stripped +--- !u!114 &7585652203083821388 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4181986942095061725, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 4257543492969479376, 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: 2da0c512f12947e489f739169773d7ca, type: 3} + m_Script: {fileID: 11500000, guid: 422b3d1f0377a0d47acb782b4a7682ad, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &7383090374177351392 stripped +--- !u!114 &4135858231327417772 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 3757817180409998204, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 7725351650279663664, 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: f4e3ec7d8aceeb94c84f0b3d14916afd, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &2356435386368203710 stripped +--- !u!114 &8742905801970135246 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 8278687299762640418, guid: 24317b369c54e2143af902331f595adf, + m_CorrespondingSourceObject: {fileID: 3100017794379513170, guid: 24317b369c54e2143af902331f595adf, type: 3} m_PrefabInstance: {fileID: 5931367441388064156} m_PrefabAsset: {fileID: 0} @@ -9022,42 +9002,36 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!114 &8742905801970135246 stripped +--- !u!114 &7383090374177351392 stripped MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 3100017794379513170, 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 &7585652203083821388 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 4257543492969479376, guid: 24317b369c54e2143af902331f595adf, +--- !u!1 &4666713041352449235 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1338428400787657039, 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 &4135858231327417772 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 7725351650279663664, guid: 24317b369c54e2143af902331f595adf, +--- !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} - m_GameObject: {fileID: 4666713041352449235} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f4e3ec7d8aceeb94c84f0b3d14916afd, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!114 &1099457508181913526 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 6706560802818712106, guid: 24317b369c54e2143af902331f595adf, @@ -9070,15 +9044,15 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e64b2bbe094026a4299165af1a474ab1, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!224 &7567846488276705717 stripped -RectTransform: - m_CorrespondingSourceObject: {fileID: 4275630235739450409, guid: 24317b369c54e2143af902331f595adf, - type: 3} - m_PrefabInstance: {fileID: 5931367441388064156} - m_PrefabAsset: {fileID: 0} ---- !u!1 &4666713041352449235 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 1338428400787657039, guid: 24317b369c54e2143af902331f595adf, +--- !u!114 &2356435386368203710 stripped +MonoBehaviour: + 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: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scripts/Character/CharacterController.cs b/Assets/Scripts/Character/CharacterController.cs index 177eb339..64ac5ca4 100644 --- a/Assets/Scripts/Character/CharacterController.cs +++ b/Assets/Scripts/Character/CharacterController.cs @@ -10,58 +10,55 @@ public class CharacterController : MonoBehaviour { private Rigidbody _rigidbody; - private GroundDetector groundDetector; - public JumpStatus isAirborne; - [Header("Player State Attributes")] public bool isRunning; + private GroundDetector _groundDetector; + + [Header("State Attributes")] public JumpStatus isAirborne; + public bool isRunning; public bool isSneaking; - public CharacterSounds CharacterSounds { get; set; } + public CharacterSounds Sounds { get; set; } - private void Start() + protected virtual void Start() { _rigidbody = GetComponent(); - groundDetector = GetComponentInChildren(); - CharacterSounds = GetComponent(); + _groundDetector = GetComponentInChildren(); + Sounds = GetComponent(); } - private void Update() + protected virtual void Update() { // check if the player in the Air or not - if (groundDetector.currentCollisions.Count == 0) isAirborne = JumpStatus.InAir; - if (groundDetector.currentCollisions.Count > 0) isAirborne = JumpStatus.OnGround; + isAirborne = _groundDetector.currentCollisions.Count == 0 ? JumpStatus.InAir : JumpStatus.OnGround; } - public void Movement(CharacterProperties properties) + 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 modificators + // get the actual speed with all modifications if (isRunning) speed *= runMultiplier; if (isSneaking) speed *= sneakMultiplier; - // get the inputs - float horizontal = Input.GetAxis("Horizontal"); - float vertical = Input.GetAxis("Vertical"); - - // makes sure that sideways walking is slower than forward walking - if (vertical < -0.01) speed *= 0.7f; + // 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 inputVelocity = (transform.forward * vertical) + (transform.right * horizontal); Vector3 inputPlaneVelocity = new Vector3(inputVelocity.x, 0, inputVelocity.z).normalized; - if (CheckWalkableTerrain(groundDetector.transform.position, inputPlaneVelocity, 5f)) + 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) { - Vector2 planeVelocityNorm = inputPlaneVelocity.normalized; - inputVelocity.x = planeVelocityNorm.x; - inputVelocity.z = planeVelocityNorm.y; + inputVelocity.x = inputPlaneVelocity.x; + inputVelocity.z = inputPlaneVelocity.y; } inputVelocity *= speed; @@ -100,20 +97,20 @@ private void PlaySoundForMovement(Vector3 velocity) { if (isRunning && velocity.magnitude > 0.1f && isAirborne == JumpStatus.OnGround) { - CharacterSounds.Running(groundDetector.GroundType); + Sounds.Running(_groundDetector.GroundType); } else if (isSneaking && velocity.magnitude > 0.1f && isAirborne == JumpStatus.OnGround) { - CharacterSounds.Sneaking(groundDetector.GroundType); + Sounds.Sneaking(_groundDetector.GroundType); } //TODO: replace with isWalking flag else if (isAirborne == 0 && velocity.magnitude > 0.1f) { - CharacterSounds.Walking(groundDetector.GroundType); + Sounds.Walking(_groundDetector.GroundType); } else { - CharacterSounds.StopMovement(); + Sounds.StopMovement(); } } @@ -130,17 +127,21 @@ public bool CheckWalkableTerrain(Vector3 position, Vector3 desiredDirection, flo { 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; + 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); + if (slopeAngle <= 45f) + return true; + return hit.distance >= 0.26f; } public void Jump(float jumpPower) { - if (groundDetector.currentCollisions.Count == 0) + if (isAirborne != JumpStatus.OnGround) return; Vector3 vel = _rigidbody.velocity; 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/Player/PlayerController.cs b/Assets/Scripts/Character/Player/PlayerController.cs index bfe328f4..0c4d7963 100644 --- a/Assets/Scripts/Character/Player/PlayerController.cs +++ b/Assets/Scripts/Character/Player/PlayerController.cs @@ -2,16 +2,12 @@ using System.Linq; using Interaction; using Sounds.Manager; -using TMPro; using UnityEngine; namespace Character.Player { - [RequireComponent(typeof(CharacterController))] - public class PlayerController : MonoBehaviour + public class PlayerController : CharacterController { - private CharacterController _characterController; - private MusicManager _musicManager; private List _soundManagers; @@ -27,35 +23,23 @@ public class PlayerController : MonoBehaviour public Transform playerCameraTransform; public PlayerProperties playerProperties; public QuestjournalDisplay questDisplay; - public TMP_InputField questjournalSearchbar; - public Questlog questlog; - private void Start() { + base.Start(); + playerCameraTransform = Camera.main.transform; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; - _characterController = 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)) { @@ -74,25 +58,45 @@ private void Update() // menu detection: If no menu is active, enable input if (Input.GetKeyDown(KeyCode.I)) inventory.inventoryDisplay.Toggle(); - + + 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; + } + } + // get all Inputs and calls the methods if (Input.GetButtonDown("Walk/Run")) - _characterController.isRunning = !_characterController.isRunning; + isRunning = !isRunning; if (Input.GetButtonDown("Jump")) - _characterController.Jump(playerProperties.jumpPower); + Jump(playerProperties.jumpPower); if (Input.GetButtonDown("Interact")) interactor.KeyDown(); if (Input.GetButtonDown("Sneak")) ToggleSneak(); - _characterController.Movement(playerProperties); - + 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"); - _characterController.Rotation(rotationX, mouseSensitivity); RotateCamera(rotationY); } @@ -115,31 +119,25 @@ private void FindAndPauseSounds() private void ToggleSneak() { - _characterController.isSneaking = !_characterController.isSneaking; - if (_characterController.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 RotateCamera(float rotationY) { - Vector3 cameraRotation = new Vector3(-rotationY, 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)) + 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) { - playerCameraTransform.Rotate( - cameraRotation * mouseSensitivity * Time.deltaTime, Space.Self); + playerCameraTransform.Rotate(cameraRotation, Space.Self); } } } 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