]> git.cameronkatri.com Git - gmtk-gamejam.git/commitdiff
AI flips (not that great though)
authorCameron Katri <me@cameronkatri.com>
Sun, 13 Jun 2021 03:48:19 +0000 (23:48 -0400)
committerCameron Katri <me@cameronkatri.com>
Sun, 13 Jun 2021 03:48:19 +0000 (23:48 -0400)
Assets/Scripts/Controllers/AIController.cs

index 9d3d77b1dc4632693a3b546f0da857e6c0234fb8..92dc6bc35049bb5e354f3267fa8ecea2bb10911a 100644 (file)
@@ -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));