Commit 51b09c33 authored by Benjamin Lane's avatar Benjamin Lane

Changed ChargeEnemy to turn around when hitting a wall/ledge

parent 55b66cd3
......@@ -10,14 +10,17 @@ public class EnemyCharge : BaseEnemy
public LayerMask lm;
public bool FallOffLedge = false;
void FixedUpdate()
void Update()
{
Vector2 fwd;
if (!sr.flipX) {
if (transform.localScale.x < 0 )
{
// Raycast to check if player is in front with layermask to prevent it from detecting itself
fwd = transform.TransformDirection (Vector2.right);
} else {
fwd = transform.TransformDirection (Vector2.left);
fwd = Vector2.left;
}
else
{
fwd = Vector2.right;
}
RaycastHit2D hit;
Debug.DrawRay (transform.position, fwd);
......@@ -33,14 +36,25 @@ public class EnemyCharge : BaseEnemy
if (Charging)
{ //Will stop or keep going based on FallOffLedge bool
if (!FallOffLedge) {
if (!CheckCollision (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) {
Charging = false;
if (!FallOffLedge)
{
if (!CheckCollision (fwd, transform.localScale.x < 0 ? rightCollisionPos.position : rightCollisionPos.position))
{
//Charging = false;
Vector2 facing = transform.localScale;
facing.x *= -1;
transform.localScale = facing;
return;
}
} else {
if (!CheckCollisionCharge (fwd, sr.flipX ? leftCollisionPos.position : rightCollisionPos.position)) {
Charging = false;
}
else
{
if (!CheckCollisionCharge (fwd, transform.localScale.x < 0 ? rightCollisionPos.position : rightCollisionPos.position))
{
//Charging = false;
Vector2 facing = transform.localScale;
facing.x *= -1;
transform.localScale = facing;
return;
}
}
......
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