Continued working on AI Controller

This commit is contained in:
Caleb Sandford deQuincey
2025-10-30 16:50:35 +00:00
parent 1972134c81
commit b838293aa5
13 changed files with 73 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
using System;
using RPG.Combat;
using RPG.Core;
using RPG.Movement;
using UnityEngine;
using UnityEngine.AI;
@@ -8,21 +10,54 @@ namespace RPG.Control
public class AIController : MonoBehaviour,IAction
{
[SerializeField] float chaseDistance = 5f;
[SerializeField] float suspicionTime = 3f;
Fighter fighter;
Health health;
Mover mover;
GameObject player;
void Start()
Vector3 guardPosition;
float timeSinceLastSawPlayer = Mathf.Infinity;
private void Start()
{
fighter = GetComponent<Fighter>();
health = GetComponent<Health>();
player = GameObject.FindWithTag("Player");
mover = GetComponent<Mover>();
guardPosition = transform.position;
}
void Update()
private void Update()
{
if (health.IsDead()) return;
if (InAttackRangeOfPlayer() && fighter.CanAttack(player))
fighter.Attack(player);
{
timeSinceLastSawPlayer = 0;
AttackBehaviour();
}
else if (timeSinceLastSawPlayer < suspicionTime)
{
SuspicionBehaviour();
}
else
{
fighter.Cancel();
//fighter.Cancel();
GuardBehaviour();
}
timeSinceLastSawPlayer += Time.deltaTime;
}
private void GuardBehaviour()
{
mover.StartMoveAction(guardPosition);
}
private void SuspicionBehaviour()
{
GetComponent<ActionScheduler>().CancelCurrentAction();
}
private void AttackBehaviour()
{
fighter.Attack(player);
}
private bool InAttackRangeOfPlayer()
@@ -33,7 +68,13 @@ namespace RPG.Control
public void Cancel()
{
}
//Called bt Unity
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position, chaseDistance);
}
}
}