From c65c617e2031aa6ece4fa6831891fcf1e13662d4 Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Sun, 13 Jun 2021 08:51:14 -0400 Subject: Fix animations, and improve helptext --- Assets/Scripts/Controllers/AIController.cs | 31 ++++++++++++++++++++-------- Assets/Scripts/Controllers/GameController.cs | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs index a7de4fb..7246023 100644 --- a/Assets/Scripts/Controllers/AIController.cs +++ b/Assets/Scripts/Controllers/AIController.cs @@ -7,6 +7,7 @@ namespace Controllers { [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(BoxCollider2D))] + [RequireComponent(typeof(Animator))] public class AIController : MonoBehaviour { [SerializeField] private float speed; @@ -18,6 +19,10 @@ namespace Controllers [SerializeField] private Leg rightLeg; [SerializeField] private float maxLegAngle; [SerializeField] private float legSpeed; + + [Header("Arsm")] + [SerializeField] private GameObject leftArm; + [SerializeField] private GameObject rightArm; [Header("References")] [SerializeField] private GameController game; @@ -26,11 +31,13 @@ namespace Controllers public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent(); private Rigidbody2D _rigidbody; - private float animationStep; private bool turn; public BoxCollider2D BoxCollider => _boxCollider != null ? _boxCollider : _boxCollider = GetComponent(); private BoxCollider2D _boxCollider; + + public Animator Animator => _animator != null ? _animator : _animator = GetComponent(); + private Animator _animator; private void Start() { @@ -60,6 +67,15 @@ namespace Controllers } } + private Vector3 lastPosition; + private static readonly int Running = Animator.StringToHash("Running"); + private void FixedUpdate() + { + Animator.SetBool(Running, (lastPosition - transform.position).x > 0.025); + + lastPosition = transform.position; + } + private void Update() { if (game.freezeMotion) return; @@ -89,7 +105,7 @@ namespace Controllers } movement -= transform.position; - + bool currentTurn = movement.x > 0; if (turn && currentTurn) flipper.transform.localScale = new Vector3(1f, 1f, 1f); @@ -98,13 +114,10 @@ namespace Controllers game.enemy.Move(transform.position + new Vector3(0f, BoxCollider.size.y * 3/4, 0f) + (transform.right * (0.5f * (turn && currentTurn ? -1 : 1)))); turn = currentTurn; - - 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)); - rightLeg.top.transform.localRotation = Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(animationStep * -legSpeed)); - rightLeg.bottom.transform.localRotation = Quaternion.Euler(0, 0, maxLegAngle + maxLegAngle * Mathf.Sin(animationStep * -legSpeed)); - - animationStep += Time.deltaTime * Mathf.Abs(movement.x); + + // Point the arms at the ball. + leftArm.transform.up = -(game.ball.transform.position - leftArm.transform.position); + rightArm.transform.up = -(game.ball.transform.position - rightArm.transform.position); } [Serializable] diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs index 926238a..c9cb0ce 100644 --- a/Assets/Scripts/Controllers/GameController.cs +++ b/Assets/Scripts/Controllers/GameController.cs @@ -90,7 +90,7 @@ namespace Controllers freezeMotion = false; startTime = Time.time; - ball.Rigidbody.velocity = new Vector2(0, 5f); + ball.Rigidbody.velocity = new Vector2(0, 10f); } private void Update() @@ -102,7 +102,7 @@ namespace Controllers { if (player.HasBall || enemy.HasBall) { - ball.transform.position = ballTarget - new Vector3(0, Mathf.Sin(Time.time * dribbleHeight * dribbleSpeed) + 1f, 0); + ball.transform.position = ballTarget - new Vector3(0, (Mathf.Sin(Time.time * dribbleSpeed) + 1f) * (ballTarget.y - 0.75f) * dribbleHeight, 0); } } -- cgit v1.2.3-56-ge451