Fix weapon selection issues and shot tracking

This commit is contained in:
Michal Pikulski
2025-12-16 19:29:01 +01:00
parent bd4c365d98
commit c5f37a5df4
4 changed files with 125 additions and 49 deletions

View File

@@ -1,8 +1,10 @@
using System.Collections;
using System;
using System.Collections;
using Core;
using Core.Settings;
using Input;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Minigames.FortFight.Projectiles
{
@@ -23,6 +25,12 @@ namespace Minigames.FortFight.Projectiles
private bool inputEnabled = false;
private bool hasExploded = false;
/// <summary>
/// Fired when trash bag explodes and spawns pieces.
/// Parameters: (Transform trashPieceToFollow) - a piece for camera to follow
/// </summary>
public event Action<Transform> OnTrashPiecesSpawned;
public override void Launch(Vector2 direction, float force)
{
base.Launch(direction, force);
@@ -145,13 +153,14 @@ namespace Minigames.FortFight.Projectiles
/// <summary>
/// Spawn multiple trash pieces in a cone away from the hit surface.
/// Uses hit normal + projectile momentum for realistic splash effect.
/// Returns the first spawned trash piece for camera tracking.
/// </summary>
private void SpawnTrashPieces(Vector2 impactPoint, Vector2 hitNormal)
private Transform SpawnTrashPieces(Vector2 impactPoint, Vector2 hitNormal)
{
if (trashPiecePrefab == null)
{
Logging.Warning("[TrashBagProjectile] No trash piece prefab assigned!");
return;
return null;
}
// Get settings
@@ -175,6 +184,8 @@ namespace Minigames.FortFight.Projectiles
// 70% normal (splash away from surface) + 30% reflection (maintain some momentum direction)
Vector2 baseDirection = (hitNormal * 0.7f + reflectDirection * 0.3f).normalized;
Transform firstPiece = null;
// Spawn pieces in a cone around the base direction
for (int i = 0; i < pieceCount; i++)
{
@@ -189,6 +200,12 @@ namespace Minigames.FortFight.Projectiles
Vector2 spawnOffset = pieceDirection * 0.2f; // Small offset to prevent clipping
GameObject piece = Instantiate(trashPiecePrefab, (Vector2)impactPoint + spawnOffset, Quaternion.identity);
// Store first piece for camera tracking
if (i == 0 && piece != null)
{
firstPiece = piece.transform;
}
// Setup trash piece physics
Rigidbody2D pieceRb = piece.GetComponent<Rigidbody2D>();
if (pieceRb != null)
@@ -203,6 +220,14 @@ namespace Minigames.FortFight.Projectiles
Logging.Debug($"[TrashBagProjectile] Spawned trash piece {i} in direction {pieceDirection}");
}
// Fire event with first piece for camera tracking
if (firstPiece != null)
{
OnTrashPiecesSpawned?.Invoke(firstPiece);
}
return firstPiece;
}
#region ITouchInputConsumer Implementation