Path Planning For Games∗ Mark H. Overmars Institute of Information and Computing Sciences Utrecht University, The Netherlands [email protected] ABSTRACT In games entities move around and must find their routes to various locations. These routes must be collision free, natural, and computed very fast. This is a major challenge and many games solve this by using precomputed waypoints, scripting, or simple but fast methods based on grid search or potential fields. Also very often they cheat or accept the fact that characters walk through objects. The problem becomes even more complicated when entities in games must move in groups. They should behave as a natural group does, but the flocking techniques that are often exploited for this can lead to rather unexpected and unwanted results. Path planning is a challenging problem to solve for a number of reasons. Paths must avoid obstacles and be relatively short, leading to a difficult combinatorial problem in an environment that consists of a huge number of obstacles. When entities have multiple degrees of freedom, the dimension of the space of motion (often called the configuration space) becomes large, adding to the difficulty. Constraints on the motion, like the non-holonomic constraints involved when steering a car, complicate this even further. And finally paths must be natural, that is, they should look similar to paths taken by humans or animals. This in particular is complicated when there are multiple moving entities, like an army of soldiers or a flock of animals. In this paper we discuss a different approach to path planning that has been developed primarily in the area of robotics. This technique can efficiently deal with moving entities in very complicated scenes and can guarantee path quality and clearance constraints. This is achieved by combining automatic preprocessing on the static part of the scene and adaptation to dynamic changes during path execution. We will also show how such techniques can be applied to the motion of groups of entities and how they can effectively be combined with the animation. Paths must be computed in real time. Only a small percentage of the processing time is available for path planning. This requires fast techniques that are often based on preprocessing. In current games path planning is usually done using a combination of scripted motion, using for example waypoints, grid-based A* techniques, local methods for obstacle avoidance, and flocking for group motion (see e.g. [4, 18]). 1. INTRODUCTION Path planning, also termed pathing or motion planning is a crucial ingredient in computer games. Path planning occurs at many places in games. Clearly, computer controlled entities must find their routes to various locations to perform certain actions. But also the avatar controlled by the player must find collision avoiding paths; in particular when avatar control is indirect. And finally the camera through which the player observes the game world must move around. ∗This research was partially supported by the IST Programme of the EU as a Shared-cost RTD (FET Open) Project under Contract No IST-2001-39250 (MOVIE - Motion Planning in Virtual Environments) and by the Dutch BSIK/BRICKS project. Although fast, current techniques lead to many errors. For example, in many strategy games, vehicles do not obey the non-holonomic constraints and rotate on the spot. In other games characters walk through obstacles or get stuck. And often characters take rather stupid routes that e.g. bring them close to enemy units. With group motion this becomes even worse. Characters walk through each other, behave in very unnatural ways, and choose bad individual paths, not respecting the group goals. See for example Figure 1. Now that graphics in games is become very realistic it is getting increasingly important that character behavior also becomes more realistic. A player is much less willing to accept unnatural motion in a realistic environment than in a non-realistic environment. So new techniques for path planning are required that lead to better motion. Path planning has been studied for a number of decades in the robotics community. See for example the books of Latombe[12] and LaValle[13]. Many different techniques have been designed. Unfortunately these cannot be directly transferred to the game world as the conditions in robotics are rather different. For example, the complexity of the environment is often a lot smaller, the number of degrees of freedom is higher, and there is more processing time avail- Figure 1: One of the problems with the current techniques for motion planning for multiple units is that the group splits up to reach the goal. This scene was taken from Command and Conquer: Generals from EA Games. able. Fortunately, recently there is a move toward applying the techniques for robotics to path planning in virtual environments and games, for example in the EU funded MOVIE project (Motion Planning in Virtual Environments, see www.movie.nl). In this short note we will give a brief introduction into some of the most promising approaches. In particular we will focus on the probabilistic motion planning (PRM) method. This method is flexible and has been successfully applied in many different contexts. It uses preprocessing to build a roadmap of possible motions which can at runtime be used to instantly compute a required path. We will describe the basic approach and then give some insight in a number of extension that are important for path planning in games, in particular techniques for creating high-quality roadmaps, using corridors, dealing with group motion, exploiting the relation between path planning and animation, and the incorporation of tactical information in path planning. 2. CREATING ROADMAPS The first step in the motion planning approach we propose is the construction of a roadmap. We base the roadmap construction on the probabilistic roadmap method (PRM) that we will briefly describe. It has been studied by many authors, see e.g. [11, 19, 10, 5]. In a preprocessing phase, a roadmap of possible motions for the entities is computed. This roadmap is represented as a graph in which the nodes correspond to placements of the entity and the edges represent collision-free paths between these placements. We will describe a simple version in which only the position (x, y) of the entities is taken into account when planning the motion. The PRM method can though work in arbitrary configuration spaces. Basically the PRM method works as follows. We start with an empty roadmap graph. Randomly a collision free placement p is taken. This is added as a node to the graph. Next a number of nearby nodes in the graph is selected. For each of these nodes n we first test whether n is in the same connected component of the graph as p. If not we test whether a simple, straight line motion between p and n is collision free. If so we add this motion as an edge to the roadmap graph. We repeat this process until the graph is dense enough and its connectivity represents the connectivity of the space. This roadmap is computed in a preprocessing phase. It requires only simple operations, in particular collision checks to see whether a placement or a straight line motion is collision free. This makes it fast and easy to implement. During the game the roadmap is used for answering path planning queries as follows. When a path between a start placement s and a goal placement g is required, we first try to connect s and g to the roadmap by determining some nearby nodes in the roadmap and checking whether a straight line motion is collision free. Once we have connect both nodes to the roadmap we compute a path through the roadmap from s to g. This path in the graph then corresponds to a collision free motion through the environment. If s and g cannot be connected we report that no path exists. (It can be proved that, provided that the roadmap is dense enough, the method will only fail when no path exists.) Even though fast to compute the PRM method leads to low quality roadmaps in which paths can take long detours. This is due to the random nature of the PRM method. Techniques exist to improve paths in a postprocessing stage but this is time-consuming and can still lead to long detours. Many improvements for the PRM method have been proposed (see e.g. [1, 2, 17, 20, 6, 3, 7]), but all are based on the same underlying concept and lead to roadmaps consisting of straight line segments only that result in low path quality. It is though possible to create much better roadmaps in a relatively easy way. This is based on the following ingredients. We create nodes that lie far away from obstacles by sampling near to the Voronoi diagram. This will result in roadmaps that have a high clearance, which is normally a preferred properties. Secondly we will add additional edges to create cycles in the roadmap graph using a technique from [16]. This will avoid long detours. Finally, we allow for both Figure 3: A corridor for a path, with an upperbound on the disk radius. Figure 2: An example of a smooth roadmap computed by our technique. straight line motions and circle arcs. We will make sure these are properly aligned to avoid second order discontinuities in the motion. This is achieved as follows. Once the roadmap is ready we add a center node halfway each edge. Next we remove the original nodes and replace them by smooth paths between the center nodes. For details see [14]. See Figure 2 for an example. Such roadmaps can be used in the query phase without the need for any postprocessing. 3. USING CORRIDORS Moving along the roadmap is not the ideal solution to motion planning. It leads to predictable motions and makes it impossible to take small obstacles or other moving entities into account. To remedy these problems we introduce the notion of corridors. Given a point p on the roadmap (either a vertex or on an edge) let dp be the largest empty disk around p, that is, the largest disk that does not intersect with an obstacle. (Normally we also put an upperbound on the radius r of the disk.) The corridor for an edge e of the roadmap is now the union of the disks dp of points p on e. In the same way we define the corridor for a path in the roadmap. See Figure 3 for an example. The corridor information can easily be computer during the preprocessing phase, and stored with the roadmap. Rather than moving along a path in the roadmap we will move within the corridor around the path. This gives the flexibility we want. If we want to plan the motion from a start placement s to a goal placement g we first determine a point ps and pg such that s ∈ dps and g ∈ dpg . (If s or g do not lie in a corridor we can easily locally extend the roadmap.) Next we compute the shortest path Π in the roadmap graph from ps to pg . We create an attractor point a which will start at ps and moves along Π to pg . We use a potential field approach to attract our moving entity to the attractor point p in such a way that we are guaranteed that the entity stays within the corridor around Π. This can easily be achieved by basing the attracting force on the radius of the disk da . Additional constraints on the motion of the entity can now easily be incorporated in the potential. For example, it is easy to create additional forces that make sure the entity avoids small obstacles or other entities in the corridor. Also e.g. non-holonomic constraints can be taken into account, assuming that the corridor is wide enough. 4. GROUP MOTION Games are often populated with a large number of moving entities. The entities should often behave as a coherent group rather than as individuals. For example, one needs to simulate the behavior of whole army divisions. Current games solve the problem of path finding on the entity level, i.e. they plan the motion of individual entities, using techniques like flocking to keep the entities together. However, in cluttered environments this often leads to non-coherent groups. There is no guarantee that the entities will stay together. Even though the entities all have a similar goal, they try to reach this goal without real coherence. This results in groups splitting up and taking different paths to the goal. We will briefly describe a technique in which groups do stay together. More details can be found in [8]. So we are given a game level in which a group of entities must move from a given start to a given goal position. The entities must avoid collisions with the environment and with each other, and should stay together as one group. Our solution follows the global approach outlined above. We first compute a roadmap with high clearance, together with the corridor information. During the query phase we compute a path in the roadmap and the corresponding corridor. Once the corridor is created, we need to use it to generate the motion of the individual entities. The approach used is an artificial force field technique. Forces are defined that act on the entities and influence their movement. Every entity in the group has a corresponding attraction point on the path. This attraction point is selected as the maximum advanced point p along the path such that the entity is still inside the disk dp . The attraction points make the entities move forward and keep the entities inside the corridor. The entities also repulse each other to avoid collisions between them. Additional forces could be incorporated, for example For example, we already saw that it might help to pick placements far away from obstacles to increase the clearance. In other situations though you might want your units to stay close to obstacles to avoid detection. This can easily be achieved by picking other nodes and choosing other neighbors. We can also change the local method, for example to take terrain features into account, to obey the nonholonomic constraints of vehicles[11], or to create pleasant motions for a camera[15]. Secondly, we can change the way the corridors are computed. Depending on the type of application we might want to restrict ourselves to very narrow corridors. Also we can make sure that corridors have a certain minimal clearance from the obstacles to take the size of the entities into account. Figure 4: A group moving through an environment. to accomplish formations. In order to keep the group coherent the dispersion should be upper bounded. Due to the manner in which the corridor is constructed, the lateral dispersion (dispersion perpendicular to the backbone path) is automatically upper bounded by the chosen maximal disk radius. However, the longitudinal dispersion (in the direction of the backbone path) is not yet bounded in this approach. To achieve this, the distance along the path from the least advanced attraction point to the most advanced attraction point is limited. This results in the entities in front waiting for the entities at the back. The behavior of the group can be controlled by adjusting the coherences parameters, lateral dispersion and longitudinal dispersion, resulting in a longer, more stretched group or more compact groups. Figure 4 shows an example of a group moving through an environment from the left lower corner to the right upper corner. The most advanced entities, i.e. the entities that passed the narrow passage earliest, wait for the last entity to pass the passage. We tested the performance of the approach to show that the technique is usable in real-time applications as computer games. For this, we developed a typical implementation. In this implementation we created numerous paths. The processor usage to create the paths was very minimal. For groups of 50 to 100 entities the processor usage did not exceed 1 percent. More efficient implementations could further decrease the processor usage. 5. FURTHER EXTENSIONS One of the powerful features of the approach outlined above is that it is very flexible. First of all, we can adapt the way the roadmap is constructed. The method has three important ingredients: selecting new placements to add to the graph, selecting the set of neighbors, and the local method that is used to connect nodes. In the basic PRM method we pick random placements, select neighbors based on distance, and use a straight line motion for connections. But we can make different choices to adapt the approach to our needs. Thirdly, we can change the way a path, and hence a corridor, is selected. In our description above we used the shortest path, but we can also take for example the width of the corridor into account. Or we can incorporate tactical information to avoid dangerous places as much as possible. And finally we can change the potentials that are used to determine the path through the corridors. Rather than moving close to the center of the corridor it can for example be advantageous to stay close to the boundaries. Also we can again incorporate tactical information, for example, by adding forces that push entities away from potential dangerous places and to let groups maintain certain preferred formations. Let us briefly describe one particular extension to take animation constraints into account when planning paths. See [9] for more details. A walking character is normally represented by a number of different animations, each corresponding to a different speed and turning angle. The actual motion is calculated by interpolating between such animations. The animations span a region R of the space of possible combinations of speed and turning angle. Animation outside this region R can only be achieved by extrapolation which normally has poor results. So we should constrain the path to lie within R and preferably not even close to its boundaries. We can incorporate this in the PRM approach in different ways. First of all we can generate a roadmap that only consists of paths that satisfy the constraints. This can be achieved by adapting the local method. The disadvantage is that this would require a different roadmap for each character. The alternative is to use the corridors. We can define forces on the moving character that guarantee it to stay inside the region R of preferred animations and adapt the speed of the character when this is required to satisfy the constraints. It turns out that the resulting animations are a lot better. This can even be combined with group motion. 6. CONCLUSIONS In this short note I have given some insight in the possibilities of path planning techniques that originated from robotics for use in games and virtual environments. By creating high quality roadmaps we can achieve instant query responds during the games, leading to high quality paths. Using the notion of corridors and attraction points, in combination with a local potential field approach enables us to incorporate small changes, deal with other entities, guide the motion of groups of entities, and even take constraints on animation and tactical information into account. Clearly the techniques presented do not yet provide a readyto-use off-the-shelf solution to all path planning needs. A lot of research is still required to achieve this. But I hope you are at least convinced that there are more solutions to path planning than grid-based A* algorithms. 7. REFERENCES [1] Bohlin, R. and L. Kavraki (2000). Path planning using lazy prm. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 521–528. [2] Boor, V., M. Overmars, and A. van der Stappen (1999). The gaussian sampling strategy for probabilistic roadmap planners. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 1018–1023. [13] S. M. LaValle (2006). Planning Algorithms. Cambridge University Press. [14] Nieuwenhuisen, D., A. Kamphuis, M. Mooijekind and M.H. Overmars (2004). Automatic construction of roadmaps for path planning in games. In Proceedings CGAIDE 2004: 5th Game-On International Conference, pp. 285–292. [15] Nieuwenhuisen, D. and M. Overmars (2004a). Motion planning for camera movements. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 3870–3876. [16] Nieuwenhuisen, D. and M. Overmars (2004b). Useful cycles in probabilistic roadmap graphs. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 446–452. [17] Nissoux, C., T. Siméon, and J.-P. Laumond (1999). Visibility based probabilistic roadmaps. In Proc. IEEE Int. Conf. on Intelligent Robots and Systems, pp. 1316–1321. [3] Branicky, M., S. Lavalle, K. Olson, and L. Yang (2001). Quasi randomized path planning. In Proc. IEEE Int. Conf. on Robotics and Automation. [18] Russell, S. and P. Norvig (1994). Artificial Intelligence: A Modern Approach. Prentice Hall. [4] DeLoura, M. (Ed.) (2000). Game Programming Gems 1. Charles River Media. [19] Švestka, P. and M. Overmars (1998). Coordinated path planning for multiple robots. Robotics and Autonomous Systems 23, 125–152. [5] Holleman, C. and L. Kavraki (2000). A framework for using the workspace medial axis in prm planners. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 1408–1413. [20] Wilmarth, S., N. Amato, and P. Stiller (1999). Maprm: A probabilistic roadmap planner with sampling on the medial axis of the free space. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 1024–1031. [6] Hsu, D., T. Jiang, J. Reif, and Z. Sun (2003). The bridge test for sampling narrow passages with probabilistic roadmap planners. In Proc. IEEE Int. Conf. on Robotics and Automation. [7] Isto, P. (2002). Constructing probabilistic roadmaps with powerful local planning and path optimization. In IEEE/RSJ Int. Conf. on Intelligent Robots and Systems, pp. 2323–2328. [8] Kamphuis, A. and M. H. Overmars (2004). Finding paths for coherent groups using clearance. In Eurographics/ACM SIGGRAPH Symposium on Computer Animation, pp. 19–28. [9] Kamphuis, A. J. Pettre, M.H. Overmars, and J.-P. Laumond (2005). Path finding for the animation of walking characters. In Poster Proceedings Eurographics/ACM SIGGRAPH Symposium on Computer Animation, pp. 8–9. [10] Kavraki, L. and J.-C. Latombe (1994). Randomized preprocessing of configuration space for fast path planning. In Proc. IEEE Int. Conf. on Robotics and Automation, pp. 2138–2139. [11] Kavraki, L., P. Švestka, J.-C. Latombe, and M. Overmars (1996). Probabilistic roadmaps for path planning in high-dimensional configuration spaces. IEEE Transactions on Robotics and Automation 12, 556–580. [12] J.-C. Latombe (1991). Robot Motion Planning. Kluwer.
© Copyright 2026 Paperzz