aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorCarson Katri <carson.katri@gmail.com>2021-06-13 02:06:00 -0400
committerCarson Katri <carson.katri@gmail.com>2021-06-13 02:06:00 -0400
commitac864b588ee59fbbc62c8bcf7c82cc51767276ec (patch)
tree092e3bfc54b178da080de3e77d3d957eeeeeb512 /Assets/Scripts
parent994202b1439fced5859d0cc7e916721f8892cb25 (diff)
downloadgmtk-gamejam-ac864b588ee59fbbc62c8bcf7c82cc51767276ec.tar.gz
gmtk-gamejam-ac864b588ee59fbbc62c8bcf7c82cc51767276ec.tar.zst
gmtk-gamejam-ac864b588ee59fbbc62c8bcf7c82cc51767276ec.zip
Add dribbling animation
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Controllers/GameController.cs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs
index 6faf2dd..926238a 100644
--- a/Assets/Scripts/Controllers/GameController.cs
+++ b/Assets/Scripts/Controllers/GameController.cs
@@ -27,6 +27,10 @@ namespace Controllers
/// The single ball for the game.
/// </summary>
[SerializeField] public Ball ball;
+
+ [SerializeField] private float dribbleHeight;
+ [SerializeField] private float dribbleSpeed;
+ private Vector3 ballTarget;
[SerializeField] public SpriteRenderer[] trenchCoatSegments;
@@ -86,7 +90,7 @@ namespace Controllers
freezeMotion = false;
startTime = Time.time;
- ball.Rigidbody.AddForce(new Vector2(0f, 10f));
+ ball.Rigidbody.velocity = new Vector2(0, 5f);
}
private void Update()
@@ -94,6 +98,14 @@ namespace Controllers
UpdateUI();
}
+ private void FixedUpdate()
+ {
+ if (player.HasBall || enemy.HasBall)
+ {
+ ball.transform.position = ballTarget - new Vector3(0, Mathf.Sin(Time.time * dribbleHeight * dribbleSpeed) + 1f, 0);
+ }
+ }
+
private bool gameover;
private void UpdateUI()
{
@@ -160,7 +172,7 @@ namespace Controllers
public void Move(Vector2 handPosition)
{
if (controller.state == (isEnemy ? State.EnemyDribble : State.PlayerDribble)) // Make sure they're dribbling.
- controller.ball.transform.position = handPosition; // TODO: Make this perform a dribbling motion, otherwise it looks like they're travelling.
+ controller.ballTarget = handPosition;
}
/// <summary>