Game Development Reference
In-Depth Information
Indirect control agent control
Interfacing with the animation controller only requires queuing up additional commands.
We can bind different key events in order to queue each available command:
IndirectSoldierAgent.lua :
local function _IsNumKey(key, numKey)
-- Match both numpad keys and numeric keys.
return string.find(
key, string.format("^[numpad_]*%d_key$", numKey));
end
function Agent_HandleEvent(agent, event)
-- Queue a new command with the soldier controller.
if (event.source == "keyboard" and event.pressed) then
if (_IsNumKey(event.key, 1)) then
_soldierController:QueueCommand(
agent, SoldierController.Commands.IDLE);
elseif (_IsNumKey(event.key, 2)) then
_soldierController:QueueCommand(
agent, SoldierController.Commands.SHOOT);
elseif (_IsNumKey(event.key, 3)) then
_soldierController:QueueCommand(
agent, SoldierController.Commands.MOVE);
elseif (_IsNumKey(event.key, 4)) then
_soldierController:ImmediateCommand(
agent, SoldierController.Commands.DIE);
elseif (_IsNumKey(event.key, 5)) then
_soldierController:QueueCommand(
agent,
SoldierController.Commands.CHANGE_STANCE);
end
end
end
Search WWH ::




Custom Search