aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-06-12 23:48:19 -0400
committerCameron Katri <me@cameronkatri.com>2021-06-12 23:48:19 -0400
commit20e5bf4339ffe52b6b09c7b72413c1e2295e282a (patch)
tree06f68b60f5e1b03268dc3e0fa1bdae65b91761f1
parentc500c71d07756d5f4bee8644fa6eb9a95e354b0e (diff)
downloadgmtk-gamejam-20e5bf4339ffe52b6b09c7b72413c1e2295e282a.tar.gz
gmtk-gamejam-20e5bf4339ffe52b6b09c7b72413c1e2295e282a.tar.zst
gmtk-gamejam-20e5bf4339ffe52b6b09c7b72413c1e2295e282a.zip
AI flips (not that great though)
-rw-r--r--Assets/Scripts/Controllers/AIController.cs9
1 files changed, 8 insertions, 1 deletions
diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs
index 9d3d77b..92dc6bc 100644
--- a/Assets/Scripts/Controllers/AIController.cs
+++ b/Assets/Scripts/Controllers/AIController.cs
@@ -27,6 +27,7 @@ namespace Controllers
private Rigidbody2D _rigidbody;
private float animationStep;
+ private bool turn;
public BoxCollider2D BoxCollider => _boxCollider != null ? _boxCollider : _boxCollider = GetComponent<BoxCollider2D>();
private BoxCollider2D _boxCollider;
@@ -75,7 +76,6 @@ namespace Controllers
// transform.position += new Vector3(game.ball.transform.position.x - transform.position.x, 0f, 0f).normalized * (Time.deltaTime * speed);
var direction = Vector2.MoveTowards(transform.position, game.ball.transform.position, speed * Time.deltaTime);
transform.position = new Vector2(direction.x, transform.position.y);
- flipper.localScale = new Vector3((Vector2.Distance(transform.position, direction) > 0 ? -1f : 1f), 1, 1);
}
}
else // Otherwise, move toward the basket, and then once we get within range, take the shot.
@@ -87,6 +87,13 @@ namespace Controllers
}
movement -= transform.position;
+
+ bool currentTurn = movement.x > 0;
+ if (turn && currentTurn)
+ flipper.transform.localScale = new Vector3(1f, 1f, 1f);
+ else
+ flipper.transform.localScale = new Vector3(-1f, 1f, 1f);
+ turn = currentTurn;
game.enemy.Move(transform.position + new Vector3(0f, BoxCollider.size.y * 3/4, 0f));