83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using System.Collections;
|
|
using Core;
|
|
using UnityEngine;
|
|
|
|
namespace Minigames.FortFight.Projectiles
|
|
{
|
|
/// <summary>
|
|
/// Vacuum projectile - high mass, slides along ground after landing.
|
|
/// On ground impact: disables gravity, moves horizontally for 2 seconds.
|
|
/// </summary>
|
|
public class VacuumProjectile : ProjectileBase
|
|
{
|
|
[Header("Vacuum Specific")]
|
|
[Tooltip("Speed when sliding on ground")]
|
|
[SerializeField] private float slideSpeed = 10f;
|
|
|
|
[Tooltip("How long to slide before destroying")]
|
|
[SerializeField] private float slideDuration = 2f;
|
|
|
|
[Tooltip("Layer mask for ground detection")]
|
|
[SerializeField] private LayerMask groundLayer = 1; // Default layer
|
|
|
|
private bool isSliding = false;
|
|
|
|
protected override void OnHit(Collider2D hit)
|
|
{
|
|
// Check if hit ground
|
|
if (((1 << hit.gameObject.layer) & groundLayer) != 0)
|
|
{
|
|
Logging.Debug("[VacuumProjectile] Hit ground - starting slide");
|
|
StartSliding();
|
|
}
|
|
// If hit wall or fort block, destroy immediately (handled by base class)
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start sliding behavior after hitting ground
|
|
/// </summary>
|
|
private void StartSliding()
|
|
{
|
|
if (isSliding) return;
|
|
|
|
isSliding = true;
|
|
|
|
// Disable gravity
|
|
if (rb2D != null)
|
|
{
|
|
rb2D.gravityScale = 0f;
|
|
|
|
// Set velocity to horizontal only (preserve direction)
|
|
Vector2 horizontalVelocity = new Vector2(rb2D.linearVelocity.x, 0f).normalized * slideSpeed;
|
|
rb2D.linearVelocity = horizontalVelocity;
|
|
|
|
Logging.Debug($"[VacuumProjectile] Sliding with velocity: {horizontalVelocity}");
|
|
}
|
|
|
|
// Destroy after slide duration
|
|
StartCoroutine(SlideCoroutine());
|
|
}
|
|
|
|
private IEnumerator SlideCoroutine()
|
|
{
|
|
yield return new WaitForSeconds(slideDuration);
|
|
|
|
Logging.Debug("[VacuumProjectile] Slide duration ended - destroying");
|
|
DestroyProjectile();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override to NOT destroy immediately on ground hit
|
|
/// </summary>
|
|
protected override void DestroyProjectile()
|
|
{
|
|
// Only destroy if we're done sliding or hit a wall
|
|
if (!isSliding || rb2D.linearVelocity.magnitude < 1f)
|
|
{
|
|
base.DestroyProjectile();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|