Commit 9a5e7b4e authored by Tanner Grehawick's avatar Tanner Grehawick

finish dash + breakable refactor

parent 2f3253fb
......@@ -7,13 +7,15 @@ using UnityEngine;
public class Dash : AbstractBehavior {
private float lastDash;
public float coolDown = 1f;
public float dashforce = 5;
public float holdTime = 0.4f;
public float minVelocity = 0.5f;
public float minVelocity = 0.5f;
private bool _isDashing = false;
private Transform dashMeter;
private float lastDash;
private CircleCollider2D collider;
// Call to check if currently dashing
public bool isDashing
......@@ -27,6 +29,7 @@ public class Dash : AbstractBehavior {
void Start() {
dashMeter = GameObject.FindGameObjectWithTag("DashMeter").transform;
collider = GetComponent<CircleCollider2D>();
}
void Update() {
......@@ -60,6 +63,9 @@ public class Dash : AbstractBehavior {
float initialGrav = body.gravityScale;
body.gravityScale = 0;
// results for circle cast
RaycastHit2D[] results = new RaycastHit2D[8];
// Decelerate
for (float i = 0; i < holdTime; i += Time.deltaTime) {
// Calculate velocity
......@@ -72,6 +78,19 @@ public class Dash : AbstractBehavior {
// Apply velocity
body.velocity = targetVel;
float checkDistance = body.velocity.magnitude * Time.deltaTime;
// check for breakable in front
int resultCount = Physics2D.CircleCastNonAlloc(body.position, collider.radius, body.velocity, results, checkDistance);
for (int r = 0; r < resultCount; r ++) {
RaycastHit2D result = results[r];
Breakable breakable = result.collider.GetComponent<Breakable>();
if (breakable != null && breakable.breakOnPlayerDash) {
breakable.Break();
}
}
// Wait
yield return new WaitForEndOfFrame();
}
......
fileFormatVersion: 2
guid: 3a07c26186d61461d8bb2547dfa73f32
timeCreated: 1487898154
guid: 5e257b3931afd45bf902bc96e4c29208
timeCreated: 1487900567
licenseType: Free
MonoImporter:
serializedVersion: 2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment