]> git.cameronkatri.com Git - gmtk-gamejam.git/commitdiff
Merge branch 'master' of git.cameronkatri.com:gmtk-gamejam
authorCarson Katri <carson.katri@gmail.com>
Sun, 13 Jun 2021 04:06:21 +0000 (00:06 -0400)
committerCarson Katri <carson.katri@gmail.com>
Sun, 13 Jun 2021 04:06:21 +0000 (00:06 -0400)
Assets/Scripts/Controllers/AIController.cs

index ad258f3a4111ecf7cb579ac536ed31cadacdedb3..cdfc9a8220e514686f28af98f4e05ca26d6bf482 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;
@@ -77,7 +78,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.
@@ -89,6 +89,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));