using Core; using Core.Lifecycle; using Core.Settings; using UnityEngine; namespace Minigames.BirdPooper { /// /// Poop projectile that falls straight down with manual gravity. /// Destroys when off-screen or hitting targets (Phase 5). /// [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(Collider2D))] public class PoopProjectile : ManagedBehaviour { private IBirdPooperSettings settings; private float verticalVelocity; // Current downward velocity private const float GravityAcceleration = 20f; // Gravity acceleration (units/s²) internal override void OnManagedAwake() { base.OnManagedAwake(); // Load settings settings = GameManager.GetSettingsObject(); if (settings == null) { Debug.LogError("[PoopProjectile] BirdPooperSettings not found!"); Destroy(gameObject); return; } // Initialize velocity with settings speed as starting velocity verticalVelocity = settings.PoopFallSpeed; // Verify Rigidbody2D configuration Rigidbody2D rb = GetComponent(); if (rb != null) { rb.bodyType = RigidbodyType2D.Dynamic; rb.gravityScale = 0f; // Manual gravity rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous; } // Verify collider is trigger (for target detection in Phase 5) Collider2D col = GetComponent(); if (col != null && !col.isTrigger) { Debug.LogWarning("[PoopProjectile] Collider should be set as Trigger for target detection!"); } } private void Update() { if (settings != null) { ApplyGravity(); FallDown(); CheckBounds(); } } /// /// Apply gravity acceleration to velocity. /// private void ApplyGravity() { // Increase downward velocity over time (gravity acceleration) verticalVelocity += GravityAcceleration * Time.deltaTime; } /// /// Manual downward movement using current velocity. /// private void FallDown() { // Move straight down at current velocity transform.position += Vector3.down * verticalVelocity * Time.deltaTime; } /// /// Check if projectile is off-screen and should be destroyed. /// private void CheckBounds() { if (transform.position.y < settings.PoopDestroyYPosition) { Destroy(gameObject); } } /// /// Trigger collision detection for targets (Phase 5). /// TODO: Uncomment when Target.cs is implemented in Phase 5 /// private void OnTriggerEnter2D(Collider2D other) { // Phase 5 integration - currently commented out /* if (other.CompareTag("Target")) { // Notify target it was hit Target target = other.GetComponent(); if (target != null) { target.OnHitByProjectile(); } Destroy(gameObject); } */ } } }