From 9c10ca695dbeaa5d0e785a54a6d3e5bbe9653528 Mon Sep 17 00:00:00 2001 From: Gregory Campbell Date: Thu, 5 Dec 2019 22:42:16 -0500 Subject: [PATCH 1/3] Crouching/crawling functionality is working --- Assets/Scripts/PlayerController.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index b692186..d61dfd5 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -10,6 +10,7 @@ using System.Collections; public class PlayerController : MonoBehaviour { CharacterController characterController; + CapsuleCollider capsule; public float speed; public float jumpHeight; @@ -19,11 +20,18 @@ public class PlayerController : MonoBehaviour public GameObject playerModel; private int jump = 0; + private float capsuleHeight; + private float controllerHeight; + private float transformHeight; private Vector3 moveDirection; void Start() { characterController = GetComponent(); + capsule = GetComponent(); + transformHeight = transform.localScale.y; + controllerHeight = characterController.height; + capsuleHeight = capsule.height; } void Update() @@ -55,6 +63,19 @@ public class PlayerController : MonoBehaviour moveDirection = moveDirection.normalized * speed; } + if(Input.GetKey(KeyCode.LeftControl)) + { + moveDirection = (moveDirection.normalized * speed/4); + characterController.height /= 2; + capsule.height /= 2; + transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z); + } else { + moveDirection = moveDirection.normalized * speed; + characterController.height = controllerHeight; + capsule.height = capsuleHeight; + transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z); + } + } if (Input.GetButtonDown("Jump") && jump <= 1) From ba63ebf72bd5a3c504a3b5e2e8605b239138912b Mon Sep 17 00:00:00 2001 From: Gregory Campbell Date: Thu, 5 Dec 2019 23:17:24 -0500 Subject: [PATCH 2/3] Added sliding which reverts back to crouching/crawling after 1 second --- Assets/Scripts/PlayerController.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index d61dfd5..e299121 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -25,6 +25,9 @@ public class PlayerController : MonoBehaviour private float transformHeight; private Vector3 moveDirection; + float startTime = 0.0f; + float oneSec = 1.0f; + void Start() { characterController = GetComponent(); @@ -44,8 +47,7 @@ public class PlayerController : MonoBehaviour if (jump <= 1) { moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run - } else - { + } else { moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run } @@ -65,10 +67,19 @@ public class PlayerController : MonoBehaviour if(Input.GetKey(KeyCode.LeftControl)) { - moveDirection = (moveDirection.normalized * speed/4); + if(Input.GetKeyDown(KeyCode.LeftControl)) + { + startTime = Time.time; + } + + moveDirection = (moveDirection.normalized * speed * 2); characterController.height /= 2; capsule.height /= 2; transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z); + if (startTime + oneSec <= Time.time) + { + moveDirection = (moveDirection.normalized * speed/4); + } } else { moveDirection = moveDirection.normalized * speed; characterController.height = controllerHeight; From 645395a43c81b9fd492a8881515c760200e5a626 Mon Sep 17 00:00:00 2001 From: Gregory Campbell Date: Fri, 6 Dec 2019 22:34:57 -0500 Subject: [PATCH 3/3] Added implementation so that crawling in differentiated from sliding through current player movement --- Assets/Scripts/PlayerController.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index e299121..45416b5 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -67,19 +67,27 @@ public class PlayerController : MonoBehaviour if(Input.GetKey(KeyCode.LeftControl)) { + + characterController.height /= 2; + capsule.height /= 2; + transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z); + if(Input.GetKeyDown(KeyCode.LeftControl)) { startTime = Time.time; } - moveDirection = (moveDirection.normalized * speed * 2); - characterController.height /= 2; - capsule.height /= 2; - transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z); - if (startTime + oneSec <= Time.time) + if(characterController.velocity != new Vector3(0, 0, 0) && startTime + oneSec >= Time.time) { + + moveDirection = (moveDirection.normalized * speed * 2); + + } else { + moveDirection = (moveDirection.normalized * speed/4); + } + } else { moveDirection = moveDirection.normalized * speed; characterController.height = controllerHeight;