Hi I’ve made a few code changes to make it so the enemies attack range will work based on the equipped weapons attack range rather than having to manually increase the enemies chase distance.
First in fighter
move equipweapon into awake otherwise the execution order will cause an error:
private void Awake()
{
_mover = GetComponent<Mover>();
_animator = GetComponent<Animator>();
EquipWeapon(_defaultWeapon);
}
Make a public getter for currentweapon:
public Weapon CurrentlyEquipedWeapon => _currentWeapon;
Now in AIController
create an attackRange float and then set it start:
private void Start()
{
_guardPosition = transform.position;
_attackRange = _fighter.CurrentlyEquipedWeapon.WeaponRange;
}
Then in the bool that checks if in range of player (I can’t remember original name I changed mine) create an if else that will make the chase/attack range based on if the attack range is higher than the set chase distance:
private bool InAttackRangeOfPlayer()
{
float distanceToPlayer = Vector3.Distance(_player.transform.position, gameObject.transform.position);
if (_attackRange > _chaseDistance)
{
return distanceToPlayer < _attackRange;
}
else
{
return distanceToPlayer < _chaseDistance;
}
}