Game Development Community

dev|Pro Game Development Curriculum

Dijkstra

by Robert Brower · 07/12/2004 (2:09 pm) · 13 comments

Download Code File

This zip file contains a modified AIPlayer.cs file, and a new file, dijkstra.cs. The current AIPlayer.cs script contains an AIManager script object. I have extended this by including my file from aiplayer and making some changes to make the AIPlayer hunt down the closest player using Dijkstra's Shortest Path algorithm.

#1
07/12/2004 (2:28 pm)
must not be ready yet.. I get a looping effect.. :)
many windows open before i realized there is no file.. :) lol

oh and first
#2
07/12/2004 (2:58 pm)
Ah seemed to gd to be true!!!
#3
07/12/2004 (3:13 pm)
lol - I swear they did that for suspense ;).

This seems to be a very nice resource though - good job!
#4
07/12/2004 (9:09 pm)
I want to also give some added info on the mechanics of how this works since there is no readme.txt file...

The screenshot shown here shows my test mission which contains a DIF of a maze with an open top so that I could observe the bot movement while developing the scripts. The mission contains a Sim group named 'Dijkstra'. This Sim group contains markers which are located at each intersection of the maze and in corners. Properties of the markers in the mission determine how these nodes are connected to one another. The AIManager creates an instance of a Dijkstra script object and initializes it. This calculates all of the distance-based weights from each node to the next in all possible directions. The Dijkstra script object provides AIManager a means of getting the shortest path thru the maze to the closest player. This happens in the AIManager::think() method. AIPlayer was modified slightly to utilize the Dijkstra script objects output which is an array of marker id's and to make the bot fire his weapon at the player when the player entered the bot's line of sight. A small snippet of my mission file is shown below:

new SimGroup(Dijkstra) {

new Marker(marker0) {
position = "0 0 0";
rotation = "1 0 0 0";
scale = "1 1 1";
seqNum = "1";
type = "Normal";
msToNext = "1000";
smoothingType = "Spline";
NextNode2 = "-1";
NextNode3 = "-1";
NextNode0 = "1";
NextNode1 = "-1";
};
new Marker(marker1) {
position = "0 10 0";
rotation = "1 0 0 0";
scale = "1 1 1";
seqNum = "2";
type = "Normal";
msToNext = "1000";
smoothingType = "Spline";
NextNode2 = "0";
NextNode3 = "3";
NextNode0 = "-1";
NextNode1 = "2";
};
new Marker(marker2) {
position = "5.8 10 0";
rotation = "1 0 0 0";
scale = "1 1 1";
seqNum = "3";
type = "Normal";
msToNext = "1000";
smoothingType = "Spline";
NextNode2 = "-1";
NextNode3 = "1";
NextNode0 = "4";
NextNode1 = "7";
};

.
.
.

The only relevent properties here are NextNode0 through NextNode3. The Dijkstra script object links one node to up to 4 other nodes in sort of a north east south west arrangment through these properties.

Good luck with the resource.

Robert
#5
07/13/2004 (5:42 am)
Interesting, I could never get the default ai to do anything other then run its neverending marathon, so i comented it out and used a nother resource.

Now you need to make it attack. :)

good job.
#6
07/13/2004 (8:56 am)
This AI guy attacks when he finds you. Think of a pacman ghost with a missile launcher.
#7
07/13/2004 (4:42 pm)
well i must of missed something then, i will look again, i only played with it for a few minutes before work this morning
#8
07/14/2004 (10:57 am)
@Robert, did you add those markers after inserting the dif or are they built into the dif? And, does this resource help bots find doorways into difs?
#9
07/14/2004 (11:37 am)
The markers are not built into the dif. The mission file snippet shows how they are set up. They refer to each other by index, or to -1 which indicates a closed path. They are in the Dijkstra Sim group. The reason I made this a script only resource was for the benfit of people who could not easily make engine changes.

Cheers,

Robert
#10
07/14/2004 (12:15 pm)
Thx, good idea!
#11
07/14/2004 (9:31 pm)
@Robert: Can you provide a mission file as it's confusing when you have more than a few markers to see how they should be organized. Also I'm not sure how to organize them correctly given a landscape setting rather than a maze? Thanks.
#12
07/14/2004 (11:47 pm)
Bil,

The index of the marker is determined by the order in which they are found in the mission Sim group called 'Dijkstra'. I updated the zip file to include my entire mission file.

This implementation is 2 dimensional in that it does not use the height of the terrain to determine the weights. Instead it uses the distance from one marker to the next. Placement of the markers in the world space is arbitrary.

The findPath() method is a member of the Dijkstra script object. You have to instantiate it like I did in AIPlayer.cs in order to call this member.

Unfortunately, I cannot get into a torque scripting tutorial due to time constraints, but I recommend you replace your AIPlayer.cs with mine, and put Dijkstra.cs in the fps.starter\server\scripts folder and load up the mission that I added to the zip file tonight. Then you can see how the markers are arranged. I placed them at every intersection and corner in the maze, so if you were going to use this for a mission with terrain, you could create interconnected paths through the valleys along the roads. The zip doesn't contain my maze DIF or the entire demo, so you might have to ~wing it~.

Good luck,

Robert
#13
07/15/2004 (12:02 am)
@Robert: No need for the scripting tutorial as that's oxygen to me. I just wasn't sure how the node relationships went. The new mission file inclusion will clear up any confusion I had on it. Thanks.