Graphics Reference
In-Depth Information
When both left and right sides ahead are blocked by an obstacle, the bot will simply
back up. This behavior may not be ideal in all situations, but for the Tank Bat tl e example
game in this topic, I saw it as the equivalent of making the AI wait for its target to come
back out from behind the wall. This code tends to make the bot hang around until it even-
tually turns to face its target:
if( obstacleFinderResult==3 ){ // BACK UP
MoveBack ();
}
break;
The AIState.paused_no_target state does literally nothing. It doesn't aim or move—
none of that!
case AIState.paused_no_target:
// paused_no_target
break;
Just in case something falls through the cracks, this function provides a default
behavior similar to your average politician—that of doing nothing:
default:
// idle (do nothing)
break;
}
}
That's is the UpdateAI() function all wrapped up. Next, there is a collection of func-
tions to set inputs for turning left and right or moving forward and backward. The reason
that these have their own functions rather than just setting them in the UpdateAI() code
is so that it would be easy to deal with other types of control systems by overriding them
in a derived class. In this script, it is literally a case of setting the values of the horz and
vert variables as required:
public virtual void TurnLeft ()
{
horz= -1;
}
public virtual void TurnRight ()
{
horz= 1;
}
public virtual void MoveForward ()
{
vert= 1;
}
public virtual void MoveBack ()
{
vert= -1;
}
Search WWH ::




Custom Search