AI Spawning & Combat - Winds of War

Disclaimer: “Winds of War” is in active development, showcased features are not finalized.


In Winds of War, the core gameplay loop focuses on conquering lands using strategic combat and using gold to upgrade your army and purchase new units. Combat involves two sides of the battlefield spawning in units with the goal of having those units reaching the other side to deal damage to the enemy base. In the video, the green line trace shows where the player spawner currently is for the left side, the blue is for the AI on the right side.

Player & AI Spawning

Spawning units is handled differently for the player & AI.

  • The player character “BP_Player” keeps track of the currently selected unit, unit cooldowns, & unit counts. There is a separate spawner blueprint “BP_PlayerSpawner” which is referenced by the player character to control its up/down movement and to spawn the provided AI given it’s current transform when called.

BP_Player (Event Graph) - Showing Player Movement, Spawner Movement, & Spawning Selected Actor Events

 

BP_PlayerSpawner - Spawn Actor Function

 

The AI player “BP_AISpawner” uses a character blueprint with an assigned AI controller and blackboard/behavior tree to handle actions. The AI spawner is discussed more in the “Lane Data System for AI - Winds of War” post.

 

AIC_AI-Spawner - AI Controller

BT_AI-Spawner - Behavior Tree

 

Base AI

As for the units, they are all derived from a base class “BP_BaseAI”. When a new unit needs to be created, a child blueprint is made from BP_BaseAI and edited. They have several variables that need to be set:

 
 
  • Faction: the team they are a part of, used to prevent friendly attacking.

  • Name: the name given to this particular unit, will mainly be used for UI within the upgrade menu.

  • Armor Data Table: the armor set, also contains data for reducing incoming damage.

 
  • Weapon: the assigned weapon class.

  • Damage: the outgoing damage that occurs when the weapon hits an enemy.

  • Sweeping?: a boolean that determines if the weapon only deals damage to the first hit actor or if multiple actors can be hit during one swing (for larger weapons, like claymores).

  • Health: health points.

  • Speed: max walk speed.

  • Cooldown: how long this unit takes to increase its spawnable amount by +1 during combat.

  • Max Count: integer which determines how many can be ready to be spawned at any given time during combat.

  • Allies: an array of friendly factions (if two factions were to make alliances). Prevents attacking during combat.

  • Power: how much health is subtracted from the enemy base when reached and it’s also used with the lane system.

Base AI - Behavior Tree, Perception System, & Environmental Query System

A behavior tree is used to keep track of current actions on AI units. There are 4 different states which are set in the AI controller: Dead, Fleeing, Attacking, Passive to determine which sequence of actions should be followed. The framework is set up for expansion to ranged units (archers/mages).

 
 

The AI follows this gameplay loop:

  1. Walk to the other side of the battlefield. (Passive State)

  2. If an actor overlaps within a 300uu radius and is a valid target, set as TargetActor. (Attack State)

  3. If the actor is no longer valid (dead or out of range*), enter passive state.

  4. While in passive state, run an EQS (environmental query system) query** to check for another target. If valid, set TargetActor - if not, continue walking to the other side.

  5. When the actor reaches the safe zone of the other side (forest), enter fleeing state. Once fleeing, it can’t attack or be attacked. The enemy base then loses health once it reaches the very end.

* For determining if an actor is out of range, I’m utilizing Unreal’s AI perception system. If the AI can no longer see its target actor (determined by its dominant sense: sight), then it’s set to passive.

** When the AI is set to passive, an EQS query is ran which gets all actors within 300uu to determine if another target actor is valid. The closest actors are queried first. This is useful when several hostile targets are surrounding the AI.

Melee Combat - Anim Notify

Hit events for melee weapons are handled with an AnimNotifyState, static mesh sockets, and box traces.

  1. ANS_Attack is called for the duration of the downward swing of the attack animation.

 
 

2. During the anim notify’s tick, the AI’s weapon runs box traces between two sockets (Base, End) for hit events.

Animeke

Creator of animeke.moe, an anime content hub.

https://animeke.moe
Previous
Previous

AI - General Showcase

Next
Next

Lane Data System for AI - Winds of War