AI

From OniGalore
Jump to navigation Jump to search

An action game like Oni needs artificial intelligence-driven characters ("AIs" or "bots") and some sort of interaction amongst these characters and between them and the world. The goal is to make an AI act at least a bit like a human being. That means giving the AI abilities such as moving in the game world believably, and seeing, hearing, and reacting to events in the game world. Different games deal with these problems in various ways, but in this article, we will take a look at Oni and its AI.

This page serves two purposes: to give an overview of Oni's AI and to help modders with AI tweaking.

Pathfinding and movement

Example of a pathfinding grid.
An example of a pathfinding grid.
Example of an A*.
An example of the A* algorithm's work: nodes chosen as a path for AI are highlighted.

Oni has two ways to make an AI move in a game world - pathfinding, and what could be called vector-based.

Pathfinding is used when AI-driven character needs to travel from one place to another. Examples of pathfinding movement are:

  • patrol paths - AI-driven character moves in a pre-designed fashion (see PATR)
  • alarm running - AI character is requested to go to given console and use it, see section Alarm behavior
  • pursuit of target - AI character loses direct sight of the enemy, see section Pursuit
  • running to weapons in order to pick them up, see Extra combat behaviors
Pathfinding utilizes an A* (A-star) algorithm to design routes for AI within the game world.
Human players see walls and obstacles placed between their current location and their desired location, thus they can plan their route thanks to the best computer so far known to man -- the human brain. The AI, on the other hand, has to be told where it can go and where it cannot (a wall, a pit, an obstacle, etc.). Since the A* is a chart-searching algorithm, there is a need to have some sort of chart, conveniently mapping the environment for AI purposes. And that is a pathfinding grid, which can be seen in-game by entering ai2_showgrids = 1 (see picture on right).
If an AI has to travel through the level by pathfinding, then a "mark" is set at the final destination and the "chart" mentioned above is consulted to get the shortest available route. After this process, the AI is continually fed with "traversal nodes" -- temporary marks placed in the part of the pathfinding grid which the AI is currently running through. An AI will simply run directly towards each mark, so when an AI needs to turn a corner, a number of these nodes have to be generated in order to make the AI run around the corner.
Pathfinding grids are tied to AKVAs and are loaded into memory only for the period of time that they serve some purpose (i.e., when the character is inside the AKVA volume). More detailed info about various types of pathfinding grid tiles and their effects on pathfinding can be found here.
There was a short-lived modding initiative to alter pathfinding grids manually, but it failed due to the extreme amount of labor required. These days, OniSplit can import levels and generate pathfinding grids.


Modding hints: if an AI has to turn a sharp corner, the pathfinding still picks the shortest route possible. This usually results in the AI having problems turning corners at full running/sprinting speed -- the AI stops at the corner, turns, runs past the corner, turns again to finish the path, and continues on its way. This is caused by the limited rotation speed assigned to the character in his ONCC.
In an ONCC XML file there is a <RotationSpeed> under <AIConstants>. The default is 1, but 1.5 works way better without causing any visible negative influence on the game. A rotation speed of 2.0 is the maximum recommended because the pathfinding in the game is designed for a speed of 1.0, so with a much higher rotation rate comes the paradox that new problems in pathfinding may appear, instead of issues being erased (mainly the AI colliding with obstacles).


Vector-based movement is used when an AI-driven character:

  • enters close combat state and begins to use melee
  • is dodging gunfire, be it firing spreads or projectiles
  • is asked to run away from an enemy by a special setting in their CMBT profile
In this mode, an AI is not given an exact destination. Instead it is given a "desire" to go in some direction. This mode still uses the pathfinding grid, however in a bit of a different way than pathfinding does, so glitches occur, mainly unexpected collisions and ignored tiles (e.g., an AI runs off a ledge and falls to its death).


Unexpected Collision movement happens when an AI runs on its own towards some destination and suddenly hits an obstacle. Ideally that should never happen, as the pathfinding grid is designed to prevent it, but still... when a collision happens, the game decides what to do according to which method is being used to move the character:

  • Pathfinding: the game makes the AI take a few steps back, rotate a bit, and lets the AI continue its journey. There is a limit to how many unexpected collisions an AI can undergo before it gives up on its destination as unreachable.
  • Vector-based: according to the angle at which the AI is facing the obstacle, the game decides either to let the character slide along the obstacle or to stop the character completely until the angle of the AI's vector of movement changes.

Vision and hearing

Visualization of vision fields.
An example of a blue Striker's central and peripheral vision.
Visualization of sound spheres.
Three examples of sound spheres.

When emulating humans with AI, senses have to be taken into an account: sight, hearing, taste, smell, touch. Unfortunately, Oni emulates only sight and hearing.

Sight is important. Without it, the only option for AI to recognize an enemy would be getting attacked by the enemy first. Unlike the majority of action games, Oni AIs have two kinds of vision:

  • Central: an enemy seen by central vision will be recognized and attacked
  • Peripheral: an enemy seen by peripheral vision will raise the AI's alert level to low and the AI will go into pursuit of the enemy; see Pursuit section
Modding hints: the parameters of the vision fields are stored in ONCC, under <VisionConstants>. The central vision field distance has to be greater than the peripheral vision field distance, otherwise peripheral vision detection will somehow be broken (it will not detect). Since peripheral vision makes the AI pursue the enemy but not attack it, it can be set quite large in order to surprise lousy stealth players. But be warned: nobody likes cheating AI ^_^.


Hearing is crucial in Oni. The majority of AI character interaction is done via the sound system. Oni recognizes these types of sound (colors in parentheses are used for sound visualization when ai2_showsounds is set to 1):

  • Unimportant (blue) - is ignored to some extent if alert level of AI is "lull", but after some period of time, the AI will register it.
  • Interesting (green) - raises alert level to "low"
  • Danger (yellow) - raises alert level to "medium"
  • Melee (orange) - raises alert level to "medium", but the AI reacts a bit differently than to a Danger sound
  • Gunfire (red) - raises alert level to "high"
For more info about AI alert levels, see section Reactions and awareness. These sound types are used by impact effects (ONIE), and a danger sound type can be set in a particle's as part of its "danger radius".
For a video illustration of AI hearing, see this video.
Modding hints: The sound system and ONIE are mighty tools if a modder knows how to use them. Even doors can have attached to them a sound sphere of one of the types listed above, so a modder can create doors which draw the attention (sound type Interesting) of nearby AIs when those doors are used.
Another example is a workaround for AIs to get alerted by dead bodies: set the death particle in the ONCC to emit a custom impact effect. That impact effect will have no sound or effect attached, but will be set to be heard by AIs as gunfire within a large radius (say, 200 units).

Reactions and awareness

In real life, each human being is unique in its reactions. But even then, reactions differ with mood; when calm or when nervous or when suspicious, a man does not always react the same way. And what about Oni?

In Oni, reaction to a stimulus is based on the type of stimulus (see previous section) and on the alert level of the AI. Oni AIs have these alert levels:

  • Lull
  • Low
  • Medium
  • High
  • Combat
The level of alert for an AI can be set via BSL using ai2_setalert. Alert levels play the role of "behavior modifier" in how an AI reacts to seeing or hearing allies and enemies. Alert levels can be increased in the following ways:
  • hearing a sound which raises alert level (for detailed info, read previous section)
  • a special rise from Lull to Low can come from an enemy being seen by peripheral vision or by an enemy causing too many Unimportant sounds
  • a special rise to Combat level will come from being hit by the enemy or by an alarm being triggered (see OBD:BINA/OBJC/CONS), or by the scripting functions ai2_tripalarm, ai2_makeaware or ai2_attack.
Alert level also affects the movement mode of AI-driven characters. There are six movement modes: "creep", "walk", "walk_noaim", "run", "run_noaim", and "by_alert_level". The "*_noaim" movement modes tell the AI that, if it is armed, it should walk or run with the gun in hand but not aim with it. Movement mode can be forced via the BSL command ai2_setmovementmode. Alert level affects movement mode only if movement mode is set as "by_alert_level". In that case:
  • Lull and Low alerts use "walk_noaim"
  • Medium, High and Combat use "run"
If a patrol path (PATR) is assigned to a character, it can force a Lull-alerted character to run with an aimed weapon. However, when the AI becomes aware of and starts its pursuit of an ally/enemy, the movement mode is then dictated by its alert level (if the movement mode is set as by_alert_level).
An alert level can be decreased via BSL's ai2_setalert or with the passage of time (the location of the timer settings is unknown, maybe hardcoded).


The next component of the AI's reaction logic is its awareness of the ally/enemy. Oni distinguishes between allies ("friendlythreat") and enemies ("hostilethreat"). Oni's AIs always know whether a disturbance was caused by an ally or enemy. That means that if player is playing as Konoko and shoots, alerting some Striker, the Striker knows which character (from CHAR) shot and which team the character belongs to, and reacts accordingly (but more about that later). Oni defines four levels of awareness:

