Game Development Reference
In-Depth Information
The change stance command
Creating a command handler typically follows a similar style to previous command hand-
lers regardless of the command being handled. First, you handle any manipulation of the
command queue that needs to happen, perform the specific action associated with the com-
mand, and then remove the command once it finishes. As commands can run over multiple
update loops, each command must take this into account.
The change stance command slightly differs from other commands, as it can push an addi-
tional command back onto the queue. The change stance command looks whether any addi-
tional commands are already queued; if not, then the previous executing command is
pushed back onto the queue. This allows the controller to change the agent's stance and
then return to what the agent was previously doing, as the change stance command does not
loop:
SoldierController.lua :
local function _ExecuteChangeStanceCommand(
self, agent, deltaTimeInMillis)
-- Requeues the previous command since change stance
isn't a
-- state the soldier can stay in.
if (#self.commands == 0) then
self:ImmediateCommand(agent, self.previousCommand);
end
-- Immediately changes the stance of the agent. The
requeued
-- command is responsible for actually transitioning the
agent
-- to the correct stance visually.
if (_stance == SoldierController.Stances.CROUCH) then
_stance = SoldierController.Stances.STAND;
Soldier_SetHeight(
agent, _soldierMesh, Soldier.Height.Stand);
else
_stance = SoldierController.Stances.CROUCH;
Soldier_SetHeight(
Search WWH ::




Custom Search