From da62c3af08ec5dab747aa25c4645081ae8e72ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Sun, 2 Sep 2018 18:25:11 +0200 Subject: [PATCH] Implemented charge cancelling Stop charging with mouse 2 and still stick to things --- Assets/Scripts/LurchMovement.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/LurchMovement.cs b/Assets/Scripts/LurchMovement.cs index d38fda2..e1192d0 100644 --- a/Assets/Scripts/LurchMovement.cs +++ b/Assets/Scripts/LurchMovement.cs @@ -50,7 +50,7 @@ public class LurchMovement : MonoBehaviour { private bool stickToGround = false; [SerializeField] private float stickyOffset = 1; - + private bool blockCharge = false; [Header("Gliding")] public bool canGlide; @@ -125,7 +125,11 @@ public class LurchMovement : MonoBehaviour { void JumpControl() { - if (Input.GetButton("Fire1") && currentJumpForce < maxJumpForce) + if (Input.GetButtonDown("Fire1")) + { + blockCharge = false; + } + if (Input.GetButton("Fire1") && currentJumpForce < maxJumpForce && cooldown <= 0 && !blockCharge ) { currentJumpForce += forceIncreaseSpeed; lerpedColor = Color.Lerp(normalColor, fullyChargedColor, t); @@ -141,7 +145,7 @@ public class LurchMovement : MonoBehaviour { { lerpedColor = normalColor; t = 0.0f; - currentSize = normalSize; + currentSize = Vector3.Lerp(currentSize, normalSize, Time.deltaTime * 5f); } @@ -151,7 +155,7 @@ public class LurchMovement : MonoBehaviour { currentJumpForce = 0.0f; } - if (Input.GetButtonUp("Fire1")) { + if (Input.GetButtonUp("Fire1") && cooldown <= 0 && !blockCharge) { cooldown = 0.5f; lurchBody.isKinematic = false; stickToGround = false; @@ -159,6 +163,12 @@ public class LurchMovement : MonoBehaviour { lurchBody.AddForce(theLurch.forward * currentJumpForce, ForceMode.Impulse); lurchBody.AddForce(theLurch.up * currentJumpForce * upForceModifier, ForceMode.Impulse); } + else if (Input.GetButton("Fire2")) { + currentJumpForce = 0.0f; + cooldown = 0.5f; + currentSize = Vector3.Lerp(currentSize, normalSize, Time.deltaTime * 5f); + blockCharge = true; + } else if (LurchOnGround() && Time.time > cooldown) { //stickToGround = true;