TO SQUASH: Eye ball reorientation towards bar.

This commit is contained in:
2026-08-05 01:31:38 -04:00
parent c91a405227
commit 8fdefdc1a6
2 changed files with 32 additions and 13 deletions
+12 -12
View File
@@ -29,18 +29,18 @@ public class BallSpawner : MonoBehaviour
{ {
int currentLevel = PlayerPrefs.GetInt("CurrentLevel"); int currentLevel = PlayerPrefs.GetInt("CurrentLevel");
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
ballQueue.Enqueue(() => SpawnBall(basicBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(basicBallPrefab));
ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(fruitBallPrefab));
ballQueue.Enqueue(() => SpawnBall(oozeBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(oozeBallPrefab));
ballQueue.Enqueue(() => SpawnBall(nuclearBallPrefab)); // 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(glassBallPrefab));
ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
ballQueue.Enqueue(() => SpawnBall(glassBallPrefab)); // ballQueue.Enqueue(() => SpawnBall(glassBallPrefab));
ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab)); ballQueue.Enqueue(() => SpawnBall(eyeBallPrefab));
StartCoroutine(SpawnBalls()); StartCoroutine(SpawnBalls());
+20 -1
View File
@@ -2,6 +2,8 @@ using UnityEngine;
public class EyeBall : BallBase public class EyeBall : BallBase
{ {
private static float reorientationAngleDegrees = 3f;
// Start is called once before the first execution of Update after the MonoBehaviour is created // Start is called once before the first execution of Update after the MonoBehaviour is created
void Start() void Start()
{ {
@@ -17,7 +19,24 @@ public class EyeBall : BallBase
{ {
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); 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")) { if (stateInfo.IsName("EyeBallMove")) {
transform.Translate(speed); transform.Translate(speed);