top of page
  • Writer's pictureFelix Abbott

Influence Maps


I created a basic example of an influence map for my Advanced Game AI class. For my example, I made it so the user could place down and control a ship. They could also click on a cell which would then generate an enemy ship which has a "damage zone". The surrounding cells would then get a value based on their distance from the center cell. When the ship moved into a new cell it took damage equal to whatever the value of that cell was. So in other words, it's an example of using influence maps for AoE damage.

 

Grid Generator


Firstly is the generation of the grid.


width: Width of the grid

height: Height of the grid

gridArray: Creates an array of the grid that stores the value for each grid cell

cellSize: Size of each cell in the grid

textHolder: Object where all the UI text gets placed under (aka the parent)

gridObject: GameObject in charge of holding all the grid data


The gridObject has it's own script on it which is essentially the game manager. It generates the grid and is used to allow other scripts to access the grid data. It has a few extra values.


startValue: The initial value given to the starting cell

affectedZone: How wide the affected range from the start position is

affectedValue: How much each cell gets affected by

enemyShipPrefab: Prefab of the enemy ship

shipPrefab: Prefab of the ship the player controls

shipDown: Tracks whether or not there's a ship currently in the world, there can only be one ship at once so when it's true the player won't be able to place any more ships



 

Influence Map Calculations


Right clicking on the grid will place a ship at the corresponding cell, while left clicking will place an enemy ship with a "damage zone" starting from the cell the player clicked on.



The "damage zone" is calculated through the CalculateNeighborCells() function. The cell the player clicked on is stored and from there all the math is done in a for loop. It takes in how big the affected are should be, starts at X and then goes through all the Y values before adding to the X and repeating the process until all values have been accounted for. There's a few if statements inside the for loops. The first one checks if the cell is out of bounds of the array, in which case it'll get skipped. The following else if checks if the cell it's on is the starting (center) cell, in which case the value won't change from the default starting value.

The last else statement has another if/else statement. Firstly it checks if the value for the cell doesn't equal zero, in which case when doing the math it'll add the values rather than subtract since in this case two AoE zones are overlapping means there'd be more damage done to the player in that cell.



Example debug of the process of the ship taking damage based on the cell values


9 views0 comments

Recent Posts

See All
bottom of page