From bfa790adb6438d44736acad345a632a44d524b07 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Mon, 23 Apr 2018 21:30:31 +0200 Subject: [PATCH] Player brake time --- Assets/Scripts/PlayerMovement.cs | 24 ++++++++++++++++--- .../textures/{UI/Particles.meta => car.meta} | 2 +- Assets/graphics/textures/tmp.meta | 8 +++++++ 3 files changed, 30 insertions(+), 4 deletions(-) rename Assets/graphics/textures/{UI/Particles.meta => car.meta} (77%) create mode 100644 Assets/graphics/textures/tmp.meta diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index bfd35f0..c0ca462 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -14,11 +14,16 @@ public class PlayerMovement : MonoBehaviour { public float drift = 1f; [SerializeField] public float brake = 2f; + [SerializeField] + public float maxBrakeTime = 30f; // The time of the acceleration/deceleration sounds in seconds public double accelerationTime; public double decelerationTime; + public float brakeTime; + public float lastFrame; + public enum SpeedState { SLOW, FASTER, FAST, SLOWER @@ -34,6 +39,8 @@ public class PlayerMovement : MonoBehaviour { rb = GetComponent(); messagePosted = false; state = SpeedState.SLOW; + brakeTime = 0; + lastFrame = Time.time; } void Update() { @@ -56,7 +63,12 @@ public class PlayerMovement : MonoBehaviour { float speed = speedVec.magnitude; bool braking = Input.GetAxis("Vertical") < 0; + if (brakeTime > maxBrakeTime) { + brakeTime = maxBrakeTime; + braking = false; + } if (braking) { + brakeTime += Time.time - lastFrame; switch (state) { case SpeedState.FASTER: if (Time.time - changeTime > accelerationTime) @@ -135,8 +147,14 @@ public class PlayerMovement : MonoBehaviour { Debug.DrawLine(transform.position, transform.position + speedVec, Color.magenta, 0.01f, false); Debug.DrawLine(transform.position, transform.position + transform.localRotation * Vector3.up, Color.yellow, 0.01f, false); - //Debug.Log(transform.localRotation.eulerAngles); - //Debug.Log(transform.localRotation * Vector3.up); - //Debug.Log(curspeed); + //Debug.Log(transform.localRotation.eulerAngles); + //Debug.Log(transform.localRotation * Vector3.up); + //Debug.Log(curspeed); + lastFrame = Time.time; } + + /// The time in seconds the player was braking + public float GetBrakeTime() { + return brakeTime; + } } diff --git a/Assets/graphics/textures/UI/Particles.meta b/Assets/graphics/textures/car.meta similarity index 77% rename from Assets/graphics/textures/UI/Particles.meta rename to Assets/graphics/textures/car.meta index 90927cf..8504594 100644 --- a/Assets/graphics/textures/UI/Particles.meta +++ b/Assets/graphics/textures/car.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 344607e4adabd53428aa359d92c5daf0 +guid: 9ec323b9157704d00a3409f8ea6e46b2 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/graphics/textures/tmp.meta b/Assets/graphics/textures/tmp.meta new file mode 100644 index 0000000..7ebab68 --- /dev/null +++ b/Assets/graphics/textures/tmp.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: df6e7833427b5497b92308fb6f54e552 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: