using Core; using UnityEngine; namespace Minigames.FortFight.Projectiles { /// /// Vacuum projectile - high mass, slides along ground after landing. /// On floor/block impact: applies constant force to the right and destroys blocks. /// public class VacuumProjectile : ProjectileBase { private bool isSliding = false; private int blocksDestroyed = 0; private int maxBlocksToDestroy = 3; private Vector2 slideDirection; protected override void OnHit(Collision2D collision) { // If already sliding, count block destruction if (isSliding) { var block = collision.gameObject.GetComponent(); if (block != null) { // Spawn impact effect on each block hit SpawnImpactEffect(collision.contacts[0].point); // Get damage from settings var settings = GameManager.GetSettingsObject(); float blockDamage = settings?.VacuumBlockDamage ?? 999f; // Deal high damage to destroy block instantly block.TakeDamage(blockDamage); blocksDestroyed++; Logging.Debug($"[VacuumProjectile] Destroyed block {blocksDestroyed}/{maxBlocksToDestroy}"); if (blocksDestroyed >= maxBlocksToDestroy) { Logging.Debug("[VacuumProjectile] Destroyed max blocks - stopping"); DestroyProjectile(); } } // Don't destroy - keep sliding return; } // First hit - spawn impact effect and start sliding SpawnImpactEffect(collision.contacts[0].point); Logging.Debug("[VacuumProjectile] Hit surface - starting slide"); StartSliding(); // Don't destroy - keep sliding! } /// /// Start sliding behavior after hitting surface /// private void StartSliding() { if (isSliding) return; isSliding = true; // Get settings var settings = GameManager.GetSettingsObject(); if (settings != null) { maxBlocksToDestroy = settings.VacuumDestroyBlockCount; } // Determine slide direction based on horizontal velocity (preserve launch direction) if (rb2D != null) { slideDirection = rb2D.linearVelocity.x >= 0 ? Vector2.right : Vector2.left; rb2D.gravityScale = 0f; rb2D.linearVelocity = Vector2.zero; // Stop all momentum Logging.Debug($"[VacuumProjectile] Started sliding in direction: {slideDirection}"); } } private void FixedUpdate() { if (isSliding && rb2D != null) { // Set constant velocity in slide direction var settings = GameManager.GetSettingsObject(); float slideSpeed = settings?.VacuumSlideSpeed ?? 10f; rb2D.linearVelocity = slideDirection * slideSpeed; } } /// /// Clean up when destroyed /// protected override void DestroyProjectile() { isSliding = false; base.DestroyProjectile(); } } }