Jump to content

AI Bots - Advanced 1


moonsense715

Recommended Posts

Author: moonsense715

Skill level: 3

 

AI_Tutorial.jpg
 

Welcome to the first chapter of the tutorials that will show you how to add and configure more sophisticated bots to your maps.

In this lesson, we will place a few very simple bots and give them objectives to do. They won't shoot regular base buildings or do anything too interesting for now.
Optionally, you can also learn how to fine tune objectives and bot behaviour.
 

- Wait, what are bots?!

Bots are computer controlled objects (characters, vehicles) that do a task given to them. They don't need an actual human player to control how they behave. The most typical bots in a lot of W3D games are the mobile resource collector vehicles (Ore Truck, Tiberium Harvester) and the static base defenses (turrets, pillboxes, obelisks, sam sites).

 

1. Setup bot presets

Start the Level Editor if you haven't already and open your project.
Make sure you have generated pathfinding!

Spoiler

If you haven't generated pathfinding yet, here's how to do it.

Place a Human Pathfind Generator somewhere in open terrain:
Pathfind1.jpg

Click Pathfinding -> Generate Sectors:
Pathfind2.jpg

This can take a long time depending on the map size, sit back or take a break until it finishes:
Pathfind3.jpg

Bots need this to "see" your map, without it they will keep getting stuck on obstacles like trees, walls, etc.
If you change the terrain or place new obstacles, you will need to re-generate it.


In the preset tree, go to Objects -> Soldier, and click on a soldier preset you would like to appear on your map as a bot.
Then, click Temp.
(Note: if you are making a .mix map for a game, always use Temp to add new presets. If you are editing a game core so the presets are available on every map in the game, use Add! In case you are creating a standalone .pkg map, you can use both.)

Give this new preset a name (for example MyAwesomeBot).


We will use a script to apply the AI. Switch to the Scripts tab.
Add the script MS_AI_Behaviour to the list and hit OK. Don't modify the parameters for now.

AIScript.jpg

Click OK again to finish your new bot preset.

Create another temp preset by doing the same steps again, but this time, pick a soldier preset from the other team, so they can fight eachother.
If you want to go a little further, pick 1-1 vehicle preset as well for both teams and do the same steps to have a few bot vehicle presets set up.

Now that you have the presets ready, let's place them. Click on each preset and hit Make. You can move them around after placing to change their position. I recommend you place the bots into their own bases, but at least keep the two teams away from eachother if there are no bases on your map.
PlacedBots.jpg

If you want the bots to respawn after dying, you'll need to create spawners. Please read the spawner tutorial here.
(You will need to place new spawners and delete the placed presets, since the spawners will create them dynamically.)

 

You're done setting up and placing your bots!
 

2. Add AI Objectives

Without objectives, bots will just wander around the position where they started and shoot enemies they see. You will want to give them objectives to run to and find, positions to defend, buildings or vehicles to attack. This is done by creating AI Objectives.

Alright, you have your bots sitting in their bases. If you export and play your map now, the bots will shoot enemies that get close to them, but they will not do anything specific otherwise. To change this, we will tell them to run into the enemy base!

First, let's create an objective for Team 1. For this tutorial, this is going to be the Allied team, while Team 0 is the Soviets.
On the preset list, scroll down to Simple and Temp it.
Give it a name, e.g. MarkerObjectiveAllied.
On the Physics Model tab, pick a w3d model's ModelName, e.g. o_davesarrow.w3d.

Go to the Settings tab, make sure IsEditorObject is ticked, so this model can only be seen in LevelEdit. 
Also make sure the object cannot die, set the Skin and Shield Type to Blamo (if there is no Blamo, pick one that is invulnerable to attacks).
SkinShield.jpgEditorObject.jpg

Switch to the Scripts tab and attach the script dp88_AI_Objective. This is the marker that tells bots "Come closer, your objective is here!"
The preset we are creating is the "host" of the objective script, we will place it somewhere on the level so bots know where the objective is. Note that this is not the target that they will shoot, just a go-to location. This particular objective will be permanent and will not change position during the game.

Now, set up the parameters like so:

  • Team: 1 (= Allies/GDI)
  • Type: 1 (= Offensive)
  • Range: 15
  • Priority_Soldier/Light_Vehicle/Heavy_Vehicle/Aircraft: 1 (set all of them to 1)

AIObjective.jpg

Place this marker in the Soviet/Nod base somewhere on open ground (not inside a building). Now the Allied bots will know where the Soviet base is, and they will keep running here.
AIObjectivePlaced.jpg

What about the Soviets, you might ask? Well, let's not let them down, and add an objective for them too.
Do the same steps you did for the Allied objective, but this time, make sure the Team parameter is 0 and that you place the object in the Allied base.

 

Good job! If you go ingame now, the bots will run to eachother's base and shoot enemy characters and vehicles.

 

3. Optional: Dynamic AI Objectives, Priorities

Static objectives, the ones we placed is one thing, but let's see what else we can do here.

