]> git.cameronkatri.com Git - gmtk-gamejam.git/commitdiff
Refine AI decision-making
authorCarson Katri <carson.katri@gmail.com>
Sun, 13 Jun 2021 00:19:00 +0000 (20:19 -0400)
committerCarson Katri <carson.katri@gmail.com>
Sun, 13 Jun 2021 00:19:00 +0000 (20:19 -0400)
Assets/Scenes/Main.unity
Assets/Scripts/Controllers/AIController.cs
Assets/Scripts/Controllers/Ball.cs
Assets/Sprites/Basketball.controller

index a2bab54ad4c1f5a9639353a401e121a0cec93963..1ead15be8f74957d9c01565b7b2ec8fada7d4073 100644 (file)
@@ -712,11 +712,11 @@ PrefabInstance:
       objectReference: {fileID: 0}
     - target: {fileID: 5143626018439341592, guid: 2485406c33a7d4f5481ce936cc9b162e, type: 3}
       propertyPath: m_LocalPosition.x
-      value: 0.23
+      value: -0.00999999
       objectReference: {fileID: 0}
     - target: {fileID: 5143626018439341592, guid: 2485406c33a7d4f5481ce936cc9b162e, type: 3}
       propertyPath: m_LocalPosition.y
-      value: 5.17
+      value: 0.73
       objectReference: {fileID: 0}
     - target: {fileID: 5143626018439341592, guid: 2485406c33a7d4f5481ce936cc9b162e, type: 3}
       propertyPath: m_LocalPosition.z
index 244b5021d273f28cdea30587acf54dbefc699753..4879c4c25f9e77361def7daae13d81fb7b4da0d7 100644 (file)
@@ -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));
index d9c85c2d885a980d1d477e1ad246f10dda2c1826..07e1b37f50fc99c3d5cd70de5cf023ab53826948 100644 (file)
@@ -22,7 +22,7 @@ namespace Controllers
 
     public void Shoot(Vector3 target)
     {
-      transform.right = (target - transform.position);
+      transform.right = target - transform.position;
       Rigidbody.velocity = Vector2.zero;
       Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * shotForce);
     }
index 0b17d66c44b69aa4ec74430f9438272460782642..51c508c39b2346d5ce4811f9458631bfad3ecb2d 100644 (file)
@@ -11,13 +11,13 @@ AnimatorStateMachine:
   m_ChildStates:
   - serializedVersion: 1
     m_State: {fileID: 7946675803598422961}
-    m_Position: {x: 200, y: 0, z: 0}
+    m_Position: {x: 260, y: 60, z: 0}
   m_ChildStateMachines: []
   m_AnyStateTransitions: []
   m_EntryTransitions: []
   m_StateMachineTransitions: {}
   m_StateMachineBehaviours: []
-  m_AnyStatePosition: {x: 50, y: 20, z: 0}
+  m_AnyStatePosition: {x: 60, y: 10, z: 0}
   m_EntryPosition: {x: 50, y: 120, z: 0}
   m_ExitPosition: {x: 800, y: 120, z: 0}
   m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}