Creating a decision tree agent
To create an agent whose logic is controlled by our decision tree, we'll modify our indirect soldier agent, as the initial setup of an animation state machine and soldier controller is already done for us.
We'll first create the userData
table and associate the initial values so that our decision tree can interact with the agent. Once we've populated the userData
table, we can instantiate our decision tree. We'll change the agent's update loop to process the decision tree as well as the soldier controller. As our decision tree expects that the execution will end when an agent dies, we'll add a conditional check that halts updates when this occurs:
IndirectSoldierAgent.lua
:
local soldier; local soldierController; local soldierDecisionTree; local soldierUserData; function Agent_Initialize(agent) Soldier_InitializeAgent(agent); soldier = Soldier_CreateSoldier(agent); weapon = Soldier_CreateWeapon(agent); soldierController = SoldierController.new...