• # Path Finding for Innovative Games: Object Avoidance and Smoothing Movement

Artificial Intelligence

This article concludes the topic of Path Finding for innovative games. The model described is based on scientific evidences which assert that human intelligence is not made only by logic. The Biological Path Finding approach is still in the research phase, even if the writer already adopted it in a couple of games.

## Dynamic Object Avoiding

Nowadays, some game developers force their AI implementation to recalculate the best path when an object is intersecting the current path of an NPC. Fortunately, not all developers use this approach. The outcomes of that action, speaking in terms of credibility of the NPC and about performance, are definitely negative. Dynamic Objects in Path Finding is a strange issue, and in my opinion is a non-problem. We should first divide the issue into two main cases: 1. an object is moving toward the current path of an NPC 2. an object has moved and been placed along the current path of an NPC The way to react to these two cases should be different. In fact, if an object is moving, we have to worry about the possibility of a collision with this object. A possible collision, though, never should lead us to change the path, unless there is a high amount of moving objects in the same place. If this case happens, you shall check your game or simulation setup. In fact, a place in which there can be multiple moving objects should have lines of the graph with a higher weight. When an object (or another NPC) is moving toward a line of a path used by an NPC, the only problem to face with is avoiding it. This though must not change anything in the decision, already taken, of the path to follow. A similar problem you'll have with an object that has moved and placed along a line of the path used by an NPC. In this case, unless the object is so wide to block completely the passage, you need to treat it with the Object Avoidance algorithm. How should be a proper Object Avoidance algorithm for the BPF? There is no preference or precaution to consider. You should use the algorithm 'only' to avoid object. When the NPC has avoided the object, the algorithm must go to its end. After that, the Path Finding system will be active again, and the NPC will go straight toward its next focal point. What if the object that is blocking the path is so wide that makes impossible any trial to turn it? Do we need to find another path? I absolutely prefer avoiding this solution. Humans, when inside a real and physical problem, are not dominated by logic. Even if it's difficult to understand, emotions manages our actions. Only after having filtered events with emotions, we may think and then use logic. A human, when started on a path, if there is a problem along it, tries to imagine (not calculate!) a sub-path that helps him to turn the problem and continue along the same path. It's too complicated considering to change path, and the time is never enough for a human walking along the road. Only a danger can change this way to do, but it's something that has not to do directly with the path finding system. So, even in the worst case, there is no need to start the path finding calculation from the current position to the target. The correct solution for a proper human simulation is finding the "simplest" sub-path from the current position to the first focal point beyond the object, or using the Object Avoidance algorithm. In the human approach to the PF problem, there is never a sort of calculation, but rather estimations. Estimations consider the number of turns and the number of focal points: in our mind there is no continuous registration (like a video, for example) of the path, but only flashes about the focal points. Thus, if the human saw a map, he will have a better chance to make a better estimation of the length of each path. Any focal point is close to a micro-environment. This helps us, because it's impossible that an object occupies more than one micro-environment (unless is a giant object!).

## Smoothing Movements

Especially in case of complex or wide and open paths, I reckon that grid and mesh navigation don't give enough NPC credibility because of the number of nodes in the map. There are, substantially, four grades of quantities of nodes in a path:
1. Too few nodes, or/and placed in senseless positions: it's not possible for the NPC to walk as a human, and then it will have unpredictable results; [possible with the Waypoint approach]
2. Few nodes placed in the "focal points": the NPC reacts like humans do; [currently proposed only by Biological Path Finding];
3. Many nodes: the behaviour of the NPC is far from being similar to the one of humans. Without a good (and sometimes time-expensive) smoothing algorithm, the NPC will have a behaviour similar to one of a drunken man [can happen with the current navigation solutions].
4. Too many nodes (from dozens to hundreds of times more than the focal points): the behaviour of the NPC comes back to seem similar to the one of humans. The off-line and run-time calculations, though, become really expensive [can happen with NavGrid].
Take the example below.
Figure 1
You can see here the number of convex polygons (squares) made with the Navigation Grid and, below, the same map treated with the Mental Navigation, the Navigation made with the Biological Path Finding approach. You can see the number of nodes and relative lines that Navigation Map will create is higher in the current navigation approach in respect to the new one.
Figure 2
Another problem, for the current navigation approaches, is the need to make use of the smoothing algorithm almost for any line. For an approach that develops a high amount of nodes, this worsens performance. Mental Navigation needs the smoothing algorithm for any passage among focal points too. Nevertheless, the cost is minimal if referred to the overall time of execution of the current path finding approaches, because of the small number of focal points. There is now the need to cite another postulate of the BPF: if there is a static object or a ravine between two focal points referred to non-contiguous micro-environments, NPCs will use the Object Avoidance algorithm to move between those focal points (see the previous paragraph). This rule could even be substituted by another that, instead of using the Object Avoidance algorithm, moves one or both focal points in order to overcome the issue.

