Game Development Reference
In-Depth Information
{
}
In the Guard function, we check to see whether the AI notices the player or not. If it
does, then it will proceed to search for the player; if not, then it will continue to patrol
along its path. In the Combat function, we first check to see whether the player is
within the attacking range; if not, then the AI searches again. If the player is within
the attacking range, we check to see whether the AI prefers attacking up close or far
away.
For ranged attacks, we first create a new, temporary GameObject variable. Then,
we set it to an instantiated clone of our Projectile GameObject. From here, the
projectile will run its own scripts to determine what it does. This is how we allow our
AI to attack the player from a distance.
To finish off our actions, we have two more functions to add. The first one will be to
change the health of the AI, which is as follows:
void ChangeHealth(int Amount)
{
if(Amount < 0)
{
if(!isSuspicious)
{
isSuspicious = true;
ChangeBehavior(Behaviors.Guard);
}
}
for(int i = 0; i < Stats.Capacity; i++)
{
if(Stats[i].Key == "Health")
{
int tempValue = Stats[i].Value;
Stats[i] = new KeyValuePair<string,
int>(Stats[i].Key, tempValue += Amount);
if(Stats[i].Value <= 0)
{
Search WWH ::




Custom Search