Game Development Community

Path finding

by Chris · in Torque 3D Professional · 05/15/2009 (9:12 am) · 53 replies

Will the 2009 engine include any path finding implementation?

#21
05/18/2009 (7:23 pm)
> draw a number of points on the map and the AI moves in straight lines between them

Any quick hints on where to find this in Torque 3D?

#22
05/18/2009 (8:07 pm)
In 'World Edit Mode' select 'Library/Level' from Scene Tree, find 'Path'.
#23
05/18/2009 (10:01 pm)
Quote:
> draw a number of points on the map and the AI moves in straight lines between them

Any quick hints on where to find this in Torque 3D?
For the paths to work correctly with the code that is in aiPlayer.cs you'll use the Level Editor to place a series of numbered path markers that make up a path.

1: create a new SimGroup called "Paths" -- SimGroup(Paths)
2: inside this SimGroup you will place a "Path" object. Call it "Path1".
3: create a series of "PathMarkers" under the Path object, still inside the SimGroup. Place these "PathMarkers" where you want them.

Each PathMarker will need to have it's own "seqNum" field. This is the order in which the bot will follow the nodes(markers) on the path, 1 - 2 - 3 - 4 - etc, etc so on and so forth then back to marker #1 ad infinitum. All other fields are self-explanatory or should only take a little bit of experimentation to understand what they do/mean.

4: Save the mission. Reload.

If all steps are performed correctly you will then see a "dumb" bot following the path you just laid out -- if you're using the FPS kit then appropriately enough this bot is named "Shootme".

It's the AIManager that kicks off the spawning of the bot onto the path if a path is found for each mission, it can also control the behavior of the bot (it's "intelligence"). It's the work of the AIPlayer methods to control the actions of the bot. These AIManager and AIPlayer methods can be easily expanded into something more useful, but note that this simple pathed AI is not "true" path-finding.

#24
05/18/2009 (11:09 pm)
Quote:
I believe that the old curve based pathfinding is still in T3D(ie. draw a number of points on the map and the AI moves in straight lines between them),

This is not pathfinding; it is path following. They are completely different. However, there are many implementations where path following and pathfinding are combined.
#25
05/18/2009 (11:40 pm)
Dont you need one before you can have the other anyhow?
#26
05/18/2009 (11:54 pm)
Not necessarily...
#27
05/18/2009 (11:57 pm)
Well at any rate, Michael clarifies his quite detailed explanation with the last line of the last paragraph. Oh and "Not necessarily... " is not an answer, its a reply. The difference is 'not necessarily' the same.

Edit: And whilst on the subject of conundrums, how can an AI do 'pathfinding' if it do not know 'path following'?
#28
05/19/2009 (12:08 am)
Well, path following in this context is moving through a set of predetermined points, whereas pathfinding would involve "thinking" in order to determine where to move, often using shortest path algorithms or other means. Sure, pathfinding often does use points, or grids, or sectors to assist in determining the shortest path (or longest, or whatever), but it does not usually have the predetermination that path following does. I guess if you want to be really strict, then I guess the predetermination of movement is what is calculated before the actual movement occurs. ;)

Maybe that difference seems to be miniscule but in calculation it certainly isn't.

It was actually Bryan Morgan who made the comment I quoted. ;)
#29
05/19/2009 (12:41 am)
Quite right Joe. Thanks for explanation, i can see the difference now.
#30
05/19/2009 (2:28 am)
With a "little" bit of creative thinking (and coding) you can do a fairly decent, and scripted, implementation of deterministic path-finding that has it's roots in path-following. Just because it's currently coded that way doesn't mean you have to follow the markers in any strict order. It's also entirely possible to give your AI the freedom to move anywhere, with periodic checks to hunting/seeking "logic" dictating where they go. You would then use the path markers to confine them to a specific area, to guide them around obstacles, or even to denote areas they can't go.

I do still feel that AI and path-finding in general is highly specific to a genre (path-finding is especially useful for RTS games) or more particularly an individual game. Trying to develop a "general" purpose scheme for everyone to use is pretty much a waste of time and resources that can be better spent in other areas. Templated or generalized AI may be good for the "hobbyist" maybe, but not for someone with serious requirements for AI. At least an "add-on" external module can be specialized for a specific genre.

And yes, I have "played with" and experimented with other engines that included all-in-one AI functionality. The impression I was most left with was that all of them did so in a manner that was rather... dumb, and difficult to adapt to out-of-the-box uses. That's why I'm glad Torque offers me the flexibility of a custom solution (even if I have to do it myself) without the need of removing something that I have already seen is disappointing elsewhere.
#31
05/19/2009 (5:47 am)
Great to see this getting some discussion as it's an area we're heavily developing at the moment. I would like to keep the topic of Pathfinding seperate from A.I. though, yes pathfinding does usually get used mostly by A.I. but it can also have many other functions from showing players the direction to travel for their next objective, finding cover points or objects to pickup and so the two should be kept seperate.

