From ac864b588ee59fbbc62c8bcf7c82cc51767276ec Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Sun, 13 Jun 2021 02:06:00 -0400 Subject: Add dribbling animation --- Assets/Scripts/Controllers/GameController.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Assets/Scripts') 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. /// [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; } /// -- cgit v1.2.3-56-ge451