friendlythreat
  • Definite: the AI is 100% sure where the ally is located and ignores him. Is achieved by seeing the ally with the central vision field, being hit by his gun by accident, or being told of the ally's presence by the BSL function ai2_makeaware, ai2_tripalarm or ai2_attack.
  • Strong: the AI has a strong awareness of an ally's presence, but cannot pinpoint the exact location of the ally. Is caused by all sound types, which are described in previous section. If the ally is outside the central vision field and <FriendlyThreatDefiniteTimer> runs out, the AI decreases its level of awareness from Definite to Strong.
  • Weak: the AI has a weak awareness of the ally's presence. It is caused either by seeing an ally with peripheral vision or by <FriendlyThreatStrongTimer> running out.
  • Forgotten: the AI encountered some ally, but over time forgot about its presence (<FriendlyThreatWeakTimer> ran out).
hostilethreat
  • Definite: the AI is 100% sure where the enemy is located, and will go attack her/him. Is achieved by seeing the enemy with its central vision field, being hit by her/him (or her/his gun), or being told of the enemy's presence by the BSL function ai2_makeaware, ai2_tripalarm or ai2_attack.
  • Strong: the AI has a strong awareness of an enemy's presence, but cannot pinpoint the exact location of the enemy. Is caused by all sound types, which are described in previous section. If enemy manages to out of an AI's central vision field and <HostileThreatDefiniteTimer> runs out, the AI decreases its level of awareness from Definite to Strong. If the AI is allowed to investigate, the corresponding pursuit behavior is executed (more about this later).
  • Weak: the AI has a weak awareness of an enemy's presence. It is caused either by seeing an enemy with peripheral vision or by <HostileThreatStrongTimer> running out. If the AI is allowed to investigate, the corresponding pursuit behavior is executed (more about this later)
  • Forgotten: the AI encountered an enemy, but over time forgot about its presence (<EnemyThreatWeakTimer> ran out).
When an AI character is freshly spawned, it does not have any record of contact with other characters (a tabula rasa). Through hearing and vision, an AI learns about the presence of other characters and reacts to them according to team affiliation, alert level, and awareness level. Even when an AI character ceases to be aware of an ally/enemy, it does not completely forget them. For example, the startle behavior when an AI sees an enemy is played only once for this particular enemy; it won't play the startle animation the next time it sees him, but will go directly to attacking him.
Friendly warning: the awareness level "Forgotten" IS NOT equivalent to the result of the ai2_forget command. "Ai2_forget" actually sets the AI's memory back to tabula rasa status.


Pursuit

Now that alert and awareness levels have been covered, let's take a look at pursuit behavior. Pursuit behavior in Oni emulates the situation when a person knows "somebody is here", but does not see anybody. In Oni there are following types of pursuit behavior:

  • None: No pursuit taking place
  • Forget: the AI drops to the Forgotten level of awareness of this enemy
  • GoTo: the AI moves to the source of the disturbance and performs 600 frames (10 seconds) of Look behavior
  • Wait: the AI simply stands and waits to see/hear something more
  • Look: the AI turns in place, looking all around
  • Move: unimplemented; probably was meant to be similar to Look, but with character randomly moving around
  • Hunt: unimplemented; probably was meant to make AI purposefully hunt around for the enemy
  • Glance: the AI does not rotate its whole body, but only turns its head

Plus there are three types of lost behavior (when an AI had definite contact with the enemy but the enemy managed to get away):

  • ReturnTo Job: the AI returns to its job
  • KeepLooking: the AI does not return to its job, and keeps using the last used pursuit behavior
  • FindAlarm: the AI tries to switch to alarm behavior (see section Alarm behavior); if it does not succeed, then it returns to its job.


In Oni, a character is spawned in the level from a character profile (a CHAR file). This CHAR profile contains links to:

  • ONCC file, for character class, eg. Konoko or Comguy_1
  • CMBT file, for the combat profile for this character
  • MELE file, for the melee profile for this character
  • PATR file (OPTIONAL), for the patrol path
  • NEUT file (OPTIONAL), for neutral behavior (e.g., a civilian giving the player a powerup)
Pursuit behavior is executed only within the Pursuit range, which is the parameter <PursuitDistance> in the CMBT profile attached to the AI. If anything suspicious happens outside of this range, the AI only looks in the direction of the disturbance for a short time, then ignores it and returns to its job.
Pursuit behavior greatly depends on the AI's level of alert. There are four parameters regarding alert levels in the CHAR profile:
  • Initial: the AI is spawned with the specified level of alert
  • Minimal: the minimum alert level this AI can have
  • JobStart: the alert level of the AI when it starts some job (typically a patrol)
  • Investigate: From the alert level specified here, and all greater alert levels, the AI will tend to pursue any suspicious sound it hears or any hostile peripheral contact it makes


Also in CHAR are five fields regarding pursuit behavior:
  • Lull/Low alert level and strong awareness behavior: in XML labeled as <StrongUnseen>
  • Lull/Low alert level and weak awareness behavior: in XML labeled as <WeakUnseen>
  • Medium/High/Combat alert level and strong awareness behavior: in XML labeled as <StrongSeen>
  • Medium/High/Combat alert level and weak awareness behavior: in XML labeled as <WeakSeen>
  • Lost (when an AI had a definite contact but lost it): in XML labeled as <Lost>


If an AI registers any sound or peripheral vision contact inside its pursuit range while its alert level is below the alert level set in its Investigate parameter, then this AI will only look in the direction of the disturbance for a short time, then ignore it and return to its job. However, if the alert level of the AI is high enough, the AI goes into pursuit mode. That means that the AI will get a strong awareness of the enemy (or only weak in the case of peripheral contact), go to the source of the disturbance (the center of the sound sphere in the case of a sound, or the spot where the enemy stood in the case of peripheral eye contact), and will perform the pursuit behavior Look for 10 seconds. After this initial Look mode expires, the AI will perform the pursuit behavior prescribed in its CHAR profile.
The length of each pursuit behavior's execution depends on the HostileThreat timers (ONCC file), as described in the section above.



Modding hints: Pursuit mode complications and weird glitches

Watch this YouTube video. Pursuit mode is quite buggy, so when setting pursuit behaviors, there are several important things a modder has to have in mind.
  • The pursuit distance parameter in CMBT is important in deciding whether the character should be more of a pursuer or more of a guard.
  • Within the pursuit distance, peripheral vision pursuit follows its own rules. When an AI sees an enemy with its peripheral vision, this AI always goes into weak awareness mode and either just glances in the direction of this enemy (alert level was below Investigate level) or moves to the spot and performs weak investigation pursuit behavior (alert level was at Investigate on higher).
  • Remember that there are TWO sets of pursuit behavior:
    • strong and weak pursuit for lull/low alert levels. In XML these are called <StrongUnseen> and <WeakUnseen>, however those names simply reflect how many changes were made to this part of the game.
    • strong and weak pursuit for medium/high/combat levels, in XML called <StrongSeen> and <WeakSeen>.
  • From all the available pursuit behaviors, only GoTo, Look, Glance, Forget and Wait can be effectively used as CHAR pursuit behavior parameters. Hunt and Move are not finished code-wise.
  • Remember that general pursuit behavior is simply glitched, and the parameters from CHAR are more often ignored than actually used. The glitchiness is somehow connected with vision. When AI vision is turned off via ai2_blind=1, pursuit mechanics work as they should. However, the moment that AIs are allowed to see, then when pursuit should be performed, it results in:
    • pursuit values from CHAR being ignored if pursuit mode was called while the character was idle or moving along a patrol path. The AI character performs basic GoTo + timer-based Look for the whole period of pursuit behavior, for both strong and weak awareness. Looks so-so but definitely is a glitch.
    • one GoTo + timer based Look being called, but the timer for Look fails to decrement, so the AI simply stands and stares forever. This happens when pursuit mode is called while an AI stands at a job location on a patrol path. And, well... it looks really bad.
    • correct behavior roughly 10% of the time. It is quite random, but it looks like the AI has to be somehow disturbed while going for the source of a previous disturbance. And then Oni writes to the developer console "pursuit mode Hunt not yet implemented" ^_^.
  • The best way how to deal with the pursuit/vision issue is to either ignore it (so the character often gets glitched) or use a BSL script to create a small looping function where ai2_blind is set to 1 for at least one second (60 frames), then set to 0 again. It can cause funny moments of an AI completely ignoring an enemy right in front of it, but it silently fixes these pursuit problems.


Alarm behavior

CONTROL CONSOLE.png
ALARM CONSOLE.png
DATA CONSOLE.png
Control Alarm Data

