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 {
{
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .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)
{
......@@ -44,4 +42,14 @@ public class BaseEnemy : MonoBehaviour {
}
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
public float ChargeSpeed;
public bool Charging = false;
public LayerMask lm;
public bool FallOffLedge = false;
void FixedUpdate()
{
......@@ -31,12 +32,18 @@ public class EnemyCharge : BaseEnemy
}
if (Charging)
{ //Will move forward quickly when Charging is True
if (!CheckCollision (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position))
{
{ //Will stop or keep going based on FallOffLedge bool
if (!FallOffLedge) {
if (!CheckCollision (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) {
Charging = false;
return;
}
} else {
if (!CheckCollisionCharge (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) {
Charging = false;
return;
}
}
Move (fwd);
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