diff options
| author | Carson Katri <carson.katri@gmail.com> | 2021-06-12 16:57:05 -0400 |
|---|---|---|
| committer | Carson Katri <carson.katri@gmail.com> | 2021-06-12 16:57:05 -0400 |
| commit | 2da4072647dbf8577f8a5e2391551fbbfceef231 (patch) | |
| tree | 636de5585864d64832d362117d40c93de97e5bb9 /Assets/Scripts/Controllers/AIController.cs | |
| parent | 939170f625e5928d5ca86a57796aaa23f25a4fa7 (diff) | |
| parent | d6d5014337ab72a6eb8c2f93fae107c71d267649 (diff) | |
| download | gmtk-gamejam-2da4072647dbf8577f8a5e2391551fbbfceef231.tar.gz gmtk-gamejam-2da4072647dbf8577f8a5e2391551fbbfceef231.zip | |
Resolve conflicts
Diffstat (limited to 'Assets/Scripts/Controllers/AIController.cs')
| -rw-r--r-- | Assets/Scripts/Controllers/AIController.cs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs index 19a7d3e..1b7fba8 100644 --- a/Assets/Scripts/Controllers/AIController.cs +++ b/Assets/Scripts/Controllers/AIController.cs @@ -26,7 +26,23 @@ namespace Controllers public BoxCollider2D BoxCollider => _boxCollider != null ? _boxCollider : _boxCollider = GetComponent<BoxCollider2D>(); private BoxCollider2D _boxCollider; - + + private void Start() + { + // Try to grab (steal) the ball every n seconds. + InvokeRepeating(nameof(GrabBall), 0, 0.5f); + } + + private void GrabBall() + { + // Grab from the middle, and the bottom. + if (game.player.HasBall && Random.Range(0, 100) > 95) // 5% chance of them grabbing the ball from the player. + { + game.enemy.GrabBall(transform.position); + game.enemy.GrabBall(transform.position + new Vector3(0f, BoxCollider.size.y / 2, 0f)); + } + } + private void Update() { if (!game.enemy.HasBall) // Move towards the ball to grab it. @@ -35,14 +51,7 @@ namespace Controllers if (Vector2.Distance(player.transform.position, transform.position) < 1f) // Repel from the player if they get too close. { - transform.position -= (player.transform.position - transform.position).normalized * (Time.deltaTime * speed / 2f); - } - - // Grab from the middle, and the bottom. - if (game.player.HasBall && Random.Range(0, 100) > 50) // 50% chance of them grabbing the ball from the player. - { - game.enemy.GrabBall(transform.position); - game.enemy.GrabBall(transform.position + new Vector3(0f, BoxCollider.size.y / 2, 0f)); + transform.position += (player.transform.position - transform.position).normalized * (Time.deltaTime * speed / 2f); } } else // Otherwise, move toward the basket, and then once we get within range, take the shot. |
