Commit 0d548c07 authored by Andrew R Van Buren's avatar Andrew R Van Buren

Merge branch 'hazard' into 'master'

Hazard

See merge request !43
parents 29927019 b5859a0a
...@@ -35,8 +35,6 @@ public class BaseEnemy : MonoBehaviour { ...@@ -35,8 +35,6 @@ public class BaseEnemy : MonoBehaviour {
{ {
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f); RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f);
RaycastHit2D hitDown = Physics2D.Raycast(collisionPos, -transform.up, .1f); RaycastHit2D hitDown = Physics2D.Raycast(collisionPos, -transform.up, .1f);
Debug.DrawRay(collisionPos, dir, Color.red);
Debug.DrawRay(collisionPos, -transform.up, Color.green);
if (hitDown.collider != null && hitSide.collider == null) if (hitDown.collider != null && hitSide.collider == null)
{ {
...@@ -44,4 +42,14 @@ public class BaseEnemy : MonoBehaviour { ...@@ -44,4 +42,14 @@ public class BaseEnemy : MonoBehaviour {
} }
return false; return false;
} }
protected bool CheckCollisionCharge(Vector2 dir, Vector3 collisionPos)
{
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f);
if (hitSide.collider == null)
{
return true;
}
return false;
}
} }
...@@ -8,6 +8,7 @@ public class EnemyCharge : BaseEnemy ...@@ -8,6 +8,7 @@ public class EnemyCharge : BaseEnemy
public float ChargeSpeed; public float ChargeSpeed;
public bool Charging = false; public bool Charging = false;
public LayerMask lm; public LayerMask lm;
public bool FallOffLedge = false;
void FixedUpdate() void FixedUpdate()
{ {
...@@ -31,11 +32,17 @@ public class EnemyCharge : BaseEnemy ...@@ -31,11 +32,17 @@ public class EnemyCharge : BaseEnemy
} }
if (Charging) if (Charging)
{ //Will move forward quickly when Charging is True { //Will stop or keep going based on FallOffLedge bool
if (!CheckCollision (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) if (!FallOffLedge) {
{ if (!CheckCollision (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) {
Charging = false; Charging = false;
return; return;
}
} else {
if (!CheckCollisionCharge (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) {
Charging = false;
return;
}
} }
Move (fwd); Move (fwd);
speed = ChargeSpeed; speed = ChargeSpeed;
......
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