Pigman AI input to detonate trashbag
This commit is contained in:
@@ -454,6 +454,12 @@ namespace Minigames.FortFight.AI
|
||||
return;
|
||||
}
|
||||
|
||||
// Subscribe to projectile launch for TrashBag detonation
|
||||
if (_selectedAmmo == ProjectileType.TrashBag)
|
||||
{
|
||||
aiSlingshot.OnProjectileLaunched += HandleTrashBagLaunched;
|
||||
}
|
||||
|
||||
// Fire projectile using velocity-based launch (proper ballistic physics)
|
||||
aiSlingshot.LaunchWithVelocity(launchVelocity);
|
||||
|
||||
@@ -466,6 +472,68 @@ namespace Minigames.FortFight.AI
|
||||
Logging.Debug($"[FortFightAIController] Shot executed: {_selectedAmmo} with velocity {launchVelocity}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle TrashBag launch - calculate and trigger detonation at strategic point
|
||||
/// </summary>
|
||||
private void HandleTrashBagLaunched(Projectiles.ProjectileBase projectile)
|
||||
{
|
||||
// Unsubscribe immediately
|
||||
aiSlingshot.OnProjectileLaunched -= HandleTrashBagLaunched;
|
||||
|
||||
var trashBag = projectile as Projectiles.TrashBagProjectile;
|
||||
if (trashBag == null)
|
||||
{
|
||||
Logging.Warning("[FortFightAIController] Launched projectile is not a TrashBag!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate detonation distance based on difficulty
|
||||
float detonationDistance = Random.Range(
|
||||
_currentDifficultyData.trashBagDetonationDistanceMin,
|
||||
_currentDifficultyData.trashBagDetonationDistanceMax
|
||||
);
|
||||
|
||||
// Calculate total trajectory distance
|
||||
float trajectoryDistance = Vector2.Distance(aiSlingshot.transform.position, _targetPosition);
|
||||
|
||||
// Convert normalized distance from target to world distance
|
||||
// detonationDistance is FROM target, so detonation point is at (1 - detonationDistance) along trajectory
|
||||
float detonationPointNormalized = 1f - detonationDistance;
|
||||
float worldDetonationDistance = trajectoryDistance * detonationPointNormalized;
|
||||
|
||||
Logging.Debug($"[FortFightAIController] TrashBag detonation planned: {detonationDistance:F2} from target ({worldDetonationDistance:F1} world units from launch)");
|
||||
|
||||
// Start monitoring for detonation
|
||||
StartCoroutine(MonitorTrashBagDetonation(trashBag, worldDetonationDistance));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monitor TrashBag distance and trigger detonation at calculated point
|
||||
/// </summary>
|
||||
private IEnumerator MonitorTrashBagDetonation(Projectiles.TrashBagProjectile trashBag, float targetDistance)
|
||||
{
|
||||
Vector2 launchPosition = aiSlingshot.transform.position;
|
||||
|
||||
// Wait a brief moment for projectile to get airborne
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
// Monitor distance traveled
|
||||
while (trashBag != null && !trashBag.AbilityActivated)
|
||||
{
|
||||
float distanceTraveled = Vector2.Distance(launchPosition, trashBag.transform.position);
|
||||
|
||||
// Check if we've reached or passed the detonation point
|
||||
if (distanceTraveled >= targetDistance)
|
||||
{
|
||||
Logging.Debug($"[FortFightAIController] Detonating TrashBag at distance {distanceTraveled:F1} (target: {targetDistance:F1})");
|
||||
trashBag.ActivateAbility();
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Debug Visualization
|
||||
|
||||
Reference in New Issue
Block a user