Path Finding for innovative games: Graph Creation and Best Path Selection
Path Finding issues have the same models from several years: navigation meshes, navigation grid and waypoints navigation for building the graph, A*, Sample, Dijkstra as 'already classic' algorithm. The advent of a new awareness, whom states that the logical approach to simulate humans is not the best way to solve the PF issue, is bringing new freshness for the AI world. The topic of this article talks about a radically new approach.
Graph Creation
NavGrid or the NavMesh models are enough and good, without any customization, in several circumstances. If you want to build a single video game a time, for a video game similar to others, they can be perfect for you. If you have few NPCs living together, and you don't mind that they sometimes (or often) do what humans never do when walking, there is no reason why you should find for something better. Conversely, the future of video games will not use NPCs with a less-than-good human behaviour. Newer models should provide new features without the need to customize, to have better performance. The current Navgrid and Navmesh models have good pros, but even stronger cons. Both could make, in several circumstances, long time for the off-line calculations. You should not use them when there are several NPCs living together in a wider level. If you want your game go fast, or if the correctness of the human behaviour is a must, you shall find something new and different. Besides, it's not recommended the use of Navgrid for wider 3D levels, whom also develop in height. The use of the Navgrid in that context raises connections a lot, letting the path calculation be even more complex, with obvious performance issues. Waypoints in the reality: the focal points Can waypoints have a counterpart in the reality? You know that waypoints, or any kind of polygons that form a navigation map, are fundamental for NPCs to move across levels. Probably you never thought that also humans and animals need to have similar references when they move in the reality. A real human, with his needs, have to have a limited number of "strategic" positions along a path. Please put your attention to a real path. For instance, a path inside a building. You know that no living being can go straight to its target, unless it is in an open space. It has the need to change direction. Do you think we can find a rule with which reproduce the positions in which a real living being should necessarily change its direction? The goal is considering only points where a human need usually to change his direction. These points can be next to a corridor, between two neighboring columns, a doorpost and so on. Micro-environments If you take a look at an environment, especially a human-made one, you can see there are some parts where the passage is narrower respect to the contiguous parts of the environment (see the figure 1). Two walls forming a corridor make a micro-environment; a doorpost is a thin micro-environment; a column close to a wall or to another column forms a micro-environment. There can be different ways to build the Mental Map and, then, identify micro-enviroments. One of the easier (and the faster, in case you have one or more wider zones in the level) is possible thanks to the launch of linecasts from a series of points defined in the environment. The first thing to do is checking whether the reference point is inside an object or not. Only the reference point outside objects will be considered. There will be a point each X units of measure. The X is a value compatible with the width of the species of NPCs. I named this approach Radar Node Generation, because it emulates the way with which a moving radar builds up its representation of the environment. This solution simulates the behaviour of our mind when, the first time we walk a new path, records positions, clutters and so on. In the reality, our mind don't record all the positions in which we have been (as stated by Lynch). On the other hand, the approach I have proposed emulates, also, the ancient behaviour of our mind (shared with all living beings whom owns eyes) whom calculates the spaces between clutters. The algorithm will launch two linecasts from each single point: one to its left and one to its right, both toward the farthest point. The implementation of this approach can vary. Anyway, see the figure 2 for an example. We then need to check whether there is a collision with a closer object respect to the previous or the following point along the series. If, for example, the previous point hasn't found any closer object on the right of it, and the current point has found one, we could clearly state there is (from this point on) an object closer to the point. We should/could made this action in length, width and height. Nevertheless it depends on the level complexity, and is up to the developer. There are several tips that makes the action performance-compliant, but it's not the place in which to talk about it.
Figure 1
Figure 2 - paths: the streets, sidewalks, trails, and other channels in which people travel;
- edges, perceived boundaries such as walls, buildings, and shorelines;
- districts, relatively large sections of the city distinguished by some identity or character;
- nodes, focal points, intersections;
- landmarks, readily identifiable objects which serve as external reference points.
We can have one or two entrances for a micro-environment.
2- VisibilityA micro-environment is such if the focal points created at its limit or inside it see one each other. For example, a corridor formed by two big objects, placed in the middle of a wider place, leads the design-time elaboration create two focal points, each at the beginning (or ending) of the corridor. Where the focal points of the micro-environment can't see one each other (in case of a rounded corridor, for instance), we should add one or more new focal points along the micro-environment. In this way, each focal point can see at least one other focal point.
3- Two become OneIf the micro-environment is small, speaking about one dimension (horizontal or vertical) referred to the size of a medium NPC (for instance, between two columns), instead of creating two focal points, the algorithm will create only one. This resultant focal point will take place in the middle of the space between the deleted focal points. For instance, look at the two doorposts in the Figure 1, where you can see the result of this postulation.
4- Radius Distance toward static objectsConsider a user-defined radius distance between the static object of the level and the limit of the surface. This could help in avoiding to have lines between focal points that collides with static objects.
5- Follow the last visible Focal PointFocal points are the only parts of any zone that humans and animals consider, in a path, when they need to change direction. However, during the movement along the path, the BPF (Biological Path Finding) states the agent will go not toward the next focal point, but toward the "last focal point", along the path, the agent can "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.
Figure 3 - A faster off-line calculation of the single graph, respect to the current ones*.
- Ability to use multi-genre paths for NPCs, by 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 "believable best path"**
- Resolve the problem of the dynamic objects along the paths with no added complexity
- Find multiple targets even of the same species (for example, shelters and bulky objects)***
- 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****
Believable Path Selection
District Best Path Selection BPF is so different respect to the classic, "only-logic" approach, that work better without any use of the current algorithms used to find the shorter path. It's worth not going into details, for this issue. However, there are several factors for which the filters can bring to select a single path with no help of other algorithms. For example, the weight of emotions, mental map errors, the traits of NPC species or the limited number of levels, will usually bring to have only one path that overcomes all the filters. For example, a wide level could use 10 districts (see my previous article for more details). Normally, each district could have four other districts connected to them (unless the level develops even in height). Unless the level is a sequence of districts, or the level is huge, it's rare that the target is distant more than two districts from the NPC. Usually, then, it's useless to adopt any calculation of the best path, about the District level (see the previous article). There is a simple and effective solutions to limit the number of paths that reproduces the human behaviour. Its goal is avoiding all the paths whose first district is not far from the straight line between the NPC and its target (presuming the NPC knows the map, at least broadly). After that, you should also remove the paths containing at least one district checked as "to avoid" for the species type of NPC. For instance, the decision-making system or even the developer in design-time should flag the district as "to avoid" (or even the developer in design-time):- If a district is full of dangerous monsters that can kill the NPC.
- If a district is full of micro-environments non-viable, or is viable with difficulty for that NPC species.
- If the path contains a darker zone, and the personal traits of the NPC (if available) depicts it as a non-courageous individual.
Figure 4 An example of a focal point and its two flags suggesting the type of the two adjoining micro-environment. - Only the district paths whose first district is not far from the direct line between the NPC and its target
- Only paths without "to avoid" districts
- Sensation of the Length of the Path
- Only paths with known districts
- Take the path with the lower number of districts or/and consider the higher number of district traversed by the direct line between the NPC and its target
A1 - select one side of the district where there is at least one passage to the adjoining district
A11 - For each passage, check if there is a path that conduct to another adjoining district. If so, flag the passage as compatible with the passage to that district (in the way you wish).
There is no need to calculate the length of each path, and this helps a bit. The run-time part of the BPF will use the data relative to the possible passages to the next districts, to check which passage to select for going 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. Anyway, I suggest to use one or two, between the sensed length and the distance of the passage respect to the direct line toward the target. To start the run-time selection of the inner path, you need to know the early part of the inner path and the passage to the next district. The former is where the NPC is entering the district, or where the NPC is placed. When you have both, you shall select the path to use for arriving 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 of the NPC is not the right way if your project is a tactical war game. The tactical war game is one of the rare cases 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 level of arousal 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 direct managed by the PF system. Nonetheless, you could easily note the Biological approach should be faster than the current ones. The reasons I affirm that is because the actions executed by BPF are lightweight. In fact, in any case there is a reduced number of nodes in the graph, even thanks to the paths leveling (see the first article for more info).Conclusion
The biological approach to a path finding, inherent the Biological Path Finding, is an innovative solution not only for humans, zombies, monsters and aliens simulation, but even for intelligent animals. Nevertheless, never underestimate the role of emotions under the path finding issue. Even the ability to decide, 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, was responsible for most of our emotions. The eight adaptations are incorporation, rejection, destruction, protection, reproduction, reintegration, orientation and exploration. This means, also, that a wide variety of animals can share the most important filters of the Mental Navigation. So, what differs from humans way to solve a path finding to the ones of animals? The difference is rather small, and is specifically related to the use of logic. This is not entirely true, by the way. Nonetheless, the causes of this are so deep and so difficult to reproduce in code that I prefer not to mention. Most animals cannot use training to better govern their emotions, and they are also unable to consider more than one deduction about the filters adopted. If you want to distinguish the human behaviour to the animal one (or among animals with different intelligence) toward the decision for the path selection, use only one filter for the simplest animals. Then, apply other filters when you are facing with humans (or more intelligence animals). The only filter you should always use is the one about the selection of the paths whose first focal point is toward the direction of the target. A last consideration I wish to put into the article is the following: as you could state, the two (or more) level Path Finding requires you to have a Decision-Making system whom allows NPCs have more levels of goals. This is another important issue to bear in mind when you chose the BPF. The next article will focus on the Mental Map, Dynamic Object Avoidance and Smoothing movements.References
Byrne, R. W. (1979) Memory for urban geography. Quarterly Journal of Experimental Psychology 31, 147-154 Hirtle, S. C. and Mascolo, M. F. (1992) The heuristics of spatial cognition. Proceedings of the 13th annual conference of the cognitive science society. Hillsdale, N: Erlbaum 1992, pp. 629-634 Lloyd, R. and Heivly, C. (1987) Systematic distortions in urban cognitive maps. Annals of the Association of American Geographers 77, 191-207 Lynch, K. (1960) The Image of the City. Cambridge MA: MIT Press. Maki, R. H. (1981) Categorization and distance effects with spatial linear orders. Journal of Experimental Psychology: Human Learning and Memory 7, 15-32 McNamara, T.P. (1986) Mental representations of spatial relations. Cognitive Psychology 18, 87-121 Moar, I. and Bower, G. H. (1983) Inconsistency in spatial knowledge. Memory and Cognition 11, 107-113 Plutchik, R. (1980). Emotion, a psychoevolutionary synthesis. New York: Harper and Row. Sadalla, E. K. and Montello, D. R. (1989) Remembering changes in direction. Environment and Behavior 21, 346-363 Sadalla, E. K. and Staplin (1980) The perception of traversed distance: Intersections. Environment and Behavior, L. J. 12, 167-182 Tversky, B. (1993) Cognitive Maps, Cognitive Collages, and Spatial Mental Models. In Frank, A.U. and Campari, I. (Eds.) Spatial Information Theory: A Theoretical Basis for GIS, Proceedings COSIT '93. Lecture Notes in Computer Science, 716, pp.14-24, Springer: Berlin.Article Update Log
19 Mar 2014: Added References 19 Mar 2014: General updating for ease the reading 18 Mar 2014: Change the figure 4, added other 2 images, adde a description of the term micro-environment 14 Mar 2014: Title modification, moved the image as an attachment, some other changes 10 Mar 2014: Initial releaseRelated Tutorials
What To do If Your Game Received a Copyright Complaint
This tutorial explains how to respond to copyright complaints and why you shouldn't be scared of Apple's emails. It inc…
Video Game PR Basics
A brief guide to the very basics of video game public relations.
Felicia McEntire
Building a Discord
Mega Cat Studios walk us through the journey the followed in setting up their Discord server.
Mega Cat Studios
Publishing 103 - What Publishers Look For in Games
A detailed look at what publishers want from a game, and the materials that you as a developer should have prepared.
Publishing 102 - How To Find The Best Publisher For You
In this article, I will be detailing the tactics you should use while you are on the search for the best publisher. It’…
A Guide to DIY Market Research for Indie Game Devs
Ah, market research. Just seeing those words probably sent shivers down your spine. Market research for indie game devs…
Discussion
More from Giovanni Guarino
Path Finding for innovative games: Navigation
The current main approaches to the path finding issue are good for simple and classic games, but not for innovative one…
Path Finding for Innovative Games: Object Avoidance and Smoothing Movement
This is the last of three articles that treat a new approach for the Path Finding. It's a part of the studies and exper…
Discussion