[Tool] Graph Creation Tool

This is a tool to visualize a graph and ease the creation. It is mainly a tool for my graph-based pathfinding resource: [Resource] Graph-based Pathfinding Algorithm for Dummy Bots
The graph defines where the dummy bots are walking. So be careful when creating it.

Share Code: MVZE1 - Version 1.2

What is a graph? A graph can be imagined as a network. It consists of a set of nodes, wich are connected by edges.
For an Overwatch-navigation-graph this would mean nodes are positions on the map a bot can walk to and edges are connections between them, if a bot can walk from one position to another. If a bot can't walk between 2 positions, they are not connected by an egde.

How is the graph type implemented in workshop? The nodes are an array of position vectors.
The edges are an array of vectors in this structure: vector(node1, weight, node2)
- node1: This is the index of the node in the nodes array the bot is coming from.
- node2: This is the index of the node in the nodes array the bot can walk towards.
- weight: This number represents how long the way from one node to the other is. If it's 0 it doesn't mean that the way is free, but that it's an unweighted (= undefined weight) edge.

How to visualize a given graph:

  • Copy the “nodes” array into the rule “Nodes”
  • Copy the “edges” array into the rule “Edges”
  • Start the game
  • The green spheres are the nodes
  • The blue beams are the weighted edges (Y component > 0)
  • The red beams are the unweighted edges (Y component = 0)
  • Edges are a bit higher on the one end and a bit lower on the other end. This means that the egde is coming from the higher end (this is the node in the X component of the vector) and is going towards the lower end (this is the node in the Z component of the vector)

How to create a new graph:

  • Start the game
  • Adding a new node
  • Go to the position of the node you want to add
  • Press primary fire to create a new node
  • The new node is a blue sphere, wich means that it has just been created
  • If you don’t like it you can press interact to remove it. You can only remove the last created node. If you press primary fire 2 times you can’t remove the first one with interact, only the second
  • Go close to the new node and press ultimate to teleport directly to its position
  • Open workshop and add a similar line to the Nodes rule: set global variable at index(nodes, *next free index*, vector(0, 0, 0))
  • When adding the “vector” value, press the button with the camera and the little red circle
  • Repeat until you have all the nodes you want (you can also add new nodes any time)
  • IMPORTANT Make sure that there is no “0” in the nodes array, as this will break the pathfinding algorithm
  • Adding a new edge
  • Go close to the first node you want to connect. Press Secondary Fire. Write down the number or keep it in mind. I reference it as “node1” here.
  • Go close to the second node you want to connect. Press Secondary Fire. Write down the number or keep it in mind. I reference it as “node2” here.
  • Open workshop and add a similar line to the Edges rule: set global variable at index(edges, *next free index*, vector(node1, 0, node2))
  • Keep in mind that you also have to add a second edge vector(node2, 0, node1) if you want the edge to be walkable in both directions, unless you plan do use the undirected version of my pathfinding algorithm.
  • Setting the weight of an existing edge
  • Go close to the first node of the edge. Press Crouch.
  • Go close to the second node of the edge. Press Crouch again.
  • Now the message will display with the index of the edge and the weight.
  • Open workshop and look for the edge with the index in message, then set its Y component to the weight.
  • If the egde you have chosen doesnt exist, the index in the message will be -1, or the index of the first element in the array that is 0.
  • Removing an edge
  • Chose the edge with crouch like before.
  • You can freely remove it from the array.
  • Removing a node
  • Don’t just remove the node from the array. It will be replaced by a 0 and this will break the pathfinding algorithm.
  • Remove all the edges the node is connected with first.
  • Then, instead of removing it, you change the Y component of the node you want to remove to a very low value. It has to be underneath the ground, so it will never be chosen by the pathfinding algorithm.

Top-Down Camera Controls:

  • Press reload to start the top-down camera.
  • Hold ability 1 (shift) and move the mouse / control stick to rotate the camera.
  • Hold ability 1 (shift) and move forward / backward to zoom the camera in / out.
  • move left / right / forward / backward (don’t hold ability 1) to move the camera around.
  • Press reload again to leave the top-down camera.

