From 8fdefdc1a6f9195b824f8a300e1e16386057bf52 Mon Sep 17 00:00:00 2001 From: Miguel Astor Date: Wed, 5 Aug 2026 01:31:38 -0400 Subject: [PATCH] TO SQUASH: Eye ball reorientation towards bar. --- Assets/Scripts/Game/BallSpawner.cs | 24 ++++++++++++------------ Assets/Scripts/Game/Balls/EyeBall.cs | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Game/BallSpawner.cs b/Assets/Scripts/Game/BallSpawner.cs index 5c78c5c..e66dc58 100644 --- a/Assets/Scripts/Game/BallSpawner.cs +++ b/Assets/Scripts/Game/BallSpawner.cs @@ -29,18 +29,18 @@ public class BallSpawner : MonoBehaviour { int currentLevel = PlayerPrefs.GetInt("CurrentLevel"); - ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(oozeBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(nuclearBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); - ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(oozeBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(nuclearBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); + // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab)); StartCoroutine(SpawnBalls()); diff --git a/Assets/Scripts/Game/Balls/EyeBall.cs b/Assets/Scripts/Game/Balls/EyeBall.cs index aeecc84..5b03162 100644 --- a/Assets/Scripts/Game/Balls/EyeBall.cs +++ b/Assets/Scripts/Game/Balls/EyeBall.cs @@ -2,6 +2,8 @@ using UnityEngine; public class EyeBall : BallBase { + private static float reorientationAngleDegrees = 3f; + // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { @@ -17,7 +19,24 @@ public class EyeBall : BallBase { AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); - // TODO: Adjust eye ball direction based on the player's bar if active. + // Adjust eye ball direction based on the player's bar if active. + var barSegments = GameObject.FindGameObjectsWithTag("Bar"); + + if (barSegments.Length > 0) + { + // For simplicity, just take the first bar segment found. + var barSegment = barSegments[0]; + Vector3 directionToBar = (barSegment.transform.position - transform.position).normalized; + float currentSpeed = speed.magnitude; + + if (currentSpeed > 0f) + { + float signedAngle = Vector2.SignedAngle(speed.normalized, (Vector2)directionToBar); + float clampedAngle = Mathf.Clamp(signedAngle, -reorientationAngleDegrees, reorientationAngleDegrees); + Vector2 smoothDirection = (Vector2)(Quaternion.Euler(0f, 0f, clampedAngle) * speed.normalized); + speed = smoothDirection * currentSpeed; // Maintain current speed magnitude + } + } if (stateInfo.IsName("EyeBallMove")) { transform.Translate(speed);