diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 942145e..50c4ce4 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -1,33 +1,47 @@ using UnityEngine; using System.Collections; -public class PlayerMovement : MonoBehaviour { - +public class PlayerMovement : MonoBehaviour +{ public float speed = 0f; public float turn = 0f; + public Rigidbody characterRigidBody; + + // Boost public float boostFactor = 1f; public float seconds; - float initialTime; + float boostDeadline; bool SpeedBoostTimerStart; - //private Rigidbody rb; - - + // Slow motion + public float timeFactor = 0.2f; + public float duration = 5.0f; + float slowmoDeadline; + private bool SlowmoTimerStart = false; - // Update is called once per frame - void Update () { + // Update is called once per frame + void FixedUpdate() + { + SpeedBoostTimer(seconds); + SlowmoTimer(duration); + ManageMovement(); + } + + private void ManageMovement() + { + Vector3 fowardVector = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); - if (Input.GetAxis("Vertical")>0) + if (Input.GetAxis("Vertical") > 0) { - characterRigidBody.velocity = ( fowardVector * speed * boostFactor * Time.deltaTime); + characterRigidBody.velocity = (fowardVector * speed * boostFactor * Time.deltaTime); } - else if (Input.GetAxis("Vertical")<0) + else if (Input.GetAxis("Vertical") < 0) { characterRigidBody.velocity = (-fowardVector * speed * boostFactor * Time.deltaTime); } - if (Input.GetAxis("Horizontal")<0) + if (Input.GetAxis("Horizontal") < 0) { - characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime); + characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime ); } else if (Input.GetAxis("Horizontal") > 0) { @@ -35,31 +49,46 @@ public class PlayerMovement : MonoBehaviour { } } - void FixedUpdate() - { - SpeedBoostTimer(seconds); - } - - void OnTriggerEnter (Collider other) + void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "SpeedBoost") { - other.gameObject.SetActive (false); + other.gameObject.SetActive(false); SpeedBoostTimerStart = true; } + + if (other.gameObject.CompareTag("Slowmo")) + { + SlowmoTimerStart = true; + other.gameObject.SetActive(false); + } } private void SpeedBoostTimer(float seconds) { if (SpeedBoostTimerStart) { - boostFactor = 8f; - initialTime = Time.realtimeSinceStartup + seconds; + boostFactor = 8.0f; + boostDeadline = Time.realtimeSinceStartup + seconds; SpeedBoostTimerStart = false; } - if (Time.realtimeSinceStartup >= initialTime) + if (Time.realtimeSinceStartup >= boostDeadline) { - boostFactor = 1f; + boostFactor = 1.0f; + } + } + + private void SlowmoTimer(float seconds) + { + if (SlowmoTimerStart) + { + TimeManager.SlowFactor = 0.2f; + slowmoDeadline = Time.realtimeSinceStartup + seconds; + SlowmoTimerStart = false; + } + if (Time.realtimeSinceStartup >= slowmoDeadline) + { + TimeManager.SlowFactor = 1.0f; } } } diff --git a/Assets/Scripts/TimeManager.cs b/Assets/Scripts/TimeManager.cs new file mode 100644 index 0000000..3a38676 --- /dev/null +++ b/Assets/Scripts/TimeManager.cs @@ -0,0 +1,18 @@ +using System; + +public static class TimeManager +{ + private static float slowFactor; + public static float SlowFactor + { + get + { + return slowFactor; + } + set + { + slowFactor = value; + } + } +} + diff --git a/Assets/Scripts/ViewControl.cs b/Assets/Scripts/ViewControl.cs index c53f884..71886d8 100644 --- a/Assets/Scripts/ViewControl.cs +++ b/Assets/Scripts/ViewControl.cs @@ -7,7 +7,7 @@ public class ViewControl : MonoBehaviour // Speed at which the camera will catch up to the mouse pointer location public float mouseSensitivity = 100.0f; public float clampAngle = 80.0f; - + private float rotY = 0.0f; // rotation around the up/y axis private float rotX = 0.0f;