aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts/Controllers/AIController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Controllers/AIController.cs')
-rw-r--r--Assets/Scripts/Controllers/AIController.cs23
1 files changed, 17 insertions, 6 deletions
diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs
index 244b502..4879c4c 100644
--- a/Assets/Scripts/Controllers/AIController.cs
+++ b/Assets/Scripts/Controllers/AIController.cs
@@ -35,6 +35,7 @@ namespace Controllers
{
// Try to grab (steal) the ball every n seconds.
InvokeRepeating(nameof(GrabBall), 0, 0.5f);
+ InvokeRepeating(nameof(ShootBall), 0, 2f);
}
private void GrabBall()
@@ -47,6 +48,17 @@ namespace Controllers
}
}
+ private void ShootBall()
+ {
+ if (!game.enemy.HasBall) return;
+ var hoopDistance = Mathf.Abs(transform.position.x - game.EnemyHoop.transform.position.x);
+ var playerHoopDistance = Mathf.Abs(player.root.transform.position.x - game.EnemyHoop.transform.position.x);
+ if (hoopDistance < 6f && hoopDistance > 2.5f && (Random.Range(0, 100) > 30 || playerHoopDistance > hoopDistance)) // Take the shot when in range. 70% chance he decides to if the player is standing between him and the basket.
+ {
+ game.enemy.Shoot(transform);
+ }
+ }
+
private void Update()
{
var movement = transform.position;
@@ -68,16 +80,15 @@ namespace Controllers
}
else // Otherwise, move toward the basket, and then once we get within range, take the shot.
{
- transform.position = new Vector2(Vector2.MoveTowards(transform.position, game.EnemyHoop.transform.position, speed * Time.deltaTime).x, transform.position.y);
- if (Mathf.Abs(transform.position.x - game.EnemyHoop.transform.position.x) < 5f) // Take the shot.
- {
- game.enemy.Shoot(transform);
- }
+ // How far the enemy tries to get from the hoop before shooting.
+ // Currently, it will try to shoot a 3pt. shot if down, but a 2pt. shot if up or tied.
+ var targetDistance = game.enemy.score < game.player.score ? 5f : 3f;
+ transform.position = new Vector2(Vector2.MoveTowards(transform.position, game.EnemyHoop.transform.position + new Vector3(targetDistance, 0, 0), speed * Time.deltaTime).x, transform.position.y);
}
movement -= transform.position;
- game.enemy.Move(transform.position + new Vector3(0f, BoxCollider.size.y / 2, 0f));
+ game.enemy.Move(transform.position + new Vector3(0f, BoxCollider.size.y * 3/4, 0f));
leftLeg.top.transform.localRotation = Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(animationStep * legSpeed));
leftLeg.bottom.transform.localRotation = Quaternion.Euler(0, 0, maxLegAngle + maxLegAngle * Mathf.Sin(animationStep * legSpeed));