AI Modding - Tips and tricks

***Click here to return to the AI Editor main page.***

## Things Every AI Needs

### Class Behaviour Trees

In-game AI's use behaviour trees named after their classes. These add functionality to the bots that would be expected in-game, such as health upgrades. Without a class behaviour tree, an AI will not function properly in-game. In order to load a class behaviour tree, add an executeBehaviourTree block with "their class" as the argument to fileName.

### GeneralAI

Every AI needs a behavior tree called a GeneralAI. GeneralAI's are shared logic that finds it's way into every bot. It handles things such as finding where to go, pushing, and chasing. Without a GeneralAI, your AI will do nothing.

There are many different GeneralAI's used in AI's. This is because bot makers like to modify GeneralAI with their own tweaks. However, it is generally accepted that a bot should use VeankoAI, or some derivative of it. To use VeankoAI, add an executeBehaviourTree block with "VeankoAI" as the argument to fileName.

### Movement Logic

AI's intended for the game need to be able to move. Movement logic is something you need to create yourself. While many AI's have some extra features in their movement logic, every one follows the same general formula. First, you need to create a MoveAwayFromTarget block, which tells bots how to move away from their targets. Secondly, you need a MoveTowardsTarget block, which tells bots how to move towards their targets. Finally, AI's need a "Handle Movement" block, which describes how to actually move. To learn how to use these, it is best to look at AI's in your "ExampleAIs" folder.

Movement logic also uses a few bools to dictate how bots should move every tick. These are then interpreted by movement logic to translate into actual movement. Most of them are reset to "no" after every tick.

* MoveAwayFromTarget - Interpreted by the MoveAwayFromTarget block, which sets bools for moving away from a selected target.
* MoveTowardsTarget - Interpreted by the MoveTowardsTarget block, which sets bools for moving towards a selected target.
* float - Typically not necessary, but used by some AI's in more advanced logic. This tells AI's to float in air by jumping multiple times.
* CantMove - Tells bots not to move. This is not reset every tick.

* DontMove - Tells bots not to move, but still allows jumping.
* DownJump - Jump under a platform.
* jump
* GoBack
* GoForward
* GoDown
* GoUp

### Skill Logic

To create a skill logic, first think about what kind of skills your character has. Then think about what situations you use them, and how.

Skills are used with the mouse. To make the bot use a skill you have to use pressButton, and the arguments we're going to need are:

* FACE\_LEFT (left click)
* FACE\_RIGHT (right click)
* FACE\_TOP (middle click)

The durations of these button presses are typically 0.1, but could be anything, depending on how long you want the bot to hold down the button.

Here's how a simple skill-logic could look:

When using VeankoAI, it is a good idea to use a getBoolEquals block, as shown in the picture. This does, so when the bot is on lower difficulties, it will only use skills after a specific amount of times, to make it easier.

Then we use hasTarget to check whether we have a target or not. If we do, aim at him. If target is close enough, the AI will proceed to press the left mouse button.

## Multi-Target

When making bots, it is sometimes helpful to be able to keep track of multiple enemies in a single tick. A toolkit called Multi-Target makes it possible to do exactly that by allowing bots to revert their targets. Using Multi-Target is simple. To remember a target, execute "Mod\_RememberTarget." To revert to your last remembered target, execute "Mod\_RevertTarget." The most common method of using Multi-Target is to execute "Mod\_RevertTarget" at the very beginning of a tick (the first block under "root") and "Mod\_RememberTarget" after executing your GeneralAI of choice. Then, you can switch targets at any point during a tick and your new target will be reverted in time for the next tick.

## How to Check if you are Targeting a Character-Creep

In some gamemodes, most notably bot tournaments, players will be spawned by a spawner bot. These are called creeps instead of players in the Awesomenauts code, so it is often necessary to check if the creep you are targeting is actually a player. To do so, you can execute this toolkit before your check. It will set a bool called "TargetCreepIsPlayer" to true if your bot is targeting a player, and false if it is not.

## How to Fix Getting Stuck on the Ground

Some bots will get stuck on the ground during play and be unable to jump to their next waypoint. This is most likely because they are actually holding down the jump button. To fix this have the bot press FACE\_DOWN for 0 seconds if it is on the ground and is pressing FACE\_DOWN. Pressing a button for 0 seconds actually releases it, so the bot can continue to jump. Additionally, you should place a timer for 0.59 seconds with "execute first time" set to yes before any code that makes the bot jump. Your jumping code should be an "else" condition to this timer. This can be longer or shorter for longer or shorter jumps, but is a good guideline.

## Video Tutorials

Awesomenauts AI Tutorial - The Basics

Awesomenauts AI Tutorial - A Basic Bot