A.I. to me is the thinking process and I agree with Michael it's far too game/genre specific to create a full configurable system... although to me the genre kits should contain starter AI too so that the less technically minded people can expand on it.

Pathfinding is different though and a good set of classes for Search Space representation usually a graph (navMesh) of some form, a way to edit and create it and some search algorithms (A*, Djistra) is something that would be worth while adding because it would be very similar in FPS, RPG, RTS, etc.

We are working on a PathFinding solution for Torque (TGEA) which will get ported to Torque 3D and I'm determined to make it available in one form or another to the community. We're nearing completion of the editor side and in the next week or two will be moving onto A* implementation.
#32
05/19/2009 (6:40 am)
@Andy
Was about to say I'll believe it when I see it... but then I realized it was Andy - who has already posted a quite fine video!

Your navmesh generation for bsps looks pretty sweet... next to duplicate those results for terrain and other static geometry ;)
#33
05/19/2009 (7:01 am)
Time for "James's Random, Mostly-Unrelated Thought of the Day!"

I'm constantly amazed how many times the same code has to get written... If you think about all the game related code in the world, I bet 99.99% of it is redundant. But you end up writing it yet again because a) you just don't have access to most of it, and b) the algorithm may exist but it has to be "ported" to your language, your engine, etc...

The response to this might be, you only ever understand your code and writing it yourself is the only way to really grasp the concepts. Which might be true, but the whole situation just seem really odd if you think about it...

Its sortof like how you look around some grocery stores and every single thing is individually packaged, and most of those packages contain more individually packaged what-have-yous inside. Then you buy it and it goes in... a bag. Sure its like that for a reason (convenience), but... what a phenomenal waste.

Sorry for the interruption, please continue everyone...
#34
05/19/2009 (7:26 am)
Thanks James. That was most ponderous.
Now I can go to bed and fell good about how today went.

EDIT: Its nice to see that the people on the other side of my computer screen are real, and share similar existential pondering. (Its a sign that you all dont just exist in my head!)
#35
05/19/2009 (8:39 am)
@ Caylo

I am sure you don't mean to suggest that James, and or what he wrote, is awkward and unwieldy, or dull and labored ( "ponderous" ), but rather that it is capable of being considered carefully or deeply ( "ponderable" ).

Sorry if this seems like nit-picking, but don't blame me... I am just a voice inside your head. ^_^

#36
05/19/2009 (11:13 pm)
I'm actually of the opinion that a good pathfinding implementation would be useful across genres. Sure it may require some tweaking for specific scenarios, but if there were a framework in place it would help some of us to see how the code interacts with the game objects/players/NPCs. That was my big hurdle when trying to come up with some workable AI in TGE/TGEA.
#37
05/20/2009 (12:12 am)
@Gerry: Words are more flexible then you think they are.
#38
05/20/2009 (4:44 am)
function GenerateNavMap()
{
   //Dumb Nav Graph Map
   
   $MapSize = Terrain.baseTexSize;  // Get the default size of the terrain
   $NodeDistanceApart = 5; //World Units apart
   $MarkerZOffset = 1; //World Units above terrain that marker will be located

   %nodesInLine = round($MapSize/$NodeDistanceApart);
   %initalZ = getTerrainHeight($MapSize/2, $MapSize/2);
   %StartPos = $MapSize/2 @ " " @ $MapSize/2 @ " " @ %initalZ;

   for( %y = 0; %y < %nodesInLine; %y++ )
   {
      for( %x = 0; %x < %nodesInLine; %x++ )
      {
         //Positive Corners to Negative Corners
         %xOffset = %x * $nodeDistanceApart;
         %xNewPosition = getword(%startPos, 0);  //Innate Torque Function
         %xNewPosition -= %xOffset;
         
         %yOffset = %y * $nodeDistanceApart;
         %yNewPosition = getword(%startPos, 1);  //Innate Torque Function
         %yNewPosition -= %yOffset;

         %zNewPosition = getTerrainHeight( %xNewPosition, %yNewPosition ); //Innate Torque Function
         %zNewPosition += $MarkerZOffset;

         %markerPos = %xNewPosition @ " " @ %yNewPosition @ " " @ %zNewPosition;

         %p = new Marker("TestX" @ %x @ "Y" @ %y){
               canSaveDynamicFields = "1";
               Position = %markerPos;
               rotation = "1 0 0 0";
               scale = "1 1 1";
               seqNum = "10";
               type = "Normal";
               msToNext = "1000";
               smoothingType = "Spline";
            };
         MissionCleanup.add(%p);  //Innate Torque Function :P Lets keep it clean!
      }
   }
}

//Now you have a NavGraph for all of the AI to use for Path Finding. Each node is uniquelyNamed
#39
05/20/2009 (5:14 am)
Next take a simple resource like this one:
http://tdn.garagegames.com/wiki/TGB/Source/Pathfinding

and incorporate it into your project.
#40
05/20/2009 (9:00 am)
Quote: Words are more flexible then you think they are.

Tell that to my C++ compiler...

or the biker who punches you in the nose when you decide to get "creative" with the language rather than relying on common everyday usage.

;)