aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorCarson Katri <carson.katri@gmail.com>2021-06-12 23:01:15 -0400
committerCarson Katri <carson.katri@gmail.com>2021-06-12 23:01:15 -0400
commit21b894f8c6fabee844e9d4f970e422454658cc40 (patch)
tree29e47ead47b69982a9a96bfbc275315ddfa5a13f /Assets/Scripts
parentf913672cb017632ef115d2fb7a0c4d531650faf0 (diff)
downloadgmtk-gamejam-21b894f8c6fabee844e9d4f970e422454658cc40.tar.gz
gmtk-gamejam-21b894f8c6fabee844e9d4f970e422454658cc40.tar.zst
gmtk-gamejam-21b894f8c6fabee844e9d4f970e422454658cc40.zip
Finally fix shooting
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Controllers/AIController.cs6
-rw-r--r--Assets/Scripts/Controllers/Ball.cs9
-rw-r--r--Assets/Scripts/Controllers/GameController.cs2
-rw-r--r--Assets/Scripts/Controllers/Player/PlayerController.cs2
4 files changed, 8 insertions, 11 deletions
diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs
index bd5fee1..9d3d77b 100644
--- a/Assets/Scripts/Controllers/AIController.cs
+++ b/Assets/Scripts/Controllers/AIController.cs
@@ -53,9 +53,9 @@ namespace Controllers
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.
+ if (hoopDistance < 10.5f && 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, 0f);
+ game.enemy.Shoot(transform, Random.Range(0.5f, 1f));
}
}
@@ -82,7 +82,7 @@ namespace Controllers
{
// 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;
+ var targetDistance = game.enemy.score < game.player.score ? 10f : 4f;
transform.position = new Vector2(Vector2.MoveTowards(transform.position, game.EnemyHoop.transform.position + new Vector3(targetDistance, 0, 0), speed * Time.deltaTime).x, transform.position.y);
}
diff --git a/Assets/Scripts/Controllers/Ball.cs b/Assets/Scripts/Controllers/Ball.cs
index 936b857..ae0656f 100644
--- a/Assets/Scripts/Controllers/Ball.cs
+++ b/Assets/Scripts/Controllers/Ball.cs
@@ -1,5 +1,3 @@
-using System;
-using System.Net.Mime;
using UnityEngine;
namespace Controllers
@@ -20,11 +18,10 @@ namespace Controllers
controller.BallDropped();
}
- public void Shoot(Vector3 target, float time)
+ public void Shoot(Hoop target, float time)
{
- transform.right = target - transform.position;
- Rigidbody.velocity = Vector2.zero;
- Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * (shotForce * ((Mathf.Clamp(time, 0f, 1f) + 1))));
+ transform.localRotation = Quaternion.identity;
+ Rigidbody.velocity = (Vector2)((target.transform.position - transform.position).normalized + transform.up * Mathf.Clamp(time, 0f, 1f)) * shotForce;
}
}
}
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index ce6ea7e..9fbe674 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -144,7 +144,7 @@ namespace Controllers
controller.dribbleSound.Stop();
controller.state = shoot;
controller.ball.Rigidbody.bodyType = RigidbodyType2D.Dynamic;
- controller.ball.Shoot(hoop.transform.position, time);
+ controller.ball.Shoot(hoop, time);
lastShotPosition = playerTransform.position;
return true;
}
diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs b/Assets/Scripts/Controllers/Player/PlayerController.cs
index 1360b6c..d72b077 100644
--- a/Assets/Scripts/Controllers/Player/PlayerController.cs
+++ b/Assets/Scripts/Controllers/Player/PlayerController.cs
@@ -103,7 +103,7 @@ namespace Controllers.Player
ShootStartTime = Time.time;
if (Input.GetKeyUp(controls.shoot))
- game.player.Shoot(segments.Last().transform, ShootStartTime - Time.time);
+ game.player.Shoot(segments.Last().transform, Time.time - ShootStartTime);
}
[Serializable]