Commit bb345224 authored by Tanner Grehawick's avatar Tanner Grehawick

Merge branch 'dashrefactor'

parents 150022c1 9a5e7b4e
......@@ -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();
}
......
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
using System.Collections.Generic;
// breakable object
public class Breakable : MonoBehaviour {
public bool breakOnPlayerDash = false;
public UnityEvent onBreak;
public void Break() {
// handle animation and stuff here
onBreak.Invoke();
Destroy(gameObject);
}
}
fileFormatVersion: 2
guid: c7ca022d5dbae2f43a9a23d5ca5ee019
timeCreated: 1487785552
guid: 5e257b3931afd45bf902bc96e4c29208
timeCreated: 1487900567
licenseType: Free
MonoImporter:
serializedVersion: 2
......
......@@ -6,13 +6,13 @@ public class ToggleEnemy : MonoBehaviour {
Camera cam;
public List<Collider2D> enemies;
//List<BaseEnemy> disabledEnemies;
// List<BaseEnemy> disabledEnemies;
// Use this for initialization
void Start () {
cam = Camera.main;
}
// Update is called once per frame
void Update () {
//get frustum of camera
......@@ -22,7 +22,7 @@ public class ToggleEnemy : MonoBehaviour {
//check if enemy is in view of camera and disable if not
if (!GeometryUtility.TestPlanesAABB(camPlanes, enemies[i].bounds))
{
//enemies[i].gameObject.GetComponent<BaseEnemy>().enabled = false;
// enemies[i].gameObject.GetComponent<BaseEnemy>().enabled = false;
enemies.Remove(enemies[i]);
}
}
......
fileFormatVersion: 2
guid: f5015e51666ab3b4e9a750c868d6703b
folderAsset: yes
timeCreated: 1487785551
guid: 11ecc39894ce94f60a0a952e704c611f
timeCreated: 1487896949
licenseType: Free
DefaultImporter:
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -8,7 +8,7 @@ public class Hazard : MonoBehaviour {
{
if (other.CompareTag("Player"))
{
other.GetComponent<Birb>().Die ();
// other.GetComponent<Birb>().Die ();
}
}
}
......@@ -7,10 +7,10 @@ public class WinTrigger : MonoBehaviour {
//checks for incoming collision
public void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.name == "Player") //ensuring it's the player
if(other.gameObject.name == "Player") //ensuring it's the player
{
//tell manager it has won
//GameEditor.Win();
// GameEditor.Win();
//Debug.Log("Victory Achieved");
}
}
......
m_EditorVersion: 5.3.5f1
m_StandardAssetsVersion: 0
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