Você está na página 1de 3

AI Senses

Sight:
Sight is the most powerful sense we humans have. Though there are those who have learned to
live without it, for the rest of us, it is the primary sense we depend on each day. However, AIs are
different. Because they have knowledge of a player's location, it is through the sense of sight, we can
limit an AIs knowledge and make it balanced and fun. Here is some pseudocode of how I would like to
limit an AIs sense of sight:

Public bool CanSee (Transform target){


if (Distance between Self & target <= viewDistance) {
Create Vector from Target to self;
Create Angle between Forward and vectorToTarget;
if (angleToTarget <= FOVAngle){
Create RaycastHit;
if(Raycast collides with object){
if(Collided with target){
Call CheckPercentageVisable (RaycastHit hitInfo);
return true;
}
}
}
}
return false;
}

Public void CheckPercentageVisable (RaycastHit hitInfo){


Grab Left-most and Right-most Edge Variable from Target.
Calculate percentage of visible target
Action Delay = (1 - percentageVisible) + Delay;
//This makes it seem like the AI is thinking about whether it can figure out if it is target or not.
}

This causes the AI to seem like its trying to think about whether it can figure out if what it see,
is the player. Even though it knows, and is just delaying its action in its Finite State Machine. Some
other details needed, is the left and right bounds of the player's model and having the player script store
those distances. These will be accessed when the AI can see the player and is used to calculate how
much the AI see's of the player. However, this is quite modular and can be added too. For example, you
can have an uncertainty threshold. Meaning, if the percentage of the player visible is smaller than the
threshold, then the AI may not Notice the player and continue in its Patrol state. You can also have
the RayCast add a layer mask to the parameters which could be used as an exclusion area. Like if the
player is in the Shadow Layer then, ignore the player, even if percentageVisible is 100%.

Hearing:
Hearing is such an under appreciated sense. When one become acute to their sense of hearing,
then so much more of your environment becomes noticeable and one's sense of their surroundings
become broader and they become more aware. This is the opposite of why AIs can hear. It is to limit an
AIs knowledge of their surroundings and cause them to only be perceptive under certain circumstances.
Here is some pseudocode of how I would like my AIs to hear:

Public bool CanHear (Transform target){


//Event: Sound is made
Calculate Local Sound Level (localDb)
if(localDb >= hearingThreshold){
return true;
}
return false;
}

Public float CalculateLocalDb (float EpicenterDb, Transform target, Transform self){


distanceBuffer = Round((Target.position self.position)/soundDelay);
localDb = EpicenterDb (10 * distanceBuffer);
return localDb;
}

This code allows for lots of variables. It uses distance to reduce how loud sounds are like how it
is in real life. This also means, that you can attach different values to different sounds. For example,
foot steps can be quite low in value so that the AI needs to be close to a player to hear them walk or
you can decrease their threshold to make the AI more sensitive to sound. This also means, that loud
explosions can be heard much farther away which is similar to how it works in real life.

Threat:
This is how threatening a player looks. This can be used to determine whether an AI fights or
flees or if it fights in your face or from a distance. This will be calculated through many things
including player level, number of opponents killed, Threat Level given from equipment, etc. Here is
some pseudocode of how I would calculate a player's Threat level:

(Inside Player Code)


Public float ThreatLevel ( ){
threatLevel = playerLevel + #ofEnemiesKilled + (Levels given from Equipment);
}

(Inside AI Code)
public void isThreatening (ThreatLevel playerThreatLevel){
if(playerThreatLevel >= (2 * selfThreatLevel){
Flee;
}
if(playerTheatLevel < (2 * selfThreatLevel) && >= (1.5 * selfThreatLevel)){
Be cautious;
}
if(playerTheatLevel < (1.5 * selfThreatLevel) && >= selfThreatLevel){
Attack from Range;
}
if(playerThreatLevel < selfThreatLevel){
Attack up close;
}
}

This code shows how AIs will react to a player's threat level. The AI's threat level will be
calculated similar to the player's. And when the AI see's the player, they will then check the player's
Threat Level vs it's own and act accordingly. This gives the player a sense of power when facing lower
level enemies and a sense of challenge when an AI charges the player showing that they are of similar
fighting levels.

Você também pode gostar