Okay @Brian_Trotter, I’ve managed to change most of the Friend-Foe System, I’m struggling with the AIController.cs since it needs requires a game object with the “player” tag.
These are the changes that I have made so far;
For ControllerBase.cs
using UnityEngine;
namespace RPG.Control
{
public abstract class ControllerBase : MonoBehaviour
{
public int team;
int charmedTeam = 0; //<- doesn't accept team;
float charmedTimeRemaining = 0;
public int Team => charmedTeam>0? charmedTeam : team;
public void Charm(int newTeam, float charmTime)
{
if(charmedTimeRemaining>0 && charmedTeam==newTeam)
{
charmedTimeRemaining+=charmTime; //Extend exisiting charm
}
else
{
charmedTeam = newTeam;
charmedTimeRemaining = charmTime;
}
}
public virtual void Update()
{
if(charmedTimeRemaining > 0) charmedTimeRemaining -= Time.deltaTime;
}
}
}
in CombatTarget.cs I added
if(callingController.GetComponent().team == gameObject.GetComponent().team) return false;
Within the HandleRaycast() Method, then in PlayerController.cs I changed enemiesInRange from a gameobject to an int and changed TriggerAttackMode() from returning a gameobject to returning an int as well making the method look like this:
public bool TriggerAttackMode(int combatTarget)
{
if (combatTarget == team) return false;
RaycastHit[] hits = Physics.SphereCastAll(transform.position, detectEnemyRange, Vector3.up, 0);
foreach (RaycastHit hit in hits)
{
Health target = hit.collider.GetComponent<Health>();
ControllerBase enemies = hit.collider.GetComponent<ControllerBase>();
if(enemies.team == team) return false;
if (enemies == null) return false;
if(target== null) return false;
if (target.IsDead()) return false;
return true;
}
return false;
}
Finally I added in the AIController.cs
public bool CheckTeam()
{
RaycastHit[] hits = Physics.SphereCastAll(transform.position, chaseDistance, Vector3.up, 0);
foreach (RaycastHit hit in hits)
{
ControllerBase enemy = hit.collider.GetComponent<ControllerBase>();
if (enemy == null) continue;
if(enemy.Team != Team) return true;
}
return false;
}
then adding it to the AttackPlayer() method to look like this:
if (IsAggrevated()&& CheckTeam() && fighter.CanAttack(hostile))
{
AttackBehaviour();
}
So my main issue is that in the AIController.cs is returning a gameobject to trigger the Fighter.cs (and I don’t think converting everything from a gameobject into an int within Fighter.cs is efficient nor the solution) so as is this is what it looks like:
//Cache
GameObject hostile;
private void Awake()
{
hostile = GameObject.FindGameObjectWithTag("Player"); // need to change to return object with ControllerBase
}
fighter.CanAttack(hostile) //<- within the AttackPlayer()
,
private void AttackBehaviour()
{
timeSinceLastSawPlayer = 0;
if (fighter.CanAttack(hostile))
{
fighter.Attack(hostile);
}
else
{
return;
}
AggrevateNearbyEnemies();
}
and
public bool IsAggrevated()
{
float distanceToPlayer = Vector3.Distance(hostile.transform.position, transform.position);
//^^ needs to return specific gameobject or else null exception error.
return distanceToPlayer < chaseDistance|| timeSinceAggrevated < aggroCoolDown;
}
Everything else but the AIController works, the closest I’ve gotten causes the AI to attack itself if the player aggravates it. Is there something I’m missing or does this require a larger overhaul than I expected? Thank you again for your time.