In the previous article, I mentioned a new approach you should consider if you want to build next-gen, innovative games, called Biological Path Finding (BPF). I always thought that the most used models are not a bible, to use without thinking about, and that doubts are often the factor that brings our mind to create better AI models.
Please note that you need to read the previous article of this topic (relative to the Navigation), before reading this one.
If you want to build a single videogame per time, for a videogame similar to a lot of others, if you have few NPCs living in the same time and you don’t mind that they sometimes (or often) do what humans never do when walking, you could find the NavGrid or the NavMesh models as enough and good, without any customization. Conversely, the future of videogames can’t be built continuing to make NPCs that pretend to be humans, but rather having high credibility with new features, by adopting newer models that provide all these features without customizations.
The current Navgrid and Navmesh models have good pros, but even stronger cons. For instance, both could make, in several circumstances, long time for the off-line calculations, and both should not be used when there are several NPCs living together in a wider level. Not if you want your game go fast, and not if the correctness of the human behaviour is a must.
Moreover, the Navgrid should not be used for 3D maps for wider levels, unless you want to raise the amount of connections a lot, letting the path calculation be even more complex, with obvious performance issues.
If you think to a human with his needs, not only abstractly, logically, you find that the number of the graph nodes that has to be put into the level map is much less than with Navmesh or Navgrid, in any map and circumstances, having also a better human behaviour in the movement of NPCs.
How is this possible? The goal is taking into account only the points of the level where there is the connection between two micro-environments: next to a corridor, between two neighboring columns, a doorpost etc.
A postulation of this approach is that a micro-environment can be such if the focal points to connect it with contiguous micro-environments are all visible one each-other. So, for example, a corridor formed by two big objects, placed in the middle of a wider place, let the design-time elaboration create two focal points, each at the beginning (or ending) of the corridor. I use the same term used by Lynch (1960) about these important points, naming them as “focal points” (see the previous article for more info).
Another postulation tells this: if the micro-environment is minimal, speaking about dimensions referred to the dimension of a medium NPC (i.e. between two columns), the two focal points that will be automatically created by the graph calulation algorithm will be reduced to only one, placed in the middle of the space between them.
Focal points are the only parts of any zone that humans and animals take into consideration, in a path, when they need to change direction. Moreover, during the movement along the path, the BPF (Biological Path Finding) states that the agent will direct not toward the next focal point, but toward the last focal point, along the path, that the agent is able to “see”. This is an innovation that improve further the agent’s credibility, and this is what really humans do when are in place of agents.
Look at the image. The Green Circle, located in the left part of the building, is the position where the NPC is placed, while the Orange Circle is its target. The wider green line is the path that the NPC will use thanks to the BPF, while the thin green line tells the selected path. The Violet Circles, instead, sign the change of the kind of viability, and only the NPCs able to jump (at a defined height) will see them.
As you can see, the second focal point the NPC will take into consideration is not the second in the selected path, but the third, while the fourth that will be used is the seventh of the selected path. This is because of the previously mentioned rule, with whom the run-time approach of the BPF states that the NPC will not lose its “mind” in following each focal point of the chosen path, but will use, of them, only the “farthest, still visible” one. The result is that the number of focal points that will be used is only two, instead of five provided by the path of the mental map.
A solution like that will not only produce, probably, the lesser amount of focal points (or waypoints, as you wish) ever, but even will enhance the human behaviour simulation. Consider a real person in the same context of the NPC of the linked image (the building is a church). Throw away all the paths and focal points, and imagine how he behaves in that context. If he decides to follow the path that our NPC will use, he certainly goes straight forward, until the parts of the buildings will allow him to do in that way, and then will start to turn (a bit in advance, respect to the focal point) in order to go another time straight, until the building will allow him to do in that way, or until his target has been reached.
Together with these rules, the whole BPF implementation needs to have some others, that solve other use cases. It's better not to mention them as a matter of practicality and space, but you should have enough detail about them in the book I wrote and that will be published in the next weeks.
If the human doesn’t know (much) about the zone, the focal points will help him to understand it, because they are placed where he will stop and see how the next micro-environment is made (for instance, think about a dungeon with several rooms).
Coming back to the general level of this topic, we can say that the generation games and, especially, the innovative games, in the early future will have the need to have more features and better performance, without putting complexity over complexity on an AI model that does not already provide those features.
In detail, an innovative path finding model should provide:
(**) As the Psychology states (Lynch, 1960), a human is not able to: 1) remember a map as if he has the map physically on his hands, especially if the zone is not “lived” by the NPC for a while. Then only some parts of the path (the focal points) will be remembered better; 2) emotions and the need to decide fast can obfuscate the reasoning, and then the decide path can often be not the one that the logic would propose.
(***) It’s time, I reckon, that 'smart' games will adopt the natural subdivision among NPCs, in order to better use the new features of the next-gen path finding solutions and innovative decision-making systems.
District Best Path Selection
BPF is so different in respect to the classical, “only-logic” approach, that work better without any use of the current algorithms used to find the shorter path. Without entering into details, the weight of emotions, mental map errors, the NPC's species characteristics and the fact that the amount of districts in a level can’t be higher, will usually bring to have only one path that overcomes all the filters. In this context, with a single path that will be the result of the filters, the use of the algorithm to find the best path is useless and redundant.
For example, a wide level could use a total of 10 districts (see my previous article for more info). Normally, each district could have even four other districts connected to them (unless the level develops even in height). Unless the level is made by a sequence of districts, it’s rare that the target is more than two districts far from the NPC. In this case, it’s useless to adopt any kind of calculation of the best path, regarding the District level (see the previous article).
One of the simplest and effective solutions to limit paths a lot, from the human behaviour point of view, is to avoid all the paths whose first district is not far from the direct line between the NPC and its target (presuming the NPC knows, broadly, the map). Then, you should eliminate the paths containing at least one district checked as "to be avoided" for the species type of the NPC. For instance, if a district is full of dangerous monsters that can kill the NPC, or is full of micro-environments non-viable or viable with difficulty by that NPC species, or even if the path contains a darker zone and the personal traits of the NPC (if available) depict it as a non-courageous individual, the decision-making system should flag the district as "to be avoided" (or even the developer in design-time).
Another filter is the "sensation of the length" of each path. Look at this filter, because it should be difficult to implement but extremely useful, because it is one of the most used by our mind. Humans and the most intelligent animals should take into consideration the sensation of the length of a path. There can be several factors that could take place in the definition of the length sensed by a biological entity, like emotions proven during the past traversals and the fact that the path is mostly straight or tortuous.
Often, our sensation doesn't correspond to the real length of the path, and for this reason we must avoid making real calculations, unless you want to come back and have non-credible NPCs. If you want to use this filter without falling into really difficult psychological studies, you can even create two flags for any focal point, whose duty is reproduce the type of the two micro-enviroments between which the focal point is placed. The flag unchecked could mean that the mini-environment is straight, while the flag checked means that it is somewhat tortuous. The higher the amount of checked flags along the path, the lower the probability that path will be used.
Then, another filter is relative to the knowledge of the districts by the NPC. This is another important feature that a well-done human simulation could consider. The knowledge map of the district, made per NPC or per Species (to ease the code and the run-time system), could be made randomly or, in case of long-living NPCs, by recording the places traveled by the NPC.
Normally, the result should be one to two paths, maximum three of them. What is then the one to use, if there are more than one of them? Simple: the path containing the highest amount of districts traversed by the linecast that goes from the NPC toward the target, balanced by the less amount of districts of each path. In fact, bear in mind that humans and animals, when faced with a path finding issue, have no time to sit (imagining that an animal can do it!) and make any sort of calculation. All of them use the info gathered in the past (the other filters) and common-sense.
To recap the filters:
If the result is more than one district path:
Inner Best Path Selection
After having decided the district path to follow, the NPC has to start to resolve the path finding inside the current district. Then, when inside the next districts, redo the same for that district. The division of the level into districts (cubes) normally leads to have several cases into which two districts are linked together by more than one walkable (or better usable) surface. This means that an NPC could have more than one solution to go to the next district of the chosen district path.
Even if the division of the paths into two levels speeds up the run-time selection of the best path and forces you to split the path finding into more than one step, there are some new issues you should face with, in order to use the approach correctly. In the case of the passage between two districts, there are two things the design-time elaboration of the paths should check: the "dead paths" and the connections between passages through districts. In fact, if one of the possible paths whom connect two contiguous districts stops into the district without the possibility to pass to another one, the NPC should know previously about this issue.
In order to fulfil the problem, in design-time we shall select, for each district, the paths that travel the district by going from one contiguous district to another each contiguous to the district in question. This could be a time consuming calculation, especially if the number of the passages between contiguous districts are high. This could be a good reason to modify manually the districts, in order to avoid having too many links between two districts.
Anyway, the calculation to be done should be the following:
A - select the district
Look at the fact that there is no need to calculate the length of each path, and this helps a bit.
The data relative to the possible passages to the next districts will be then used in run-time to check which passage to select to go to the next district. If there are more than one passages that traverse the district toward the next one, the NPC mind should decide which to use. How? You should use the same filters adopted to the district level of the path finding, but I suggest to use one or two, between the sensation length and the distance of the passage respect to the direct line toward the target.
When you have the initial part of the inner path (where the NPC is entering into the district, or where the NPC is placed) and the passage to the next district, or where the target is placed, you shall select the path to use to arrive to your next path finding goal. Even in this case, you should use the filters already discussed. It's up to you to decide which of them, or use all.
Note, though, that this way of thinking, from the NPC, is not the right way if your project is a tactical war game. The tactical war game is one of the rare situations in which the paths could be already well known by each NPC "at the table". In this case, then, a good solution remains one of the correct, only-logic approaches. The only filter you should add is the arousal level of the emotions currently lived by the NPC (arousal is, for emotions, something similar to the volume for the music). This is, though, an issue not directly managed by the PF system, even if it could change the reasoning phase of an NPC about the best path find selection.
Nonetheless, you could easily note that the Biological approach should be faster than the current ones, because the actions to be executed are lightweight, and with a reduced amount of nodes in the graph, even thanks to the division of the paths into two levels (see the first article for more info).
The biological approach to a path finding, inherent in the Biological Path Finding, can be used not only for humans, zombies, monsters and aliens, but even for intelligent animals and, using the right limits, with any other kind of animal.
Nonetheless, never underestimate the role of emotions under the path finding issue. Even ability to take decisions, like the one explained in this article, is a feature made not only by logic. As a confirmation of this statement, Plutchik said that emotions are basic adaptations needed by all organisms in the struggle for individual survival (1980, p. 145). He suggested that the selection occurred in the Cambrian era, 600 million years ago. The eight adaptations are incorporation, rejection, destruction, protection, reproduction, reintegration, orientation and exploration. This means, also, that the most important filters of the Mental Navigation, emotions, are shared with a wide variety of animals.
So, what differs from humans way to solve a path finding to the ones of animals? The difference is rather small, and is only related to the use of logic. This is not entirely true, but the causes of this are so profound and so difficult to be reproduced in code that I prefer not to mention it in this context.
Most animals are unable to use training to better govern their emotions, and they are also unable to take into consideration more than one deduction relative to the filters adopted. If you want to differ the human behaviour to the animal one, toward the decision for the path selection, use only one filter for the simplest animals, and then apply other filters as you are facing more intelligence animals. The only filter you should always use is the one relative to the selection of only the paths whose first focal point is toward the direction of the target.
The next article will be focused on the Mental Map, Dynamic Object Avoidance and Smoothing movements.
14 Mar 2014: Title modification, moved the image as an attachment, some other changes
10 Mar 2014: Initial release
Please note that you need to read the previous article of this topic (relative to the Navigation), before reading this one.
Graph Creation
If you want to build a single videogame per time, for a videogame similar to a lot of others, if you have few NPCs living in the same time and you don’t mind that they sometimes (or often) do what humans never do when walking, you could find the NavGrid or the NavMesh models as enough and good, without any customization. Conversely, the future of videogames can’t be built continuing to make NPCs that pretend to be humans, but rather having high credibility with new features, by adopting newer models that provide all these features without customizations.
The current Navgrid and Navmesh models have good pros, but even stronger cons. For instance, both could make, in several circumstances, long time for the off-line calculations, and both should not be used when there are several NPCs living together in a wider level. Not if you want your game go fast, and not if the correctness of the human behaviour is a must.
Moreover, the Navgrid should not be used for 3D maps for wider levels, unless you want to raise the amount of connections a lot, letting the path calculation be even more complex, with obvious performance issues.
If you think to a human with his needs, not only abstractly, logically, you find that the number of the graph nodes that has to be put into the level map is much less than with Navmesh or Navgrid, in any map and circumstances, having also a better human behaviour in the movement of NPCs.
How is this possible? The goal is taking into account only the points of the level where there is the connection between two micro-environments: next to a corridor, between two neighboring columns, a doorpost etc.
A postulation of this approach is that a micro-environment can be such if the focal points to connect it with contiguous micro-environments are all visible one each-other. So, for example, a corridor formed by two big objects, placed in the middle of a wider place, let the design-time elaboration create two focal points, each at the beginning (or ending) of the corridor. I use the same term used by Lynch (1960) about these important points, naming them as “focal points” (see the previous article for more info).
Another postulation tells this: if the micro-environment is minimal, speaking about dimensions referred to the dimension of a medium NPC (i.e. between two columns), the two focal points that will be automatically created by the graph calulation algorithm will be reduced to only one, placed in the middle of the space between them.
Focal points are the only parts of any zone that humans and animals take into consideration, in a path, when they need to change direction. Moreover, during the movement along the path, the BPF (Biological Path Finding) states that the agent will direct not toward the next focal point, but toward the last focal point, along the path, that the agent is able to “see”. This is an innovation that improve further the agent’s credibility, and this is what really humans do when are in place of agents.
Look at the image. The Green Circle, located in the left part of the building, is the position where the NPC is placed, while the Orange Circle is its target. The wider green line is the path that the NPC will use thanks to the BPF, while the thin green line tells the selected path. The Violet Circles, instead, sign the change of the kind of viability, and only the NPCs able to jump (at a defined height) will see them.
As you can see, the second focal point the NPC will take into consideration is not the second in the selected path, but the third, while the fourth that will be used is the seventh of the selected path. This is because of the previously mentioned rule, with whom the run-time approach of the BPF states that the NPC will not lose its “mind” in following each focal point of the chosen path, but will use, of them, only the “farthest, still visible” one. The result is that the number of focal points that will be used is only two, instead of five provided by the path of the mental map.
A solution like that will not only produce, probably, the lesser amount of focal points (or waypoints, as you wish) ever, but even will enhance the human behaviour simulation. Consider a real person in the same context of the NPC of the linked image (the building is a church). Throw away all the paths and focal points, and imagine how he behaves in that context. If he decides to follow the path that our NPC will use, he certainly goes straight forward, until the parts of the buildings will allow him to do in that way, and then will start to turn (a bit in advance, respect to the focal point) in order to go another time straight, until the building will allow him to do in that way, or until his target has been reached.
Together with these rules, the whole BPF implementation needs to have some others, that solve other use cases. It's better not to mention them as a matter of practicality and space, but you should have enough detail about them in the book I wrote and that will be published in the next weeks.
If the human doesn’t know (much) about the zone, the focal points will help him to understand it, because they are placed where he will stop and see how the next micro-environment is made (for instance, think about a dungeon with several rooms).
Coming back to the general level of this topic, we can say that the generation games and, especially, the innovative games, in the early future will have the need to have more features and better performance, without putting complexity over complexity on an AI model that does not already provide those features.
In detail, an innovative path finding model should provide:
- A faster off-line calculation of the single graph, respect to the current ones*.
- Ability to let the NPCs use multi-genre paths, that is letting NPCs use not only walk and run along the path, but even jump, climb, swim etc.
- Ability to have different good paths for different species of NPC, according with the physical characteristics of each NPC species
- A faster run-time calculation of the “plausible best path”**
- Resolve the problem of the dynamic objects along the paths with no added complexity
- Find multiple targets, not only of the same kind of NPCs, but even of the same species (i.e. shelters of different types)***
- Change the graph dynamically when walls and big objects change their positions
- Take always into consideration that the mental map of each NPC can be different from the actual map
(**) As the Psychology states (Lynch, 1960), a human is not able to: 1) remember a map as if he has the map physically on his hands, especially if the zone is not “lived” by the NPC for a while. Then only some parts of the path (the focal points) will be remembered better; 2) emotions and the need to decide fast can obfuscate the reasoning, and then the decide path can often be not the one that the logic would propose.
(***) It’s time, I reckon, that 'smart' games will adopt the natural subdivision among NPCs, in order to better use the new features of the next-gen path finding solutions and innovative decision-making systems.
Best Path Selection
District Best Path Selection
BPF is so different in respect to the classical, “only-logic” approach, that work better without any use of the current algorithms used to find the shorter path. Without entering into details, the weight of emotions, mental map errors, the NPC's species characteristics and the fact that the amount of districts in a level can’t be higher, will usually bring to have only one path that overcomes all the filters. In this context, with a single path that will be the result of the filters, the use of the algorithm to find the best path is useless and redundant.
For example, a wide level could use a total of 10 districts (see my previous article for more info). Normally, each district could have even four other districts connected to them (unless the level develops even in height). Unless the level is made by a sequence of districts, it’s rare that the target is more than two districts far from the NPC. In this case, it’s useless to adopt any kind of calculation of the best path, regarding the District level (see the previous article).
One of the simplest and effective solutions to limit paths a lot, from the human behaviour point of view, is to avoid all the paths whose first district is not far from the direct line between the NPC and its target (presuming the NPC knows, broadly, the map). Then, you should eliminate the paths containing at least one district checked as "to be avoided" for the species type of the NPC. For instance, if a district is full of dangerous monsters that can kill the NPC, or is full of micro-environments non-viable or viable with difficulty by that NPC species, or even if the path contains a darker zone and the personal traits of the NPC (if available) depict it as a non-courageous individual, the decision-making system should flag the district as "to be avoided" (or even the developer in design-time).
Another filter is the "sensation of the length" of each path. Look at this filter, because it should be difficult to implement but extremely useful, because it is one of the most used by our mind. Humans and the most intelligent animals should take into consideration the sensation of the length of a path. There can be several factors that could take place in the definition of the length sensed by a biological entity, like emotions proven during the past traversals and the fact that the path is mostly straight or tortuous.
Often, our sensation doesn't correspond to the real length of the path, and for this reason we must avoid making real calculations, unless you want to come back and have non-credible NPCs. If you want to use this filter without falling into really difficult psychological studies, you can even create two flags for any focal point, whose duty is reproduce the type of the two micro-enviroments between which the focal point is placed. The flag unchecked could mean that the mini-environment is straight, while the flag checked means that it is somewhat tortuous. The higher the amount of checked flags along the path, the lower the probability that path will be used.
An example of a focal point and its two flags indicating the type of the two adjacent micro-environment.
Then, another filter is relative to the knowledge of the districts by the NPC. This is another important feature that a well-done human simulation could consider. The knowledge map of the district, made per NPC or per Species (to ease the code and the run-time system), could be made randomly or, in case of long-living NPCs, by recording the places traveled by the NPC.
Normally, the result should be one to two paths, maximum three of them. What is then the one to use, if there are more than one of them? Simple: the path containing the highest amount of districts traversed by the linecast that goes from the NPC toward the target, balanced by the less amount of districts of each path. In fact, bear in mind that humans and animals, when faced with a path finding issue, have no time to sit (imagining that an animal can do it!) and make any sort of calculation. All of them use the info gathered in the past (the other filters) and common-sense.
To recap the filters:
- Only the district paths whose first district is not far from the direct line between the NPC and its target
- Only paths without "to be avoided" districts
- Sensation of the Length of the Path
- Only paths without unknown districts
If the result is more than one district path:
- Take the path with the lower number of districts or have the higher amount of district traversed by the direct line between the NPC and its target
Inner Best Path Selection
After having decided the district path to follow, the NPC has to start to resolve the path finding inside the current district. Then, when inside the next districts, redo the same for that district. The division of the level into districts (cubes) normally leads to have several cases into which two districts are linked together by more than one walkable (or better usable) surface. This means that an NPC could have more than one solution to go to the next district of the chosen district path.
Even if the division of the paths into two levels speeds up the run-time selection of the best path and forces you to split the path finding into more than one step, there are some new issues you should face with, in order to use the approach correctly. In the case of the passage between two districts, there are two things the design-time elaboration of the paths should check: the "dead paths" and the connections between passages through districts. In fact, if one of the possible paths whom connect two contiguous districts stops into the district without the possibility to pass to another one, the NPC should know previously about this issue.
In order to fulfil the problem, in design-time we shall select, for each district, the paths that travel the district by going from one contiguous district to another each contiguous to the district in question. This could be a time consuming calculation, especially if the number of the passages between contiguous districts are high. This could be a good reason to modify manually the districts, in order to avoid having too many links between two districts.
Anyway, the calculation to be done should be the following:
A - select the district
A1 - select one side of the district where there is at least one passage to the contiguous district
A11 - For each passage, check if there is a path that conduct to another contiguous district. If so, flag the passage as compatible with the passage to that district (in the way you wish).
Look at the fact that there is no need to calculate the length of each path, and this helps a bit.
The data relative to the possible passages to the next districts will be then used in run-time to check which passage to select to go to the next district. If there are more than one passages that traverse the district toward the next one, the NPC mind should decide which to use. How? You should use the same filters adopted to the district level of the path finding, but I suggest to use one or two, between the sensation length and the distance of the passage respect to the direct line toward the target.
When you have the initial part of the inner path (where the NPC is entering into the district, or where the NPC is placed) and the passage to the next district, or where the target is placed, you shall select the path to use to arrive to your next path finding goal. Even in this case, you should use the filters already discussed. It's up to you to decide which of them, or use all.
Note, though, that this way of thinking, from the NPC, is not the right way if your project is a tactical war game. The tactical war game is one of the rare situations in which the paths could be already well known by each NPC "at the table". In this case, then, a good solution remains one of the correct, only-logic approaches. The only filter you should add is the arousal level of the emotions currently lived by the NPC (arousal is, for emotions, something similar to the volume for the music). This is, though, an issue not directly managed by the PF system, even if it could change the reasoning phase of an NPC about the best path find selection.
Nonetheless, you could easily note that the Biological approach should be faster than the current ones, because the actions to be executed are lightweight, and with a reduced amount of nodes in the graph, even thanks to the division of the paths into two levels (see the first article for more info).
Conclusion
The biological approach to a path finding, inherent in the Biological Path Finding, can be used not only for humans, zombies, monsters and aliens, but even for intelligent animals and, using the right limits, with any other kind of animal.
Nonetheless, never underestimate the role of emotions under the path finding issue. Even ability to take decisions, like the one explained in this article, is a feature made not only by logic. As a confirmation of this statement, Plutchik said that emotions are basic adaptations needed by all organisms in the struggle for individual survival (1980, p. 145). He suggested that the selection occurred in the Cambrian era, 600 million years ago. The eight adaptations are incorporation, rejection, destruction, protection, reproduction, reintegration, orientation and exploration. This means, also, that the most important filters of the Mental Navigation, emotions, are shared with a wide variety of animals.
So, what differs from humans way to solve a path finding to the ones of animals? The difference is rather small, and is only related to the use of logic. This is not entirely true, but the causes of this are so profound and so difficult to be reproduced in code that I prefer not to mention it in this context.
Most animals are unable to use training to better govern their emotions, and they are also unable to take into consideration more than one deduction relative to the filters adopted. If you want to differ the human behaviour to the animal one, toward the decision for the path selection, use only one filter for the simplest animals, and then apply other filters as you are facing more intelligence animals. The only filter you should always use is the one relative to the selection of only the paths whose first focal point is toward the direction of the target.
The next article will be focused on the Mental Map, Dynamic Object Avoidance and Smoothing movements.
Article Update Log
14 Mar 2014: Title modification, moved the image as an attachment, some other changes
10 Mar 2014: Initial release