Tactics Movement Tutorial (Cont.) – AI and A*

January 4, 2019

Tactics Movement – AI

AI with A* (A Star)

Youtube – Unity Tutorial – Tactics Movement – Part 6

By: Game Programming Academy

This part of the tutorial implements A* for use as the AI for NPCs. Most tactics games would generally involve some type of action phase, but this tutorial finishes with just getting the movement setup.

NOTES

The tutorial’s breakdown of A*:

  • processing the open list by finding the lowest f cost
  • put it in the closed list
  • checking for the target
  • then process adjacency and see if tile is in open list, closed list, or neither (in which case it is added)

Like in many tactics games, the NPCs will still show all of their selectable locations to move before actually selecting one.

For checking distance, tutorial just uses “Vector3.Distance”, but they suggest using the squared magnitude value since it is easier computing because Distance uses square root. Used for setting up simple AI searching algorithm to find the closest thing. It is a simple foreach loop that goes through an array of gameobjects checking the distance between the gameobject itself and each of those individual objects. The distance as well as the object is stored, so whenever a new lower distance is found, the object will be replaced, otherwise, the same object remains there (as that indicates the currently checked object is farther away).

The tutorial tries to keep the TacticsMove script as a generalized class that holds all the helper methods for use in the other classes.

A* uses two lists: an open list and a closed list. A* can also use a priority queue, but C# doesn’t have a built in priority queue. The open list is any tile that has not been processed, and the closed list is those that have been processed. It will finish when the target tile is added to the closed list.

Since we’re using tiles, we could use the “Manhattan Distance” instead. Manhattan distance may work better particularly with arrays though so tutorial sticks with Euclidean distance.

Since we’re using pathing to walk up to a unit, not on top of, the tutorial just decides to follow the A* path and then stop one node before the end (which would be where the target unit is located).

TERMINOLOGY

Manhattan Distance:The sum of the absolute differences of the Cartesian coordinates of two points. This represents the straight line nature of moving around on tiles in this case which is a grid-like layout.

Priority Queue: Like a normal queue but each element within has a priority value associated with it.

TODO

Suggested by the tutorial, program NPC for case where there is no target in range.

Tactics Movement Tutorial (Cont.) – Turn Manager

January 3rd, 2019

Turn Manager – Tactics

Turn Management

Youtube – Unity Tutorial – Tactics Movement – Part 5

By: Game Programming Academy

This part of the tactics game tutorials focused on creating the turn manager. An NPC character was created to represent another team. Even though there are only two units, the tutorial design deals with entire teams. The turnManager used static variables and methods because it should be very accessible and will act as a sort of global since there should only ever be one.

TERMINOLOGY

Subscriber Pattern: the tutorial mentions using this method to add units to the turn manager queue. This was tied to the idea that when a unit comes “online”, it should be able to add itself to the proper list in dictionary.

Dictionary: more uses of this in turnManager system, so I still need to look into this to see how they work.

NOTES

Will need to add method to remove unit from queue when it is defeated, which will then also lead into another method that will be needed for dealing with what happens when an entire team is defeated.

There was a method named “EndTurn” in the TurnManager script and the TacticsMove script. I am not sure if this is a bad practice or something that is generally done without consequence.

PROBLEMS

My units could move through each other or even on to the same space. Going back to tutorial video “Tactics Movement – Part 2” I saw there was an adjacencyList.Clear(); command I was missing in my Tile Reset method. Adding this back in fixed the issue. I wasn’t sure if this was removed later in the tutorial by the tutorial itself for bug testing when player movement was buggy. After checking video “Tactics Movement – Part 4” in the debugging segment, this does not appear to be the case, so it does seem that I just missed that line of code the first time.

Tactics Movement Tutorial (Cont.) – Jumping and State Machines

December 23rd, 2018

Tactics Movement (Cont.) – Jump State Machine

Jumping in Tactics Game

Unity Tutorial – Tactics Movement – Part 4

By: Game Programming Academy

This part of the tutorial focused a lot on the jumping aspects of the player movement. The movement when the unit jumps up or down to different elevation tiles should operate differently than when it just moves around on equal elevation tiles. A state machine is created to deal with all the various aspects of a jump, as well as the possibility of jumping upward or downward. The state machine however appears to have significant bugs in it that will need to be worked out.

Terms

  • Stack: Pop, Peek
  • Protected class

Problems

This part of the tutorial had several bugs that could possibly occur, which the creator of the videos also encounters. The tutorial video showed an issue where the unit would just float in a straight line when it should come down, but I have yet to have that occur. Most bugs I saw had the unit not perform a jumping action, such as just instantly teleporting onto the top of a block instead of performing its slow jump animation. My errors seem to come from the jump state machine not updating properly consistently, where the tutorial video errors seemed to be coming from an issue with the forward-facing vector of the unit not being perfectly lined up at all times (the floating issue might also just be a strange state machine update issue).

Lessons Learned

Locomotion is a good term to use as a commenting term in coding to determine where movement of an element is truly occurring. Can be helpful for figuring out timing for adding animations.

State machines can require a lot of debugging. This will just require consistently calling out what state the object is in at what times, and checking if all of the flag changes are occurring properly.

Learning Tactics Movement (Cont.) – BFS and Collections

December 22, 2018

Tactics Movement (Cont.) – Programming Collections

Breadth First Search (BFS) and Using Programming Collections

Unity Tutorial – Tactics Movement – Part 3

By: Game Programming Academy

This section begins to finally create the breadth first search algorithm for creating list of available selectable tile options. This section relies heavily on collections type elements in C# programming which I will need to delve into more.

Notes

Look into breadth first search, stacks, queues, and lists.

Stacks: Used to add things to a collection in a certain order and use/apply them in reverse order. Stack uses command “push”.

Queues: Use “enqueue” to add to queue and “dequeue” to remove/pull from the queue.

halfHeight was a variable used to find the center point of the game object in conjunction with the “bounds” and “extents” values of the collider. This is used when positioning the unit on a tile to make sure it is on/above the tile.

Lessons Learned

Had an issue where the mouse clicking functionality wasn’t working. It turned out that the main camera just was not tagged “maincamera”. Make sure to check camera labeling and that it matches what you call out in code when dealing with functions that deal with screen space and the camera.