Make Enemies Fire Multiple Abilities
🔥
5
💛
1
✨
1
🥳
1
Hello friends I noticed while creating some more complex enemies that they only fire the first ability in their list. In order to make them fire randomly from the full list I modified the TryToAttackTarget method. Simply highlight the method in your code, control V the below, and hit save. The full file is attached.
private void TryToAttackTarget(float distanceToTarget)
{
if (m_attackCooldownTimer == 0.0f && distanceToTarget < m_attackTriggerRadius)
{
List<ITriggerableAbility> triggerableAbilities = new List<ITriggerableAbility>();
// Collect all triggerable abilities
foreach (AbilityBase ability in m_character.abilityInstances)
{
if (ability is ITriggerableAbility)
{
triggerableAbilities.Add((ITriggerableAbility)ability);
}
}
// Randomly select one of the triggerable abilities
if (triggerableAbilities.Count > 0)
{
int randomIndex = UnityEngine.Random.Range(0, triggerableAbilities.Count);
m_character.FireAbility(triggerableAbilities[randomIndex]);
m_attackCooldownTimer = m_attackCooldown;
}
}
}

💬 Comments (9)
AIControllerhasn’t been modifiedWant to continue the conversation?