## The Mental Map

Mental Map is the approach for building a Navigation map that takes into account how humans (and animals) actually build the mental maps in their mind. In the previous section I already treated the most important part of this part of the module. Nonetheless, there are some factors you should consider before thinking how to implement the BPF. As I've written several times in some different places, human intelligence is not only logic. It's rather the contrary. Into the cauldron of intelligence there are other ingredients with an importance higher than logic. As the evidences of several findings made in biology and neuroscience can witness, intelligence is not owned only by humans. All primates have a high intelligence. Despite what you may think, a chimpanzee for example may use a language with 250 words! Other animals have a moderate intelligence, like dolphins and dogs. The base of intelligence is nearly equal among all these species. The human species, though, developed a multitude of "psychological adaptations" that animals don't have, or have in a simpler version. What I want to say is that logic is only the diamond tip of the biological intelligence, but it's far from being the unique ingredient. Emotions and several other factors are the very basic ingredient of intelligence, and without them we could not understand the world that surrounds us. What are the outcomes of this reasoning? Two facts: A) Humans, when the arousal* of one or more emotions is high or too low, tend to have non-logic behaviours; B) Animals, in terms of path finding approach, have almost the same way of doing things when faced with a path selection or an object avoidance. (*) - Arousal is, for emotions, something similar to the volume for a radio receiver. There has not been, so far, any complete model able to represent the whole world of intelligence. I mean, for whole world of intelligence, a module containing emotions, moods, sentiments, beliefs and personality traits, not to mention the age differences, social rules and hormones. This leads us to think that, at least for a while, BPF could not be implemented at its best.

## Conclusion

So, is it already possible to treat emotions in the Path Finding, in order to better simulate human behaviours? Maybe not immediately, I think, but soon. There are some guys trying to build a solid AI model (and I'm one of them, even if I follow a different, in some ways easier road than others). I reckon the time for a solution which simulates humans and animals behaviour with a higher reliability is coming. Anyway, you can even build an implementation of the BPF that makes no use of emotions. For the rest, you can find in the first and the second article the main ingredients of the Mental Map Navigation. The topic of the Biological Path Finding still belongs to the field of research, even if in these articles you can find the base for making successful implementations too. It's my intent to put on an Open Source project about BPF, to speed up the development of this new approach.

## Article Update Log

20 Mar 2014: An updating 19 Mar 2014: Initial release

Report Article

## User Feedback

Nice followup article, Giovanni. In future, I'd like to see more details on determining micro-environments. The BPF you described in this article would require real-time determination. Though you described micro-environment in the previous article, some practical approaches, perhaps with pseudo-code examples, would be an important aid for programmers.

##### Share on other sites

I reckon you're right, Buckeye. That's why I'm trying to completing the book about BPF with a practical approach, and I hope to start with a new Open Source project, for the first library that will help in using BPF, in April.

##### Share on other sites

One week ago I even knew what a path was. But I've seen some blogs and on told me that was just a lot of vertices (nodes) inside your scene. That was really exciting since I was thinking that was some kind of area in AI that involves a lot of complexity. I've studied A* on the college but the teacher doesn't say that the goal target in a A* problem is the player's position on the game and the enemy have to find the short distance in a path to find him. I'm just sharing a strange experience that may be kind of fun to someone. Anyway, nice article!

##### Share on other sites

A* finds a least-cost path from a given initial node (that, in game, is the closest node to the NPC) to one goal node (that, in game, is normally the closest to the PC). A* traverses the graph by following a path of the lowest expected total cost or distance. I dont' see where I told something different respect to that definition, in my article.

The issue of the A* is that is not able to make filters before making calculations. You need to calculate all the paths before knowing which is the best to use. With the Biological Path Finding you just need to filter paths with the common sense and,only for some of them,in case you remains with more than one still available, you make a sort of a draft calculation with some "on/off" relative the kind of micro-environments of each remained path.

So, the A* is a brute force, somewhat bovine approach respect to the BPF one, in the sense that you are forced to do all the calculations, even the ones that the common sense would propose you to avoid. Hope this could help better.

##### Share on other sites

Well, the second part of your discourse is clear, and right. The first part, though, I don't know if I well understood. In fact, BPF doesn't make any cost evaluatio, because humans can't do this as they have normally no cost data to use about the real possible paths. BPF only use filtering with the common sense, so I don't see similarities with the A* algorithm.

## Create an account

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 2
• 0
• 0
• 3
• 0

• 15
• 22
• 17
• 46
×