Don't able to move while dashing
Dash no longer feels like a ghost mode
This commit is contained in:
@@ -16,7 +16,7 @@ public class Teo : MonoBehaviour
|
|||||||
public float lastDashTime = 0;
|
public float lastDashTime = 0;
|
||||||
Rigidbody2D controller;
|
Rigidbody2D controller;
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
Vector2 dashVelocity;
|
bool dashing;
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
void Start() {
|
void Start() {
|
||||||
controller = GetComponent<Rigidbody2D>();
|
controller = GetComponent<Rigidbody2D>();
|
||||||
@@ -26,10 +26,12 @@ public class Teo : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update() {
|
void Update() {
|
||||||
// Move player
|
// Move player
|
||||||
|
if (!dashing) {
|
||||||
controller.AddRelativeForce (new Vector2 (
|
controller.AddRelativeForce (new Vector2 (
|
||||||
Input.GetAxis("Horizontal"),
|
Input.GetAxis("Horizontal"),
|
||||||
Input.GetAxis("Vertical")
|
Input.GetAxis("Vertical")
|
||||||
).normalized * moveSpeed);
|
).normalized * moveSpeed);
|
||||||
|
}
|
||||||
// Attack on click if not on cooldown
|
// Attack on click if not on cooldown
|
||||||
if (Input.GetMouseButtonDown(0)) {
|
if (Input.GetMouseButtonDown(0)) {
|
||||||
Attack();
|
Attack();
|
||||||
@@ -62,6 +64,7 @@ public class Teo : MonoBehaviour
|
|||||||
IEnumerator Dash() {
|
IEnumerator Dash() {
|
||||||
BoxCollider2D collider = GetComponent<BoxCollider2D>();
|
BoxCollider2D collider = GetComponent<BoxCollider2D>();
|
||||||
lastDashTime = Time.fixedTime;
|
lastDashTime = Time.fixedTime;
|
||||||
|
dashing = true;
|
||||||
collider.enabled = false;
|
collider.enabled = false;
|
||||||
controller.linearDamping = 0;
|
controller.linearDamping = 0;
|
||||||
controller.AddRelativeForce (new Vector2(
|
controller.AddRelativeForce (new Vector2(
|
||||||
@@ -69,7 +72,8 @@ public class Teo : MonoBehaviour
|
|||||||
Input.mousePosition.y - Screen.height/2
|
Input.mousePosition.y - Screen.height/2
|
||||||
).normalized * dashDistance);
|
).normalized * dashDistance);
|
||||||
yield return new WaitForSeconds(0.5F);
|
yield return new WaitForSeconds(0.5F);
|
||||||
controller.linearDamping = 15;
|
dashing = false;
|
||||||
collider.enabled = true;
|
collider.enabled = true;
|
||||||
|
controller.linearDamping = 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user