In order to make the AI look more human, it is a good idea to grant it the ability to interact with the world the same way that the player does. In Oni, for example, that means giving the AI the ability to use consoles.

Watch this YouTube video.
BSL scripting provides a command to make an AI go and use a console: ai2_doalarm. This way, an AI can be told to use any console. But there is a method to make an AI use a console completely on it own.
In order to utilize this mechanic, there is a need for a console which has the ALARM CONSOLE flag set (see OBD:BINA/OBJC/CONS). In XML this flag is called IsAlarm. Such a console then can be used by AI characters without scripting.
Next, there are Alarm parameters in CMBT profiles which define an AI's alarm behavior:
  • Search distance: a radius around the AI where the engine checks for any console with the ALARM CONSOLE flag. In XML it is named <SearchDistance>.
  • Ignore distance: a radius around the AI where this AI character (which is currently executing alarm behavior) acknowledges enemies. Enemies outside of this radius are ignored by the AI character. In XML it is named <EnemyIgnoreDistance>.
  • Attack distance: a range within which the AI (which is currently executing alarm behavior) will temporarily stop its run for the console and attack enemies if the AI sees them with its central vision field. In XML it is named <EnemyAttackDistance>.
  • Damage threshold: The time interval for which an AI stays aware of an enemy who attacked it. If this enemy enters the Attack distance, the AI temporarily stops its run for alarm and immediately attacks this enemy (it does not have to see him with central vision field). In XML it is named <DamageThreshold>.
  • Fight timer: The number of frames for which the AI should fight with the enemy before it attempts to resume its run for the alarm. In XML it is called <FightTimer>.


So the settings for alarm-running behavior are set; now how to trip it? There are three ways to make a character run and use a console without BSL (but the console must have the ALARM CONSOLE flag set and must lie within Search distance):
  • using CMBT profile: Set the no-gun behavior to "Run For Alarm" (in XML, use the string "RunForAlarm" inside <NoGunBehavior>). By setting this parameter, an AI will attempt to run and use a console when it does not have a loaded weapon or any spare clips in its inventory. If there is no alarm console nearby, the AI will switch to Melee.
  • also in CMBT: The Behaviors (Long, Medium, Short, MediumRetreat, LongRetreat) can be set to "Run for Alarm". DO NOT confuse this with the "Run For Alarm" no-gun behavior! This behavior is never used in retail Oni, the reason probably being that if there is no useable console within Alarm search distance radius, then the AI simply stands and stares even when an enemy is visible within its central vision field.
  • In CHAR: Use the "Lost" behavior "FindAlarm". When an AI makes definite contact with an enemy and then the enemy manages to escape, the AI executes this "Lost" behavior (see Pursuit of enemy section). This behavior is typically set as ReturnToJob, but FindAlarm works well with no known issues. If an alarm console is not found within Search distance, the AI simply returns to its job.


A couple of notes regarding AIs:
  • in order to register an enemy and attack her/him pre-emptively, the AI must have the "HostileThreatDefinite" timer in its ONCC file set to some value over 60 (Oni internal clock runs at 60 frames per second).
  • The no-gun behavior "Run For Alarm" can get glitchy. Say that "Alarm enemy attack distance" is set to 100; now when an AI runs for an alarm and an enemy attacks it, then if in the AI's CMBT profile the melee override is not set to a range of at least 100 (via melee override or by having "Melee" set in its corresponding combat ranges, see section Basic combat behaviors), chances are that the AI will get stuck in a loop trying to reach both the enemy and the console at the same time.
  • A similar issue can happen with the combat behavior "Run For Alarm" as well, but this time problems arise when this combat behavior "Run For Alarm" is set as the Short-range behavior.
A couple of notes regarding the target console:
  • It must be in "activated" mode. If the console is in a deactivated or "used" mode, the alarm behavior will not be executed.
  • It must be directly accessible. Oni's AI cannot use consoles in order to open up a path to get to the point of interest (a target console in this case). But the target console can be across the whole level as long as it is not behind any locked doors.


As already mentioned, Alarm behavior can be tripped by the BSL command "ai2_doalarm". In that case, alarm behavior is executed but this time the console is being set by a command instead of being looked for within the Search distance. Also, with "ai2_doalarm" the AI can be made to use any console, not just those with the ALARM CONSOLE flag.


Modding hints: the ability of the AI to use consoles is an excellent tool for increasing the challenge.

  • Beware of setting the "Run For Alarm" combat behavior as the close-range one. Such a setup causes glitches.
  • On the other hand, "Run For Alarm" can be deliberately used to add an element of surprise to fights. In the CMBT profile, set "Run For Alarm" as either the Medium or MediumRetreat behavior, then shorten the interval between the <MediumRange> and <ShortRange> values (for example, set "Medium Range" to 60 and "Short Range" to 59). Thanks to this setup, an AI can attempt to find an alarm console while still being capable of fighting when no alarm is nearby.
  • In BSL, a modder can easily determine if a console was used by the player or an AI thanks to the chr_is_player function. All that's required is a BSL function being triggered when the console is used. Here is an example where a console triggers a function called "console1_used":
func void console1_used(string ai_name)
{
  if (chr_is_player(ai_name))
  {
    *Some code in case player used the console*
  }
  else
  {
    *Some code in case AI used the console*
  }
}
  • Another way of using alarm mechanics is to create a feeling of cooperation -- in order for the player to achieve something, an AI-driven sidekick must use a console.
  • In extreme cases, an AI can be even made to move through the level on it own, from one console to another. That can be used to create "chase" missions -- an AI wants to activate a certain number of consoles, while the player is required to stop it from doing so. Thanks to Alarm behaviors, the task of tripping consoles can be fully completed by the AI, no scripting needed. Such a setup is on the one hand prone to possible AI glitches, but on the other hand can add an element of randomness and increase replayability. A demonstration of alarm behavior being used by an AI to complete all of Chapter 1 can be found HERE.

Basic combat behaviors

Example of combat ranges.
Combat ranges of an AI character.

Of course, an action game like Oni is not complete without guns blazing and fists flying through the air. But combat in real life is usually very fickle and everything has to be considered. How can Oni's AI possibly deal with such a complex task?

An AI in Oni has to have a definite awareness of the enemy in order to actively attack him. The alert level of an AI when in combat mode is Combat (duh). Definite awareness can be achieved by these ways:
  • The enemy is seen in this AI's central vision field.
  • The AI is made to attack the enemy by the BSL function ai2_attack.
  • The AI is hurt by the enemy, be it melee or gun damage.

Once combat mode is entered, then as long as the HostileThreatDefinite timer for this enemy does not reach zero, an AI will always know the exact location of this enemy and will attempt to attack it. The moment HostileThreatDefinite timer is depleted, the AI loses the privilege of knowing the enemy's exact location, its awareness decreases from definite to strong, and the AI either switches from combat mode to pursuit mode with this enemy (see section Pursuit of enemy) or, in case of another enemy being present in its central vision field, picks this new enemy as a target to attack and keeps the old enemy in strong (and later weak, then forgotten) awareness.

Since the means of combat depends on the distance between the participants, some sort of spacing is needed. Oni uses a system of three radii around the AI, called combat ranges. See picture on right. The size of these radii can be set in the CMBT profile.
These ranges work as "triggers" to make the AI character execute various behaviors based on the enemy's proximity. Moreover, Oni can distinguish between an enemy entering a specified range or exiting a specified range. All the range possibilities in Oni which can be assigned some combat behavior are:
  • Short: enemy is close to the AI.
  • Medium: enemy is approaching the AI and crossed from Long Range into Medium Range.
  • Long: enemy is approaching the AI starting at the Long Range.
  • Medium Retreat: enemy is retreating from Short Range to Medium Range.
  • Long Retreat: enemy is retreating from Medium Range to Long Range.
Well, of course nothing is perfect, and in Oni there is a bit of an issue with proper switching between combat ranges, so Long and Medium ranges are used only once at the beginning of an enemy approach. Only Short, Medium Retreat and Long Retreat ranges are used on a regular basis in combat. Even when an enemy runs into Long Retreat and goes back to to Medium range, the engine does not switch the AI's behavior range to Medium, but (contrary to its name) to Medium Retreat.


