Fixes
This commit is contained in:
@@ -36,8 +36,8 @@ namespace DemonBoss.Magic
|
||||
[Tooltip("Layer mask for ground")]
|
||||
public LayerMask groundLayerMask = -1;
|
||||
|
||||
[Tooltip("Animator trigger name for crystal casting animation")]
|
||||
public string animatorTrigger = "CastCrystal";
|
||||
[Tooltip("Animator bool parameter name for blocking state")]
|
||||
public string animatorBlockingBool = "IsBlocking";
|
||||
|
||||
[Header("Smart Positioning")]
|
||||
[Tooltip("Preference multiplier for positions behind boss (relative to player)")]
|
||||
@@ -54,7 +54,8 @@ namespace DemonBoss.Magic
|
||||
public bool showGizmos = true;
|
||||
|
||||
private GameObject spawnedCrystal;
|
||||
|
||||
private Animator npcAnimator;
|
||||
private Transform npcTransform;
|
||||
private Transform playerTransform;
|
||||
|
||||
/// <summary>
|
||||
@@ -66,6 +67,10 @@ namespace DemonBoss.Magic
|
||||
{
|
||||
OnStateEnter(fsmBehaviour);
|
||||
}
|
||||
else if (executionType == vFSMComponentExecutionType.OnStateExit)
|
||||
{
|
||||
OnStateExit(fsmBehaviour);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,13 +80,16 @@ namespace DemonBoss.Magic
|
||||
{
|
||||
if (enableDebug) Debug.Log("[SA_SpawnTurretSmart] Starting intelligent crystal spawn");
|
||||
|
||||
// Store NPC references
|
||||
npcTransform = fsmBehaviour.transform;
|
||||
npcAnimator = npcTransform.GetComponent<Animator>();
|
||||
|
||||
FindPlayer(fsmBehaviour);
|
||||
|
||||
var animator = fsmBehaviour.transform.GetComponent<Animator>();
|
||||
if (animator != null && !string.IsNullOrEmpty(animatorTrigger))
|
||||
if (npcAnimator != null && !string.IsNullOrEmpty(animatorBlockingBool))
|
||||
{
|
||||
animator.SetTrigger(animatorTrigger);
|
||||
if (enableDebug) Debug.Log($"[SA_SpawnTurretSmart] Set trigger: {animatorTrigger}");
|
||||
npcAnimator.SetBool(animatorBlockingBool, true);
|
||||
if (enableDebug) Debug.Log($"[SA_SpawnTurretSmart] Set bool: {animatorBlockingBool} = true");
|
||||
}
|
||||
|
||||
SpawnCrystalSmart(fsmBehaviour);
|
||||
@@ -89,6 +97,20 @@ namespace DemonBoss.Magic
|
||||
DEC_CheckCooldown.SetCooldownStatic(fsmBehaviour, "Turret", 12f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when exiting state - cleanup
|
||||
/// </summary>
|
||||
private void OnStateExit(vIFSMBehaviourController fsmBehaviour)
|
||||
{
|
||||
if (enableDebug) Debug.Log("[SA_SpawnTurretSmart] Exiting turret spawn state");
|
||||
|
||||
if (npcAnimator != null && !string.IsNullOrEmpty(animatorBlockingBool))
|
||||
{
|
||||
npcAnimator.SetBool(animatorBlockingBool, false);
|
||||
if (enableDebug) Debug.Log($"[SA_SpawnTurretSmart] Set bool: {animatorBlockingBool} = false");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds player transform
|
||||
/// </summary>
|
||||
@@ -128,7 +150,7 @@ namespace DemonBoss.Magic
|
||||
bool foundValidPosition = false;
|
||||
float bestScore = float.MinValue;
|
||||
|
||||
Vector3 bossPos = fsmBehaviour.transform.position;
|
||||
Vector3 bossPos = npcTransform.position;
|
||||
Vector3 playerDirection = Vector3.zero;
|
||||
|
||||
if (playerTransform != null)
|
||||
@@ -146,7 +168,7 @@ namespace DemonBoss.Magic
|
||||
|
||||
if (IsPositionValid(testPosition, out Vector3 groundPosition))
|
||||
{
|
||||
float score = EvaluatePosition(groundPosition, playerDirection, direction);
|
||||
float score = EvaluatePosition(groundPosition, playerDirection, direction, bossPos);
|
||||
|
||||
if (score > bestScore)
|
||||
{
|
||||
@@ -164,7 +186,7 @@ namespace DemonBoss.Magic
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 fallbackPos = bossPos + fsmBehaviour.transform.forward * minSpawnDistance;
|
||||
Vector3 fallbackPos = bossPos + npcTransform.forward * minSpawnDistance;
|
||||
SpawnCrystal(fallbackPos, fsmBehaviour);
|
||||
if (enableDebug) Debug.LogWarning("[SA_SpawnTurretSmart] Using fallback position");
|
||||
}
|
||||
@@ -201,7 +223,7 @@ namespace DemonBoss.Magic
|
||||
/// <summary>
|
||||
/// Evaluates position quality (higher score = better position)
|
||||
/// </summary>
|
||||
private float EvaluatePosition(Vector3 position, Vector3 playerDirection, Vector3 positionDirection)
|
||||
private float EvaluatePosition(Vector3 position, Vector3 playerDirection, Vector3 positionDirection, Vector3 bossPos)
|
||||
{
|
||||
float score = 0f;
|
||||
|
||||
@@ -214,7 +236,6 @@ namespace DemonBoss.Magic
|
||||
score += backScore * backPreferenceMultiplier;
|
||||
}
|
||||
|
||||
Vector3 bossPos = new Vector3();
|
||||
float distance = Vector3.Distance(position, bossPos);
|
||||
float optimalDistance = (minSpawnDistance + maxSpawnDistance) * 0.5f;
|
||||
float distanceScore = 1f - Mathf.Abs(distance - optimalDistance) / maxSpawnDistance;
|
||||
@@ -264,17 +285,20 @@ namespace DemonBoss.Magic
|
||||
{
|
||||
if (!showGizmos) return;
|
||||
|
||||
Vector3 pos = new Vector3();
|
||||
if (npcTransform != null)
|
||||
{
|
||||
Vector3 pos = npcTransform.position;
|
||||
|
||||
// Spawn ring
|
||||
Gizmos.color = Color.green;
|
||||
DrawWireCircle(pos, minSpawnDistance);
|
||||
Gizmos.color = Color.red;
|
||||
DrawWireCircle(pos, maxSpawnDistance);
|
||||
// Spawn ring
|
||||
Gizmos.color = Color.green;
|
||||
DrawWireCircle(pos, minSpawnDistance);
|
||||
Gizmos.color = Color.red;
|
||||
DrawWireCircle(pos, maxSpawnDistance);
|
||||
|
||||
// Obstacle check radius
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(pos + Vector3.up * obstacleCheckRadius, obstacleCheckRadius);
|
||||
// Obstacle check radius
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(pos + Vector3.up * obstacleCheckRadius, obstacleCheckRadius);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user