In LevelEdit, place any vehicle object or vehicle spawner on your map, so that you can drive the vehicle ingame.
Now, double click to edit the vehicle object that you placed in the scene, or edit its preset in the preset tree (only if it's a Temp preset!).
Add the dp88_AI_Objective script for Team 1 on the Scripts tab with the same parameters as before, but change the Priority_Soldier parameter to 100.
Head ingame and test your map, play as Soviets (team 0). Enter the vehicle you edited and drive around ingame, somewhere away from your base. You will notice that the Allied soldier bots will run after your vehicle and find you no matter where you are (as long as you are within the pathfind grid).

Now you know how to tell bots to find a moving object. This can be very useful if you know what you want to do in your map/game. 
If there are multiple objectives for the same team on a map, the bots will consider 2 things:

  • What's the priority of the objective? If two objectives are roughly the same distance away, the higher priority one will be picked.
  • How far is it from their current location? If two objectives have the same priority, the one that's closer will be picked.

After analyzing, each bot will choose the optimal objective. For example, they will most likely pick an objective 10 meters away with priority 1 instead of another one 100 meters away with priority 2.

objective_choosing.png
If the priority calculation for a particular objective ends up being negative (e.g. priority too low or distance too high), it will be treated as a 0.0001 priority objective (so it's positive). Keep this in mind when setting priorities for multiple objectives, as they can end up being the same value.

Note: after a bot chooses an objective, it will not change it, not even if a higher priority one appears. It will keep its chosen objective as long as the script-wielding object is alive or until dp88_AI_Objective is removed from it by other scripts.

 

4. Optional: Bot Targeting Priorities

Remember in the first steps, when we attached the script MS_AI_Behaviour but did not touch the parameters? Let's look at them now.

The priority system was created by @danpaul88, and lets you tell your bots what to shoot, how to shoot them, and in case of multiple targets, which one to shoot at first. MS_AI_Behaviour implements this system.

Quote

The AI uses a priority based system to 'intelligently' pick targets based upon a range of criteria such as the type of target, how far away it is, if it's already taken damage and how valuable it is. All of these criteria can be fine tuned in the script parameters to give you a high degree of control over which of several targets an AI will choose to shoot at.

The full description of the parameter list is here:

  • Priority_Infantry: Base targetting priority for infantry targets, or 0 to ignore infantry
  • Weapon_Infantry: Weapon to use against infantry targets: 1 for primary fire, 2 for secondary fire
  • Splash_Infantry: Determines if we should try to damage infantry with splash instead of hitting them directly. This is useful for slow / inaccurate weapons which do splash damage: 1 to enable, 0 to disable
  • Priority_Light_Vehicle: Base targetting priority for light vehicle targets, or 0 to ignore light vehicles
  • Weapon_Light_Vehicle: Weapon to use against light vehicle targets: 1 for primary fire, 2 for secondary fire
  • Priority_Heavy_Vehicle: Base targetting priority for heavy vehicle targets, or 0 to ignore heavy vehicles
  • Weapon_Heavy_Vehicle: Weapon to use against heavy vehicle targets: 1 for primary fire, 2 for secondary fire
  • Priority_VTOL: Base targetting priority for flying targets, or 0 to ignore flying targets
  • Weapon_VTOL: Weapon to use against flying targets: 1 for primary fire, 2 for secondary fire
  • Priority_Building: Base targetting priority for building targets, or 0 to ignore building targets
  • Weapon_Building: Weapon to use against building targets: 1 for primary fire, 2 for secondary fire
  • Max_Attack_Range: Maximum distance at which the unit can engage enemies when using primary fire
  • Min_Attack_Range: Minimum distance at which the unit can engage enemies when using primary fire
  • Preferred_Attack_Range: Preferred minimal distance, the unit will try to move within this range when using primary fire
  • Max_Attack_Range_Secondary: Maximum distance at which the unit can engage enemies when using secondary fire
  • Min_Attack_Range_Secondary: Minimum distance at which the unit can engage enemies when using secondary fire
  • Preferred_Attack_Range_Secondary: Preferred minimal distance, the unit will try to move within this range when using secondary fire
  • Modifier_Distance: Priority modification to apply based on distance to target. Higher values will favour targets which are closer to the unit, good for less accurate weapons and slow vehicles
  • Modifier_Target_Damage: Priority modification to apply based on damage a target has already sustained. Higher values will favour targets which have already been damaged in combat, picking them off first
  • Modifier_Target_Value: Priority modification to apply based on the value of the target. Higher values will favour targets with a higher purchase cost, good for hard hitting weapons
  • DebugDeprecated: No longer in use
  • Detects_Stealth: Determine whether this unit can detect stealthed enemies or not: 1 to enable, 0 to disable
  • ObjectiveType: What type of objectives this unit will run for, valid values are 1 (Offensive), 2 (Defensive) or 3 (Engineering).

All non-flying vehicles are treated as light vehicle unless they have one of the marker scripts on them: 

  1. dp88_AI_Marker_HeavyVehicle - Bots will use the Heavy_Vehicle preferences against them
  2. dp88_AI_Marker_Building - Bots will use the Building preferences against them
  3. dp88_AI_Marker_Repairable - All bots except Engineering bot types will ignore them

 

It is important to know that NEGATIVE PRIORITY is usable for any target type. The more negative a type priority is, the more chance the bot will pick that as the target. When this happens, the bot will still shoot these targets, but they will keep running towards their objective and will not chase them.
Here's an example: Object A: priority = 1 and Object B: priority = -2 ---> object B will be shot and the bot will move towards its main objective. 
If a target type should not be targeted at all, then you should use 0 as the priority value.

priority.png

For practice, try configuring rifle soldiers so that they will prefer shooting soldiers even when vehicles are within their sight range.
Make tanks shoot other vehicles first and not chase soldiers (negative priority). Make them ignore aircraft.
Last, come up with something that makes sense for a unit. E.g. anti-tank infantry, anti-aircraft vehicles, etc. Play with the priority parameters until you are happy with your bot behaviours.

Please keep in mind that Objective Priorities and Target Priorities are completely separate things, even though both are affected by the Modifier_Distance parameter. Objective Priorities are for telling bots where to run when there are no targets around to chase, while Target Priorities are frequent calculations of enemies that the bot currently sees, and decides which ones to shoot/chase.

That's it for the first lesson, now you should have a basic knowledge of how the new bot system works.

Tut1_Finish.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...