Files cleanup, added summoner code
This commit is contained in:
66
Assets/AI/_Archer/DEC_CanShoot.cs
Normal file
66
Assets/AI/_Archer/DEC_CanShoot.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Invector.vCharacterController.AI.FSMBehaviour;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ArcherEnemy
|
||||
{
|
||||
/// <summary>
|
||||
/// Decision checking if archer can shoot
|
||||
/// Checks cooldown, aiming, and射ing AI component readiness
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Invector/FSM/Decisions/Archer/Can Shoot")]
|
||||
public class DEC_CanShoot : vStateDecision
|
||||
{
|
||||
public override string categoryName => "Archer/Combat";
|
||||
public override string defaultName => "Can Shoot";
|
||||
|
||||
[Header("Configuration")]
|
||||
[Tooltip("Check if archer is facing target within tolerance")]
|
||||
public bool checkFacingTarget = true;
|
||||
|
||||
[Tooltip("Angle tolerance for shooting (degrees)")]
|
||||
public float aimTolerance = 20f;
|
||||
|
||||
[Header("Debug")]
|
||||
[Tooltip("Enable debug logging")]
|
||||
public bool enableDebug = false;
|
||||
|
||||
public override bool Decide(vIFSMBehaviourController fsmBehaviour)
|
||||
{
|
||||
// Get ArcherShootingAI component
|
||||
var shootingAI = fsmBehaviour.gameObject.GetComponent<ArcherShootingAI>();
|
||||
|
||||
if (shootingAI == null)
|
||||
{
|
||||
if (enableDebug) Debug.LogWarning("[DEC_CanShoot] No ArcherShootingAI component found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use the shooting AI's CanShoot method
|
||||
bool canShoot = shootingAI.CanShoot();
|
||||
|
||||
// Optional: additional facing check
|
||||
if (canShoot && checkFacingTarget)
|
||||
{
|
||||
Transform target = shootingAI.GetTarget();
|
||||
if (target != null)
|
||||
{
|
||||
Vector3 directionToTarget = (target.position - fsmBehaviour.transform.position).normalized;
|
||||
float angle = Vector3.Angle(fsmBehaviour.transform.forward, directionToTarget);
|
||||
|
||||
if (angle > aimTolerance)
|
||||
{
|
||||
canShoot = false;
|
||||
if (enableDebug) Debug.Log($"[DEC_CanShoot] Not facing target: {angle:F1}° (tolerance: {aimTolerance}°)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enableDebug)
|
||||
{
|
||||
Debug.Log($"[DEC_CanShoot] {(canShoot ? "CAN SHOOT" : "CANNOT SHOOT")}");
|
||||
}
|
||||
|
||||
return canShoot;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user