diff options
author | Carson Katri <carson.katri@gmail.com> | 2021-06-13 08:51:14 -0400 |
---|---|---|
committer | Carson Katri <carson.katri@gmail.com> | 2021-06-13 08:51:14 -0400 |
commit | c65c617e2031aa6ece4fa6831891fcf1e13662d4 (patch) | |
tree | f8a8fd0d37be0b3ef2a736187ea6d999e7069fb6 /Assets/Scripts | |
parent | ac864b588ee59fbbc62c8bcf7c82cc51767276ec (diff) | |
download | gmtk-gamejam-c65c617e2031aa6ece4fa6831891fcf1e13662d4.tar.gz gmtk-gamejam-c65c617e2031aa6ece4fa6831891fcf1e13662d4.tar.zst gmtk-gamejam-c65c617e2031aa6ece4fa6831891fcf1e13662d4.zip |
Fix animations, and improve helptext
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Controllers/AIController.cs | 31 | ||||
-rw-r--r-- | Assets/Scripts/Controllers/GameController.cs | 4 |
2 files changed, 24 insertions, 11 deletions
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<Rigidbody2D>(); private Rigidbody2D _rigidbody; - private float animationStep; private bool turn; public BoxCollider2D BoxCollider => _boxCollider != null ? _boxCollider : _boxCollider = GetComponent<BoxCollider2D>(); private BoxCollider2D _boxCollider; + + public Animator Animator => _animator != null ? _animator : _animator = GetComponent<Animator>(); + 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); } } |