Selecting a specific area of the graph:

  • As there is an effect limit of 128 effects, a graph that has more than 128 elements (nodes + edges) can’t be visualized entirely. So I added the option to select a specific area on the map and show only the elements wich are inside this area. This is how to do it:
  • Press reload to enter the top-down camera.
  • Move / zoom / rotate the camera.
  • You will notice a violet circle on your screen. This is the cursor position you can simply control with the mouse / control stick.
  • Press primary fire to select the center position of the area at the current position of the cursor. A yellow heart will mark the center position.
  • Press secondary fire to cancel the area selection.
  • The area gets visualized by a yellow light shaft. Move the cursor to change the size of the area. Press primary fire again to confirm the area selection.

Hardcode an area you are frequently working on:

  • If you are working on a specific area of the graph and you don’t want to select the area every time you restart the match, you can hardcode the area this way:
  • Check the inspector for the player variable “areaPhaseCenterRadius”. This array holds the center position of the currently selected area at index 1 and the radius at index 2.
  • Open the rule “initialisation”.
  • Activate the disabled actions and enter the center position and radius exactly like commented.

Change-Log:

  • Version 1.2
  • Added top-down camera option
  • Added option to show only a specific area of the graph

I hope you will like this tool. If you have any feedback, please share it with me :slight_smile:

6 Likes

Ohhh man you help me soooo much thank you !!!

1 Like

I’m glad you like it :blush:

1 Like

Wow man this is pretty awesome. I was googling “workshop programing bot shortest path”, and it took me to this article, which is EXACTLY what i was looking for.

Im making a COD style zombie game. And i needed to find a way to make the zombie come look for the player from its spawn to the players location. I figured i needed to create a “shortest path” code and that’s when I stumbled onto this article.

Great stuff!

2 Likes

Hey DaddyChill,

thank you for your kind post. I’m glad that my tool is useful to you!

Since it is apparently still popular, I am probably going to work on a qol and performance patch for it.

Sounds good. Also was going to mention, there is a FASTER way into adding the newly created Nodes to the “Nodes Array”. Instead of creating a node and adding the code one by one, you can…

First: Mark ALL of the nodes you want to create on the map.

Second: After your done. Open Workshop Editor, click on bottom right “Variable Target”, click on “Global”, and there all of your old and recent created nodes will be neatly created into one Nodes Array. All you do is just copy the code by pressing on the “X” to copy it to your clipboard. And from your clipboard you paste it into your Workshop “Nodes Rule” and replace your old “Nodes Array”.

1 Like

Or just copy the code of predefined nodes…, its not really a faster workflow, you also need to set the positions first, without positions no path nodes,…

Hey bro, I want to see what your thoughts are on this problem I have. This might be hard to figure out, If you don’t have a clue, no worries.
How do I change the bot to the enemy team and apply the code to the enemy Ana? I thought I did it correctly, but the weirdest thing happens. When Enemy Ana Bot trys to reach a node that’s passing a DOOR, she stops at the door. Any other node that is not passing a door she can reach no problem. Am I missing something?

Here are the changes I made to change bot to enemy team:

  1. I created a enemy Ana in “team 2” instead of “Team 1/ Slot 1”

  2. I replaced every piece of code that mentions Ana as “Player in Team 1 / Slot 1” to “Any player in Team 2”. (I want to create multiple bots)

  3. I also changed EventPlayer.pathTarget from “Position of Player in slot 0/Team 1” to “Position of/ Closest Player to/Opposite Team of/ Team of/ Event Player”

Nvm, I think figured it out. So it looks like the bot can not leave a door that’s close to the enemy spawn. Im not talking about being inside the spawn area, Im talking about inside the spawn area BUILDING. I’m not sure whats going on but, only the same team can go in and out of spawn area structure. Again, not Spawn Area, Spawn Building…THE WHOLE BUILDING.

1 Like