Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

.pth files

Page: 1 of 1
 Pavlos
06-18-2006, 7:33 AM
#1
Simple Question about .pth files: How exactly do these work and how does an NPC know to follow them? I can see how "Path_Points" are placed, that much is obvious to me; what I am unsure about is the connections - what do those figures mean? It has a destination figure but no origin... I'm scratching my head here as I really have no idea how the pathways are built within the game...
 Lit Ridl
06-19-2006, 1:43 AM
#2
I want to know it too and hope someone will answer it. As I know in the most cases NPCs and PC are moving from waypint-to-waypint, it is by the script, I don't remember it's basic code, but it can be easily found in source scripts. May be paths are assigned to NPCs script too? But I haven't seen any path scripts! Looks like something is going to be hard-coded.
 stoffe
06-19-2006, 4:42 AM
#3
May be paths are assigned to NPCs script too? But I haven't seen any path scripts!

While I haven't really looked into this, I assume it is the pathnode system used for in-game pathfinding. For example if a creature needs to move from point A to point B (e.g. using the ActionMoveToObject() function) and there is no straight line between those points, with obstacles or non-walkable areas in between, the creature follows the pathnodes to reach its destination. It's nothing you use directly when moving NPCs around, the game uses it behind the scenes, calculating the shortest path between two points along the pathnode grid.

As for how it's laid out, my entirely unqualified guess from looking at the file would be that the Conections field for a point/node is the number of connections going to/from it, while First_conection is an index into the Path_Conections list for a connection out from this node. The connection in turn specified which other point/node it goes to with an index back into the Path_points list. Seems like each point can have one connection going out from it, and the rest (up to the Conections count) would be connections from other points going to it.

But this is pure guesswork on my part. :)


EDIT: I wrote a quick program that reads a PTH file and plots out the points in a grid and draws lines between them according to my theory above. While it seems to generate a pattern that looks like a plausible set of paths it's hard to tell for sure since I don't know how the maps are laid out/rotated exactly. There also seems to be some gaps in the paths when drawn like this.

For example, 003ebo.pth turned out like shown in the attached image, which seems plausible seeing the rough shape of the vessel, though there are a few oddities here and there.

I'm still not convinced this is how it works due to these oddities, but at least it didn't turn out as complete gibberish when plotted. Might be that I've done some mistake when writing the program processing the PTH file as well. :)
 Pavlos
06-19-2006, 9:51 AM
#4
KotOR Tool's Module editor reads the .pth files too and shows you them in the module if you wish to see them. You could test the validity of your program by comparing it to one of the supported maps. If they turn out similarly we will know you are correct. I'm going to have to do some fiddling but I'm going to test out your theory to see if it works.
 Lit Ridl
07-01-2006, 9:28 AM
#5
I've just found this thread, it may be helpful. (http://www.lucasforums.com/showthread.php?t=142290) . Stoffe, where may I get your program? I want it!
 stoffe
07-01-2006, 10:03 AM
#6
I've just found this thread, it may be helpful. (http://www.lucasforums.com/showthread.php?t=142290) . Stoffe, where may I get your program? I want it!

This is not quite the same thing. Waypoint walking is making an NPC move between a series of waypoint objects that have been placed in an area. The pathfinding, which the .pth file defines, is what the game engine uses to find out where an NPC needs to go to reach a particular place in the area.

In the case of waypoint walking, you could say that the WalkWaypoints script tells the character to move from waypoint 1 to waypoint 2, while the pathfinding tells the character how to get there.

As for the program, nowhere currently since it was just a quick thing I threw together when trying to make sense of the .pth file format. I'm not even entirely sure it works correctly, since the paths plotted look a bit odd in some places. :)
 Lit Ridl
07-01-2006, 10:53 AM
#7
Actually I've read only the second post in thread that I have posted. Sorry please... Thank you Stoffe!
 Pavlos
07-01-2006, 10:56 AM
#8
The program doesn't work properly. Sorry. I checked myself. Your theory seems to be sound, stoffe, up to a point. A test with a droid in a cleaned out 204TEL shows me that they will get up to the middle of their waypoint pathway and then will get stuck - almost as though they realise that either way they go, it will take the same amount of time. It is something I'll fiddle with in my spare time.
 Lit Ridl
07-01-2006, 11:16 AM
#9
I know only one - paths are determined by k_incwalkways.nss . In other things I am zero.
 Pavlos
07-01-2006, 1:55 PM
#10
I know only one - paths are determined by k_incwalkways.nss . In other things I am zero.

Paths are not determined by k_inc_walkways. This is an include file, and besides that: there are no references to the .pth, or pathways, in any of the functions defined by that file.
 Lit Ridl
07-02-2006, 8:39 AM
#11
Than why Tk102 said it? I think he know what is he talking about. But I am not sure, my understanding of his english may be not right.
 Pavlos
07-02-2006, 9:11 AM
#12
He isn't refering to the .pth directly. He's saying that if you want to make an NPC walk a waypoint path you do that. The waypoint path is something different. It essentially says, go from point A to B. What the .pth does is say to the NPC, "If there is an object blocking this direct route, then you can use these routes."

I'm not quite sure how to explain it. Think of the waypoint pattern as being "As the crow flies" and then your .pth could show the NPC the motorway/autoroute whatever you want to call it.
 Lit Ridl
07-02-2006, 9:26 AM
#13
I think I understood you. Anyways waypoints are good things, they are walking Ok in my kotor. But sometimes it stayes in one place if there is an object on it.
 stoffe
07-02-2006, 9:34 AM
#14
Look at this image (http://img59.imageshack.us/img59/4673/waypoints7ou.jpg) to illustrate it more visually.

The waypoint walking system, defined in k_inc_walkways, would tell the character Move from Waypoint 1 to Waypoint 2. This in itself would be equivalent of the red arrow in the image.

However, since there is a fence and an obelisk in the way, the character, standing at Waypoint 1, cannot reach Waypoint 2 by walking in a straight line.

This is where the pathfinding network comes in. It defines a number of nodes that are tied together that makes up valid paths NPCs can use to properly navigate the map. In this case, the relevant paths that could be travelled to reach Waypoint 2, as specified in the .pth file in KotOR, could in this case look like the green arrows.

In other words, the script (using k_inc_walkways) tells the game engine Move the NPC from Waypoint 1 to Waypoint 2, and the game engine looks up the paths, as specified in the .pth file, and picks what it deems the shortest route to reach Waypoint 2.

The biggest problem with the pathfinding (aside from it being hideously CPU intensive) it that it does not automatically take obstacles, like placeables, into account. Thus if you edit an existing area and happen to put a placeable on top of a path, NPCs are likely to bump into the placeable and be unable to continue since they can't find their way around it. In cases where the map and "real terrain" diverge, NPCs always trust the map. :)
 Lit Ridl
07-02-2006, 9:59 AM
#15
Ughh... How difficult... Thank you Stoffe for information! Is it possible to create paths on my own?
Page: 1 of 1