From fb16f650accd7f3b810fbd5a5f49c70263153c9c Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Tue, 22 Oct 2024 00:14:15 -0700 Subject: [PATCH] Don't able to move while dashing Dash no longer feels like a ghost mode --- Assets/Teo.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Assets/Teo.cs b/Assets/Teo.cs index 980213e..3a14d87 100644 --- a/Assets/Teo.cs +++ b/Assets/Teo.cs @@ -16,7 +16,7 @@ public class Teo : MonoBehaviour public float lastDashTime = 0; Rigidbody2D controller; GameState gameState; - Vector2 dashVelocity; + bool dashing; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { controller = GetComponent(); @@ -26,10 +26,12 @@ public class Teo : MonoBehaviour // Update is called once per frame void Update() { // Move player - controller.AddRelativeForce (new Vector2 ( - Input.GetAxis("Horizontal"), - Input.GetAxis("Vertical") - ).normalized * moveSpeed); + if (!dashing) { + controller.AddRelativeForce (new Vector2 ( + Input.GetAxis("Horizontal"), + Input.GetAxis("Vertical") + ).normalized * moveSpeed); + } // Attack on click if not on cooldown if (Input.GetMouseButtonDown(0)) { Attack(); @@ -62,6 +64,7 @@ public class Teo : MonoBehaviour IEnumerator Dash() { BoxCollider2D collider = GetComponent(); lastDashTime = Time.fixedTime; + dashing = true; collider.enabled = false; controller.linearDamping = 0; controller.AddRelativeForce (new Vector2( @@ -69,7 +72,8 @@ public class Teo : MonoBehaviour Input.mousePosition.y - Screen.height/2 ).normalized * dashDistance); yield return new WaitForSeconds(0.5F); - controller.linearDamping = 15; + dashing = false; collider.enabled = true; + controller.linearDamping = 15; } }