OK, we have positioning down; now for the actual behaviors that an AI can be set to execute within these ranges. There are fourteen possible combat behaviors (in parentheses are the XML strings):

  • None (None): simply nothing.
  • Stare (Stare): the AI stands and stares; it does not even rotate to face the enemy.
  • Hold and fire (HoldAndFire): the AI stands still and fires a weapon. If this character does not have a weapon, then it switches to melee.
  • Firing charge (FiringCharge): the AI runs toward the enemy and fires a weapon. If this character does not have a weapon, then it switches to melee.
  • Melee (Melee): the AI always uses melee, even when it holds a loaded weapon.
  • Barabbas shoot (BarabasShoot): the AI stands still and fires a weapon with hardcoded three-second pauses between shots. If this character does not have a weapon, then it switches to melee. If this character meets certain conditions, it can start regenerating health. More detailed info about regeneration mechanics can be read here.
  • Barabbas advance (BarabasAdvance): the AI runs toward the enemy and fires a weapon using the secondary trigger (as if the player pressed right mouse button). If this character does not have a weapon, then it switches to melee. If this character meets certain conditions, it can start regenerating health. More detailed info about regeneration mechanics can be read here.
  • Barabbas melee (BarabasMelee): the AI uses melee, even with a loaded weapon in hand. If this character meets certain conditions, it can start regenerating health. More detailed info about regeneration mechanics can be read here.
  • Superninja fireball (SuperNinjaFireball): Mukade's long range behavior. With this behavior, an AI cannot shoot weapons and cannot use melee; it simply runs toward the enemy. However, if a weapon is in hand, the character can use melee (probably something from the weapon melee override). The AI is occasionally teleported behind the enemy (AnimType 222 - Teleport In) if the distance to the enemy is greater than 100 world units (however, something is screwy with this teleportation mechanic). Anyway, to add more to this behavior, the AI executes two special TRAMs (animations):
    • AnimType 224 - Ninja Fireball (Mukade's heat-seeking Devil Star); after using this, there is a 20-second cool-down before this can be used again.
    • AnimType 225 - Ninja Invisible (grants a 10-second cloak); after using this, there is a 20-second cool-down before this can be used again.
IMPORTANT There is an annoying problem with this behavior, which was coded with the Rooftops boss fight in mind. When it is called, it checks the character's position height-wise from the origin of the game world (coordinates {0, 0, 0}) and if the height is below 550, this character is automatically moved to height 550 (which in almost all cases means death by falling).
  • Superninja advance (SuperNinjaAdvance) - Mukade's medium range behavior. With this behavior, an AI cannot shoot weapons and cannot use melee; it simply runs toward the enemy. However, if a weapon is in hand, the character can use melee (probably something from the weapon melee override). This behavior also allows the use of AnimType 225 - Ninja Invisible. In order to be able to use this ability, the AI has to be at least 50 (or 40?) world units away from its enemy. The cool-down for this special technique is 20 seconds. Again, the annoying "over 550" height check is present.
  • Superninja melee (SuperNinjaMelee): Mukade's short range behavior. With this behavior, the AI cannot shoot weapons, but can use melee. This behavior allows the use of AnimType 225 - Ninja Invisible. In order to be able to use this ability, the AI has to be at least 50 (or 40?) world units away from its enemy. The cool-down for this special technique is 20 seconds. This behavior also grants the ability to teleport away from the enemy to a certain distance (around 100 world units) if any one of these conditions is met:
    • About 35 points of damage dealt to this character in a short time (exact amount of damage and exact timing not known).
    • This character get thrown.
Again, the annoying "over 550" height check is present.
  • Run for alarm (RunForAlarm): see section Alarm behavior.
  • Mutant Muro melee (MutantMuroMelee): the AI is only allowed to melee, not fire weapons. This behavior places the Daodan aura on the character irrespective of his/her HP as long as the character has <HasDaodanPowers> set to 1 in their ONCC. This aura effect does not grant the damage overpower attribute that Konoko has when she overheals. If the ONCC has both <HasDaodanPowers> and <HasSuperShield> set to 1, the chenille mode called by this behavior grants a supershield.
The supershield lasts forever if it is not terminated either via BSL or by the AI performing a TRAM which has a DisableShield flag. After a DisableShield move removes the supershield there is a 10 second interval and then it is turned back on. Another specialty of this behavior is an automatic backward-evasion move when about 35 points of damage or a throw are inflicted on the AI. The supershield is turned off if this AI switches to some other combat behavior because the enemy moved to another combat range.
  • Mutant Muro thunderbolt (MuroThunderbolt): Upon initial contact, the AI turns on chenille mode and runs toward the enemy. If chenille mode is turned off then, until definite awareness of the enemy is lost, this behavior will not cast chenille mode again. This behavior also allows the AI to use a special long range attack: the character turns off chenille, goes into AnimState 69 - Thunderbolt, and loops a special TRAM animation of AnimState 69 - Thunderbolt and AnimType 231 - Muro_Thunderbolt. That lasts for 10 seconds. Then the AI stops the animation for 5 seconds and runs toward the enemy. If, after those 5 seconds, the AI is still executing Mutant Muro thunderbolt behavior, the AI resumes the looping TRAM between AnimType 231 and 69.
This behavior's special looping animation continues even when an enemy enters some another combat range, with the exception of Short range. If the enemy enters Short range while the looped animation is running, the loop is forced to stop and the AI starts using Short range behavior.



Modding hints: Combat behaviors can have a severe positive or negative impact on AI performance in a fight.

  • Remember: due to a glitch, the crucial behaviors for combat are Short, MediumRetreat and LongRetreat. Long and Medium are used only at the beginning of an encounter.
  • In general, use common sense. There is little use in setting Firing Charge as the Short range behavior.
  • Barabbas Shoot and Barabbas Melee behaviors have access to a healing ability which can be a great asset for introducing mutants or stronger enemy units. However, remember that Barabbas Shoot limits rate of fire to one shot per three seconds.
  • Barabbas Advance is the only behavior which allows an AI to fire a weapon in its secondary fire mode. However the behavior is quite glitchy (the AI often looks away and fires stray shots). Still, with the proper gun and proper setup it can be useable for boss fights.
  • Superninja's behaviors sound excellent for cunning enemy units, however the annoying check for a character's minimum allowed height from the world origin, and subsequent forced re-positioning, severely impact these behaviors' usefulness. With a level which is deliberately raised to the correct height, the behavior will not cause random AI character re-positioning. Then it can be used to its fullest.
One other important thing about these behaviors: if the AI does not have required the TRAMs in its TRAC, the AI can get stuck if it uses these behaviors.
  • If there is no console with the ALARM CONSOLE flag within the Alarm search distance, then the behavior "Run For Alarm" will make an AI just stand and stare. Choose this behavior with caution, and consider using a workaround where Medium and Short combat ranges have very close radii, with Run For Alarm being the MediumRetreat behavior, so that the Run For Alarm behavior is executed only for a brief amount of time as the AI almost immediately switches to LongRetreat. Even one frame is enough, because if an alarm is found, the AI is requested to perform an alarm run which can override combat (see section Alarm behavior for more info).
  • MutantMuro melee behavior can be used to create tricky foes which have to be fought from a distance because if the player comes up close then the AI will turn on its (super)shield and won't put it away (by providing no TRAM with the DisableShield flag). That would make the player put some distance between him and the AI in order to make it disable the shield.
  • MutantMuro thunderbolt should NEVER be assigned as the Short range behavior, as that will negatively affect its special attack. Set it as LongRetreat or MediumRetreat. This kind of behavior (with proper TRAMs) can be used to create foes who will perform a special long range attack if the player tries to keep his distance. This ranged attack does not have to be the same as Muro's tractor thunderbolt. For example, an AI could be made to fire an aggressive energy-beam type of attack.



Extra combat behaviors

Combat ranges and various AI combat behaviors were discussed in the previous section. Even in terms of combat ranges, there are still other aspects of combat to cover: picking up weapons from the ground, melee overrides of weapons, behaviors if the character is unarmed, and, of course, firing weapons or using hand-to-hand combat.

"Melee override" (CMBT profile): Similar to the BSL command chr_dontaim, this behavior urges the AI to use its hand-to-hand animation variant (see TRAM) and to switch from some other behavior to melee combat. This field was probably added to deal with conflicts when multiple AI behaviors are applied on a character. The possible values are (XML strings in parentheses):

  • None (None): no override is used.
  • If Punched (IfPunched): melee override is applied when the AI is melee-attacked by its enemy. Does not work when the character is invincible.
  • Cancelled: unfinished feature; does nothing. There remains only the question of what it was meant to be....
  • Short (ShortRange): Melee override is applied when the enemy is within Short range.
  • Medium (MediumRange): Melee override is applied when the enemy is within Medium or Short range.
  • Always Melee (AlwaysMelee): Melee override is applied within all combat ranges.
This override can affect:
  • Alarm running: It is actually required if an alarm run is called via the no-gun alarm run behavior, otherwise glitches will appear.
  • Retreating behavior - When the no-gun behavior is set as "Retreat", an unarmed AI will try to run away from its enemy. However, if enemy meets the Melee override parameter (for example getting into the Short range while the melee override is set to ShortRange), then this AI stops running away and starts attacking the enemy.
  • Weapon firing: If the distance between the AI and its enemy is smaller than the minimum shooting distance, the AI tries to backpedal away from its enemy till the distance between characters is greater than the minimum shooting distance. However, this backpedal behavior can be overridden by the melee override if all conditions are met; the AI then starts using melee (even with a loaded weapon in hand) for at least 10 seconds (hardcoded timer). After ten seconds, the AI tries to resume its previous behavior. If the enemy is still too close, the melee override is immediately applied again.
  • Weapon pickup: if the AI is trying to pick up a weapon and an enemy crosses the range specified in MeleeOverride, then the weapon pickup behavior is overridden by melee.
  • Maybe some other aspects of AI behavior?


No-gun behavior (CMBT profile): This parameter tells the AI what kind of action it should take if it is unarmed or has an empty weapon and no spare clips. Possibilities are (XML strings in parentheses):

  • Melee (Melee): The AI attacks the enemy with hand-to-hand combat.
  • Retreat (Retreat): The AI runs away from its enemy (a bit glitchy, but works).
  • Run For Alarm (RunForAlarm): see section Alarm behavior. Reminder: this alarm-running behavior requires the melee override to be set in ShortRange, MediumRange or AlwaysMelee, otherwise the alarm behavior gets glitched and the AI gets stuck. If no alarm console is found within the alarm search distance, the AI resorts to melee.


Picture showing AI moving to a weapon.
AI moving towards a weapon.

Weapon pickup behavior (ONCC file): When in combat mode, an unarmed AI can be told to move to a loaded weapon and pick it up or to swap a held, empty gun for a loaded gun which is lying on the floor. Overall, AIs can only register pickup-able weapons up to a distance of 60 world units (hardcoded). In the ONCC file, these parameters can be set to alter the gun pickup behavior (XML tags in parentheses):

  • Chance for pickup (GoForGunChance): percent chance of AI deciding to go and pick up a weapon. It seems that the weapon closest to the AI character is always chosen to be picked up.
  • Running pickup (RunPickupChance): percent chance of AI picking up the weapon by performing an evasion (melee dodge) move.


Getting up after being knocked down (ONCC file): If an AI is knocked to the ground, it stays on the ground for a while (a simulation of being stunned), then gets up. In the ONCC file there are two parameters regarding getting up (XML tags in parentheses):

  • Knockdown minimum number of frames (DazedMinFrames): minimum number of frames that AI stays on the ground.
  • Knockdown maximum number of frames (DazedmaxFrames): maximum number of frames that AI stays on the ground.
If a knocked-down AI gets hit by melee, it gets up immediately after the hit. Being hit by weapons does not make AI character instantly get up. Standard get-ups are simple ones (the same result as if the knocked-down player hits a directional key). If the AI is in melee combat mode, its MELE profile has get-up attacks listed, and the enemy is within the required range, there is a chance that this AI will use a get-up attack instead of a simple get-up animation.


Making sure enemy is dead (ONCC file): Yes, even this is a part of Oni's combat AI.

When the enemy is defeated in hand-to-hand fighting, the AI stands over them for a while to decide if the enemy is dead. During this interval, the AI can utter a short victory speech if the corresponding sound slot in its ONCC is filled and the percent chance roll is successful. Also during the "check body" time interval, the AI can perform a taunt animation if that roll is successful. Here are listed all the related fields from the ONCC file (XML tags in parentheses):
  • Investigate body (InvestigateBodyDelay): Time period for which AI stands over its defeated enemy and stares at him/her.
  • Dead taunt chance (DeadTauntChance): Percent chance of performing a taunt animation.
  • Check body sound probability (CheckBodyProbability): Percent chance of playing a victory speech.
  • Check body sound (CheckBodySound): A link to an Oni ambient sound file (OSAm).


If the enemy is defeated by weapon, then the AI keeps shooting this dead enemy for some extra time to make sure the enemy is dead, then comes close to investigate the body. No taunts, no win phrases. The parameters of this behavior are:
  • Dead make sure (DeadMakeSureDelay): Time period for which the AI keeps shooting the dead enemy.
  • Investigate body (InvestigateBodyDelay): Same as the one listed above for melee.


Modding hints - the behaviors listed in this section can be combined to achieve quite impressive results.

  • Unfortunately, Oni does not provide any AI settings that deal with intelligent holstering and unholstering of weapons in their possession. Thus, melee overrides are the only way to make an armed AI somehow defend itself when the enemy gets too close to use its weapon.
Nevertheless, BSL does provide a function to make a character holster or unholster a weapon: chr_forceholster. In order to make a character holster a held weapon, this character has to be using a pistol or rifle animation variant (see TRAM). Since AI can use "walk_noaim" and "run_noaim" movement modes (which disable weapon variants, i.e., aiming with weapons), the weapon variant should be explicitly forced on via the BSL function chr_dontaim. Unholstering is easier: the character simply has to be be executing some aiming overlay-compatible animation at the moment when chr_forceholster is executed. That means standing, running, crouching, walking, and jumping are OK -- the function will succeed -- but attack animations or animations of getting hit are not OK and the function will fail.
  • IMPORTANT NOTE: The AI must be "active" all the time in order to perform BSL animation checks (chr_wait_animation/animtype/animstate checks). Remember that Oni was developed mostly in the '90s, so various tricks were used to save memory and enhance performance. One technique was to make unseen characters (behind a wall, closed doors, etc.) go into an "inactive" mode, which means they are only stored in RAM as a structure, but no physics, collision checks, or drawing functions are performed on them in order to save system resources (and yes, that means inactive characters can walk in mid-air and pass through walls). On the other hand, when a character is active, it is fully operational, with physics working, collisions being checked, and character being ready in graphics memory to be drawn any time. To make sure a character stays active requires either applying chr_lock_active to each AI, or (since computers have a lot more memory these days) simply setting chr_all_active to 1 to force all characters active.
Here is a simple example of a holster behavior scripted in BSL. A character is given a gun, then the weapon is holstered. When this AI notices an enemy and plays its startle animation, then an unholster is called for. This YouTube video shows the script in action.
 #Setup of AI - gets spawned, forced to be always active, weapon gets holstered.
 ai2_spawn A_t48
 chr_giveweapon A_t48 w1_tap
 chr_lock_active A_t48
 sleep 1
 chr_dontaim A_t48 0
 chr_forceholster A_t48 1
 sleep 1
 #Surprise behavior - unholster weapon when AI character is startled
 chr_wait_animtype (A_t48, Startle_Forward, Startle_Back, Startle_Left, Startle_Right)
 chr_forceholster A_t48 0
 #Aftermath - AI is usually walking only if it is not in combat mode, so let's use it as a trigger that weapon can be holstered.
 chr_wait_animtype (A_t48, Walk, Walk_Backwards)
 chr_dontaim A_t48 0
 chr_forceholster A_t48 1


  • A melee override can be used together with the "Go For Gun" behavior and a properly-set Short combat range to create AIs who go for a gun any time they have a chance, yet they are not allowing an enemy to land free hits in the process (if the enemy gets too close, the Short range melee override kicks in).
  • The no-gun behavior "Retreat" works in a rather simple manner: if unarmed, an AI is given a desire to run as far from the enemy as possible. This behavior can look a bit awkward, but is useful for making more life-like civilians. Combined with Melee override at "Short range" or "If punched", and a bit of BSL scripting to deliberately switch between "combatant" and "non-combatant", a modder can achieve impressive results without only a light load on the game engine. See this YouTube video.
  • Setting short get-up times is a good way to make an AI-driven character a formidable opponent in hand-to-hand combat. However, too-short get-up times can introduce problems. It is a good idea to experiment with get-up parameters till the character feels "natural".
  • Don't over-extend the "Check body" and "Dead make sure" timers. It looks silly, and on top of that it makes AIs easy targets for a rear throw.



Weapon combat behaviors

Back in 2001, Oni was highly praised for its mixture of shooting and hand-to-hand combat. Now what could the AI designers for Oni possibly do to make AI characters aim a gun, pull a trigger or avoid being hit by enemy gunfire? In this section, settings found in ONWC, together with ONCC and PAR3, will tell the story.

First let's look into the ONCC file. In an XML export of this file, under <AIConstants>, there's a tag named <Flags>. In the original binary data it is a bitset, meaning that more than one flag can be active at a time. The XML strings for the flags are:
  • noStartleAnim: disables the startle animation that can occur when the AI sees the enemy for the first time.
  • EnableMeleeDodge: enables firing spread/projectile dodging while the AI is in pathfinding mode or melee combat mode.
  • RunAwayDodge: enables firing spread/projectile dodging even while the AI itself is shooting a gun. The AI will stop shooting and try to move away from the danger area.
  • ShootDodge: enables firing spread/projectile dodging even while the AI itself is shooting a gun. The AI will keep shooting at its enemy while at the same time attempting to move away from the danger area.
  • NotUsed: Some characters have this bit turned on, however it looks like it does nothing.
Example of a firing spread.
Example of a firing spread.
Example of a particle with an AI projectile-dodge radius.
Example of a projectile with AI dodge radius (blue sphere).

Gunfire dodging mechanics. Gunfire dodging mechanics are quite an interesting part of Oni's AI system -- interesting because the retail version displays little to no such behavior, which is sad because it adds challenge to the gunplay. In order to make an AI perform gunfire dodging, this AI must be in combat mode with an enemy. Without combat mode and some enemy, AI character won't dodge. Additionally, an AI will only perform a dodge when the character senses one of these two things:

  • Firing spread. This can be seen by using ai2_showfiringspreads. The firing spread has the shape of a prism (its dimensions set in ONWC) which can be created when a weapon is fired. Not every gun has a firing spread, as for some guns a firing spread is useless (e.g. the Scram Cannon and Super Ball Gun). If an AI can dodge gunfire and intersects with a firing spread, this AI character starts its gunfire dodging behavior.
  • Projectile. The epic win of Oni modders. In the retail version of Oni, projectile dodging is basically broken due to a couple of bugs in the code. Since the engine hackers/modders fixed this issue, AIs can now dodge projectiles properly. Visualize this feature with ai2_showprojectiles. AIs will dodge particles themselves if they are in combat mode with some enemy and the particle (e.g. the Screaming Cell Cannon's projectile) has <AIDodgeRadius> set to a positive non-zero value.


AI parameters regarding gunfire dodging are set in ONCC (XML tags in parentheses):
  • Dodge reaction delay (DodgeReactFrames): a delay, in number of frames, which makes an AI wait a bit inside a danger zone before starting its reaction to the firing spread/projectile.
  • Dodge timescale (DodgeTimeScale): how long the AI's gunfire dodging behavior should last.
  • Dodge weight (DodgeWeightScale): how strong the desire (as a length of vector???) is for this AI character to dodge gunfire. The dodge weight can add together with other "vector" movements, and a sum of all vectors is the direction in which the AI will try to move.


Parameters of firing spread in ONWC are (XML tags in brakets):
  • Firing spread length (FireSpreadLength)
  • Firing spread width (FireSpreadWidth)
  • Firing spread skew (FireSpreadSkew)
The parameter for projectile dodging in the particle system (PAR3) is the AI dodge radius (AIDodgeRadius).


AI character's prowess with guns. Still in the ONCC, there are settings for how skillful this AI should be with each weapon in the game. Weapons are indexed (starting from zero) as follows:

  • 0: w0_sec - only Bungie West employees know what this weapon was supposed to be.
  • 1: w1_tap - TCTF Automatic Pistol
  • 2: w2_sap - Syndicate Automatic Pistol (the SMG)
  • 3: w3_phr - Plasma Rifle
  • 4: w4_psm - Phase Stream Projector
  • 5: w5_sbg - Super Ball Gun
  • 6: w6_vdg - Van de Graaff Gun
  • 7: w7_scc - Scram Cannon
  • 8: w8_mbo - Mercury Bow
  • 9: w9_scr - Screaming Cell Cannon
  • 10: w10_sni - Mukade's Devil Star (heat-seeking red ball) as an invisible weapon; probably a relic from game development.
  • 11: w10_ba1 - Barabas' gun, the Wave Motion Cannon.
  • 12: w11_ba2 - Barabas' gun; this one cannot be shot and is probably a development relic.


For each weapon, the ONCC defines these parameters (XML tag in parentheses):
  • Recoil compensation (RecoilCompensation): how much the AI character compensates for the recoil (vertical stray) of the weapon. Setting this to 0.0 means no compensation, and setting this to 1.0 means full compensation.
  • Best aiming angle (BestAimingAngle): in radians, but the question is whether it really affects aiming.
  • Shoot group error (ShotGroupError): the random deviation of the AI's aim from the target spot. Incorporated to simulate human inaccuracy. Can be set higher than 1.0.
  • Shoot group decay (ShotGroupDecay): the random deviation of the target spot itself. The target spot is naturally based on the enemy's position. Can be set higher than 1.0.
  • Shooting inaccuracy multiplier (ShootingInaccuracyMultiplier): also controls the degree that the AI's aim strays from the target, but it's not clear how much it really affects aiming.
  • Minimum shooting delay (MinShotDelay): minimum pause between reloading and resuming firing.
  • Maximum shooting delay (MaxShotDelay): maximum pause between reloading and resuming firing.



Targeting and prediction of the enemy's movement. Unlike the majority of other games, Oni's AI does not "cheat" by starting from 100% accuracy and then adding some degree of error (even though additive error is also present in Oni; see above). To the contrary, there's a bit of a problem making the AI a precise marksman ^_^. The AI is given input parameters such as the distance between itself and the enemy, the present velocity of its enemy (as a vector), and the velocity of their gun's projectile (as a number, not a vector). From this data, the AI logic computes a prediction of the enemy's location and the ideal aiming vector for hitting the enemy.

The ONCC parameters for targeting and prediction are (XML tags in parentheses):
  • Predict amount (PredictAmount): some sort of multiplier for prediction mechanics.
  • Predict position delay (PredictPositionDelay): in frames, the delay before prediction is applied, so that the AI always somewhat-outdated prediction.
  • Predict delay frames (PredictDelayFrames): in frames, the delay before prediction is computed. Must be set to at least 1.0.
  • Predict velocity frames (PredictVelocityFrames): this is a period of time in number of frames, but the meaning is not 100% clear. Maybe the enemy's velocity data is obtained and used for prediction algorithm during this period of time? Must be set to at least 2.0.
  • Predict trend frames (PredictTrendFrames): another period of time in number of frames that is not 100% clear. Maybe the distance ahead that extrapolation of the enemy's movement takes place? Must be set to at least 2.0.
The ONWC parameters for targeting and prediction are (XML tags in parentheses):
  • Prediction speed (PredictionSpeed): more precisely "projectile prediction speed". This value is taken by the prediction algorithm as the speed of a projectile fired with the corresponding fire mode of the ONWC weapon. Thus, when the actual PAR3 projectile's speed is changed, this prediction behavior produces misleading results (i.e., the AI is unable to hit moving targets).
  • Maximum inaccuracy angle (MaxInaccuracyAngle): maximum allowed deviation of aim from the enemy's pelvis while firing the weapon. If exceeded, the AI ceases fire and corrects its aiming, then resumes fire. The pelvis is considered to be the root point of the character, so without any modifications made to the targeting origin and vector (see ONWC), AIs always target the pelvis of the enemy.
  • Aim radius (AimRadius): no idea what this does.
  • Ballistic projectile speed (ProjectileSpeed): a separate prediction method can be used if the weapon fires gravity-affected projectiles (e.g. grenades). The AI then adjusts its aiming in order to hit the enemy using the ideal (parabolic) ballistic curve. This is a horizontal speed component.
  • Ballistic projectile gravity (ProjectileGravity): the vertical gravity component of the same projectile.
  • Targeting direction (Direction): a vector with three components (x, y, z) which gives the orientation of a firing spread. When set to wrong values, the firing spread will not cover the area where the weapon actually shoots (it can even point backwards ^_^). Friendly advice: do not alter unless needed.
  • Targeting origin (Origin): a vector with three components (x, y, z) which tells the AI where to fire in relation to the enemy's pelvis. When an armed AI is firing at an enemy, the AI searches for his/her pelvis (see TRIA), as the pelvis is the representation of the whole character in the AI system. The vector described in this parameter tells the AI how much and in which direction to deviate from the enemy's pelvis position.
So when the vector is set as (0, 0, -2), the AI will aim two world units above the enemy's pelvis position. Here is the effect of setting each component positive and then negative, from the shooter's point of view:
  • x - deviate forward/backward (does not have much of an effect when firing at someone on the same floor, as you would expect)
  • y - deviate right/left
  • z - deviate down/up (headshots, anyone?)


Miscellaneous ONWC AI setup - there are a few more parameters in ONWC which affect AI behavior with a weapon. They are (XML tags in parentheses):

  • Minimum shooting distance (MinShootingDistance): defines how close the enemy can be to the AI that is firing. If the enemy comes closer than this distance, the AI stops shooting and tends to move backward (a vector-based movement; see HERE) until the distance is again equal to or greater than the minimum shooting distance. Then the AI opens fire again. To witness this effect, watch an AI operating an SBG when its enemy is close to it.
IMPORTANT: for some unknown reason, the value from this field is divided by 2. So when set to 100, the AI starts backing up when its enemy is 50 units away.
  • Maximum shooting distance (MaxShootingDistance): The opposite of the parameter described above, this limits how far away an enemy can be before the AI stops shooting and starts moving closer. Watch an AI shooting with the SMG at a distant enemy.
  • Fight timer (FightTimer): a bit similar to thetimer-based BSL command chr_dontaim. Defines in frames for how long should AI switch from a weapon variant (shooting) to a melee variant (hand-to-hand combat) if this firing mode was used (don't forget, a weapon can have two firing modes) and certain conditions were met. See below for KnockdownSwitcher and StunSwitcher flag explanations.


  • The basic parameters of a weapon (pistol or rifle, type of ammunition, etc.) can be set using various flags in the ONWC (<Flags> in XML). These three flags from among those affect AI behavior (XML tags in parentheses):
    • NoHolster: apart from disabling the ability to holster the weapon, this flag also makes the AI ignore this weapon when lying on the ground. One exception is w10_ba1 when the AI has the Superammo flag (InfiniteAmmo in XML) set in its CHAR profile; then this AI character can pick up the WMC cannon. If an AI is given the weapon, it will still fire it.
    • Stun switcher (StunSwitcher): if the enemy is within an armed AI's shooting range and was knocked down, stunned or blown up, the AI switches to melee for a time specified in the weapon's Fight timer (see above). This flag was designed specially for w6_vdg.
    • Knockdown switcher (KnockdownSwitcher): similar to Stun switcher, but only a knockdown or a blownup makes the AI switch to melee. Tailored for w4_psm, probably to avoid AI abuse of an unfair advantage that the PSP grants (the enemy cannot get up as long as she/he is being shot).



Modding hints: Phew, what a long section. The described material has plenty of modding possibilities. Still, modders should be aware of a few things:

  • Don't set too high of a dodge vector (DodgeWeightScale), and don't overdo it with the dodge timer (DodgeTimeScale) -- the smallest possible value is 0.4; lower is not registered. The delay before gunfire dodging (DodgeReactFrames) should be minimal, otherwise it can happen that the AI won't start dodging till the shooter's weapon is empty.
As a side note, there is a glitch in gunfire dodging. It is not a coding bug, but a limitation of the simple vector-based movement. When the AI starts its gunfire dodge, it tries to get away from the source of danger (be it a firing spread or projectile). And because vector-based movement works as a "desire" to go in some direction, it can happen that the AI will express a "desire" to go into a wall. In such a case, the character stops until the desire to move into a wall stops -- in other words, until the enemy stops shooting at the AI. When an AI character is unarmed, it will try to switch between pathfinding movement (go towards the enemy and attacking him with melee) and vector-based projectile dodging movement, so it kind of looks like the AI is still trying to dodge the gunfire. If the weight of gunfire dodging is set to be smaller than the standard vector-based movement weight, then the AI does not even have to get stuck, as it will run in a zigzag pattern towards the armed enemy.
If the AI is armed with a loaded weapon, there is no point in the AI running towards enemy. That means if the AI starts dodging and meets a wall, this AI gets "stuck" until the enemy's gunfire stops. If this character has "ShootDodge" set in their ONCC, it will at least fire back at the enemy shooter. But in case the character has "RunAwayDodge" set, then it simply stands near the wall and stares and waits till the enemy's gunfire ceases.
From this explanation, it can be seen that the gunfire dodge parameters should be set to make the AI dodge, but to not make the dodge vector outweigh the vector for moving towards the enemy.
  • An AI's skills with weapons (in ONCC) can be used to create anything from sharpshooters to rookies who cannot hold a gun properly. For example, by setting "ShootGroupError" to 10.0 for w1_tap, we create a total amateur whose hand shakes all over the place when he fires the Campbell Equalizer. You can experiment with different settings in realtime using the ai2_skill* functions on the dev console line. See this video where ai2_skill_error is used to override a character's original grouping error setting with new values.
  • Unless really necessary, do NOT alter the ONCC prediction parameters. Bungie set them quite reasonably, and if they are messed with, the AI loses accurate predictive abilities.
  • In ONWC, Prediction speed is used for a calculation of the AI's aim. This speed should be exactly the same as the speed of this weapon's projectile. A projectile's velocity is usually set in the emitter of the projectile particle (PAR3). The separate values means that the predicted speed and actual speed of a weapon's projectile may differ, the most significant case being w3_phr (plasma balls accelerate rapidly).
If Prediction speed is set lower than the speed of a projectile, the AI will tend to shoot too far in front of an enemy moving left/right since it will assume the projectile is slower than it really is. On the other hand, setting this value higher means that the AI will shoot too directly at the moving enemy (probably missing), as the AI will think the projectiles are fast enough to hit the target.
  • Similar to Prediction speed, there are Ballistic projectile speed and Ballistic projectile gravity. When these two fields are set to non-zero values, the AI assumes that the projectiles are ballistic (e.g. grenades), and tries to shoot along a parabolic arc (the solution with shortest travel time is always chosen). In order to make AI successfully hit an enemy's pelvis, these values again must correspond with the particle's (PAR3) speed and gravity attraction, but they can be used for modding purposes as well. For example, if a projectile's gravity attraction is 0.5, but in the ONWC, the Ballistic projectile gravity is set as 0.3, the AI will shoot projectiles at the enemy's feet as it will assume that the gravity attraction of the projectile is lower and it does not have to aim so high in order to hit the pelvis (credit to Gumby). Remember: for the AI system, the pelvis is a representation of a whole character.
  • The targeting origin vector (ONWC) can be utilized to make the AI fire higher than the pelvis (with a negative "z" component), so the AI can score headshots. Currently, such a change does not have any purpose, as characters don't have separate damage coefficients for different body parts. But maybe in the future... or with Paradox's headshot mod... (see HERE for his material-dependent damage mod ideas).
  • One thing purposely left out in our main discussion of weapons is that there is an option for AIs to perform "startle" misses -- when startled, the AI can fire in some random direction. The parameters for this behavior are in ONCC and ONWC, but overall this feature is so minor that it does not need any special modding attention.
  • Remember: in the ONWC, Minimum shooting distance is divided by 2. The reason is unknown (maybe some bug in the code).
  • Through modification of Minimum shooting distance in conjunction with BSL scripting, a modder can achieve pseudo-intelligent holstering behavior. If an enemy gets too close, the AI will start backing away. Since this backing away motion is almost never used by an armed AI (it usually moves side-to-side), it can be watched for using the BSL function chr_wait_animation, and used as a trigger for scripting code to make the AI holster his weapon. To unholster, a different animation has to be watched for, such as a taunt animation. In MELE, a modder can set up a melee profile which makes the AI taunt only at a safe distance.
A drawback of this modification is that the enemy will not fire his weapon at point blank range, and also it limits the Melee override in CMBT to be only None or IfPunched; otherwise, instead of backing away, the AI goes directly into melee.



Melee combat behaviors

Ah yes. After all those OTHER things, we finally get to how the AI system handles the core gameplay feature of this game, hand-to-hand combat. First things first. As usual, a player can see her/his enemy trying to perform some move and react to it. An AI, however, cannot see a thing because it does not have eyes, nor a human brain. Thus the first question is, How does the AI learn about incoming attacks?

Melee zones around a character
A rough illustration of melee zones.
The answer lies within the TRAM files. Each animation which can hurt somebody should have "extents". Extents are invisible boundaries which tell the AI about the range of enemy attacks. There are two types, horizontal and vertical, but the more important thing AI-wise is that, without extents, attack TRAMs will not be registered by AI characters as attacks, so AI will not try to block or dodge them. As long as the attack has extents data, then the AI will have the needed knowledge of the path of the attacking character's body parts (see attack part of TRAM).
This info is used by the melee part of AI for defensive purposes (deciding what kind of evasive move to use, and whether to crouch or not) as well as for offensive purposes -- an AI will not execute an attack move unless it sees that the enemy falls within its attack move's extents.


Also, for hand-to-hand purposes, the engine recognizes roughly four zones around a character (see picture on right). These zones correspond to positioning moves, so when a melee technique has, for example, CloseBack, then the only time this melee technique is listed for possible execution is when the enemy is in back of the AI. In all other cases (enemy in the left, right or front zone), this technique is NOT listed for use. The exception is when a technique has the GenerousDir flag set; see below for more info.


Melee mode AI combat is handled via MELE profiles. A MELE profile is assigned to a spawnable character in its CHAR profile. When in melee mode, an AI uses vector-based movement. Unless otherwise specified, the AI is inclined to run towards its enemy.

A MELE profile always contains these parameters (XML tags in parentheses):
  • Character class (CharacterClass): link to an ONCC. The importance of this parameter not known, but maybe it is necessary in order to allow for some attacks to be performed (engine checks being performed through the ONCC and its TRAC).
  • Notice (Notice): percent chance that AI will notice an incoming attack. In retail profiles, it is always set to 100.
  • Dodge base (Base inside Dodge): percent chance that AI will try to use an evasion moves (if it has any in the evade section of its MELE profile) to avoid getting hurt.
  • Dodge extra (Extra inside Dodge): extra chance to dodge.
  • Dodge extra damage (ExtraDamageThreshold inside Dodge): amount of damage needed to activate the extra chance of dodging.
  • Single block skill (Single inside BlockSkill): percent chance of an attempt to block an incoming attack.
  • Group block skill (Group inside BlockSkill): percent chance of maybe of blocking more attackers???
  • Not blocked (NotBlocked): a multiplier which affects the weight of techniques which will not be blocked by the enemy under the current circumstances (such as a punch combo against an opponent who is running forward).
  • Must change stance (MustChangeStance): a multiplier which affects the weight of techniques which force the enemy to change stance (standing vs. crouching) in order to block them under the current circumstances (such as a leg sweep against a standing opponent).
  • Blocked but unblockable (BlockedButUnblockable): a multiplier which affects the weight of techniques that have the "unblockable" flag set in their attack part (see TRAM attack part settings).
  • Blocked but has stagger (BlockedButHasStagger): a multiplier which affects the weight of techniques that would make the enemy stagger if the enemy does block them, that is, they have the "stagger" flag set in their attack part (see TRAM attack part settings).
  • Blocked but has block stun (BlockedButHasBlockStun): a multiplier which affects the weight of techniques that would trap the enemy in a blocking animation for longer than 20 frames, that is, they have the "block stun" flag set in their attack part settings (see TRAM attack part settings).
  • Blocked (Blocked): a multiplier which affects the weight of techniques that will definitely be blocked by the enemy under the current circumstances and will not stagger or stun the enemy.
  • Throw Danger (ThrowDanger): something to do with throws, but only Bungie West knows the meaning of this field.
  • DazedMinFrames, DazedMaxFrames: These were documented by Neo, but the question is, Do these two parameters actually have any effect, since the get-up time is controlled from the ONCC?


Our basic melee setup is done. Now the profile branches into an attack part, an evade part, and a maneuver part. Each part has a certain number of "melee technique" slots. A melee technique is a set of one or more melee moves. A melee move is any single element of hand-to-hand combat -- an attack, a throw, a positioning command, or some maneuver. The maximum number of techniques in one melee profile is 32. If this limit is exceeded, Oni crashes. Let's take a detailed look at all three parts of the MELE profile:

  • Attack branch: techniques from this branch are executed when the AI is trying to attack and hurt its enemy. The attack branch contains not only attack techniques, but also maneuver techniques (more about this later).
  • Evade branch: techniques containing moves which are used to evade an attack -- escape moves (as when the player presses crouch + some directional key) and/or various jumps/slides. These techniques are picked only when an AI is reacting to an incoming attack.
  • Maneuver branch: techniques from this branch should be used by the AI to maneuver around, so as to not just move in a straight line towards the enemy, but also circle around him, retreat, or advance. Unfortunately, this branch is probably a development relic. The AI only starts performing techniques from this maneuver branch when the global BSL variable ai2_spacing_cookies it set to zero, but that means that the AI cannot execute attacks.
The idea was probably that when the AI had run out of attacks to execute (each attack "eats" a cookie), the AI would use the maneuver branch for a bit until it got a new cookie, and so on and so on. But somehow this setup was abandoned (the question is whether MELE was really planned that way ^_^ ), and techniques from this branch are de facto never used. This means that all maneuvering is done via the Attack branch.


Structure of a melee technique:

  • Name (for debugging purposes only)
  • Flags: the possibilities are:
  • Interruptible: this technique can "home in" on the enemy to some extent, and if the enemy gets out of its reach, the technique is ended prematurely.
  • GenerousDir: this technique is listed for possible execution even when the AI's facing does not match the position move of this technique (e.g. the technique uses CloseLeft but the enemy is directly in front). If the technique is used, the AI positions itself in order to perform the technique (in our example, the AI would turn his left side to the enemy and perform the technique).
  • Fearless: does this flag actually do something?
  • Weight: the basic weight of the technique. Techniques are chosen randomly, but with the "weight" of the technique taken into account. Techniques with higher "weight" are used more often than those with lower "weight".
Also, there are more factors which affect the final weight of the technique. The basic weight of the technique is, according to the combat situation (position of the enemy, effect of moves in the technique), multiplied by one of the MELE profile's multipliers (NotBlocked, BlockedButHasStagger, etc.), then it is also multiplied by some diminishing value which decreases the weight of the technique if it is used consecutively. And finally, the weight of the technique is multiplied by a special "orange tiles" multiplier, which weighs down techniques that would make the AI fall over an edge, that is, dive into a part of the pathfinding grid that would be visualized as an orange-tiled area.
The equation is PROBABLY very roughly something like this:
Final weight = basic weight * corresponding MELE profile setup multiplier * diminish multiplier * "orange tiles" multiplier
  • "Importance": documented by Neo, but does it have any effect?
  • RepeatDelay: in frames, how long should the technique be unavailable after its use (to avoid predictability).
  • Moves: the possible types of moves are:
  • Position: usually takes three parameters -- minimum distance, maximum distance, and tolerance range. The meaning of minimum/maximum distances is clear; the tolerance range specifies an extra distance (beyond the chosen TRAM's attack extents) over which the AI will chase the enemy till the enemy gets inside the extent range of the attack this AI wants to use.
Some positioning moves don't have any parameters (Crouch, StartToCrouch) and are used strictly for stance purposes -- to make the AI perform crouched or special attacks. Positioning moves are used to give the AI variety in their available attacks, as techniques are chosen based on the melee zone the enemy is in (see picture at the beginning of this section). HERE is a list of all available positioning moves in melee combat.
  • Attack: no parameter, just an attack action. HERE is a list of all available attack moves in melee combat.
An attack move can be the only move in a technique (no positioning move). If that is the case, then this technique is put into a list of possibly techniques only when its prerequisites (positioning and stance) are met via other means. For example, Kick_forward can be used without a Position move, but since a move is evaluated only when the AI sees an enemy within its extents, the AI will have to get into the correct position for the attack by some other means (maybe another melee technique), otherwise the technique with Kick_forward will be labeled as MISSBOUNDS.
  • Throw: no parameter, just a throw move. HERE is a list of all available throw moves in melee combat. As with an Attack, a Throw can be standalone, to be used under the circumstances described above.
  • Evade: no parameter, just an evasive action. HERE is a list of all available evasion moves in melee combat.
  • Maneuver: taking up to three parameters, these moves are used to make the AI move around (advance, retreat, circle left/right) or perform various movements (crouch, jump, taunt, use uncommon get-up moves etc.). HERE is a list of all available maneuver moves in melee combat. Almost all maneuver moves have a Duration (in seconds) as a first parameter.
Melee techniques can be a mixture of melee moves. The very first move (which should be positioning or maneuvering) is evaluated to make sure if the technique can be performed with the current positioning of the AI and its enemy. However, throws and maneuvers are checked as well even if they are not the first technique, so if a technique contains Throw_punch_behind, for example, it will be listed for use only if the AI is behind its enemy. Surprisingly enough, pairing Kick_forward and Kick_back makes the AI kick forward when the position is correct for a forward kick, and then kick backward even though there is nothing to hit ^_^. The same goes for other directional attacks.


Also, there is one special condition to executing melee techniques. When there is a ledge in a level, it is usually covered in pathfinding grid by a series of special tiles going from blue (border) to orange (danger). As mentioned earlier, the engine seems to check if an attack TRAM's extents run into an area of orange pathfinding tiles and, if so, it decreases the weight of techniques which would make the AI end up in an orange field (which would mean going over the edge). Techniques which utilize jump positioning moves are excluded from this weight decrease, so there is a very limited and random possibility for AIs to jump across gaps in order to reach the enemy.

The code behind all this must be pretty complex; hats off to the Oni developers who managed to pull this off.


Modding hints: Creating custom MELE profiles can be fun, but beware of a few pitfalls:

  • Positioning moves can be followed by some other positioning moves, but generally after a positioning move an attack or throw move is expected. If an attack or throw is not present, this melee technique will be labeled as NOATTACKNOTHROW and will be unused.
  • Jump positioning moves can be used to make the AI sometimes jump across gaps. As explained above, the presence of orange tiles nearby will up-weight jumping moves a lot. Just don't forget to follow up the jump positioning move with some jumping attack move.
  • Special attacks (e.g. Rising Fury, Devil Spin Kick) use the StartToCrouch positioning move as a starter.
  • Any combo technique (for example, a three-punch combo) without the Interruptible flag will make the AI too vulnerable.
  • Rear throw techniques and side attack techniques should have a high weight to ensure they will be chosen and used the moment there is a chance.
  • Set the distances in positioning moves reasonably so that the AI doesn't attempt to perform jumping or running attack moves at close distance.
  • Always try to utilize a given class' strength. The Fury is fast, so give weight to combos. The Tanker is slower, so give weight to throws and running attacks. The Ninja is a beast; set whatever you want and it will be annoying to deal with anyway.