Reading Notes-ai in Game Development-Chapter 6th-basic path searching and flight point application

Source: Internet
Author: User

1. Basic path search

At the most basic level, path searching is just a process for a game role to move from its initial position to the desired destination. Essentially, this is the same as the basic pursuit Algorithm in Chapter 2. For example, the simple chase method (the simplest way to make coordinates gradually the same) and the line of sight (using the breseman method ). However, if there are obstacles in the game environment, you need to consider other things. As shown in, the paths produced by the two methods may be intercepted by obstacles.

1.1 move randomly to avoid obstacles
This method is suitable for situations where there are few obstacles. For example, there are not many trees in the environment. If you move a giant at will, players will be able to see the giant. This method is simple and effective, avoiding the CPU consumption caused by the routing algorithm.

If (players in sight ){
Use a straight-line path to move players
}
Else {
Move in random direction
}

1.2 bypass Obstacle

Bypassing obstacles is another simple method to avoid obstacles. This method is quite effective when you want to find a path to bypass large obstacles in a strategy game or role-playing game, such as bypassing mountains.
Method Description: · assume that the unit sees the destination through the obstacle, but cannot cross the obstacle to reach the destination.
· Let the unit go straight toward the destination. When encountering an obstacle, it will go along the edge of the obstacle.
· When there is no obstacle between the obstacle and the destination, move toward the obstacle.

2. Search for paths with bread chips

The breadcrumb path search method makes the computer-controlled role look very intelligent, because it is a path that players unconsciously control for the computer-controlled role. Every time a player takes a step, there will be unknown marks or crumbs in the game world. When a game role encounters breadcrumb, it can continue with the breadcrumb. The game role follows the player's footprint until it catches up with the player.
The bread method is also an effective way for computers to control the movements of roles in groups. It is not necessary for every member of the group to search for the path through a laborious path, so that Members can directly follow the breadcrumb left by the creator.
Thinking: whether a role is intelligent depends on whether the player's path is intelligent. If the player turns into a circle and then goes out, the role will completely copy the player's path, which is less intelligent. This is also true for groups of units. If the units follow the routes of the consumers, there is only one route, which is too monotonous. The key is to find the appropriate use cases.
In fact, the example in the book does not completely copy the path of the target unit, but searches for the newest adjacent breadcrumb path every time. This figure is too vague to be uploaded. In this way, a little optimization is made in the player's route.

3. Find the path

Path searching is generally considered to be a problem from the starting point to the destination to be reached. However, in many cases, even if there is no final destination in the game environment, it is necessary to move the role controlled by the computer in a realistic way. For example, a computer-controlled racing car must move along the racing Lane. Similarly, in strategy games, troops may need to patrol the towns. For example:

The terrain element marked as 1 is regarded as a road, and the terrain element marked as 2 is regarded as an area outside the road boundary. We don't want giants to move randomly on the road. This kind of result looks unnatural. We want them to look like they are walking along the road. Therefore, we need to analyze the surrounding terrain to determine the path of giants.
The core idea is to follow the previous step as much as possible. For example, if the previous step is in the upper left corner, eight values are given for the eight directions. The weights in the upper left corner are + 2, and the weights in the upper and left sides are both + 1, the value in the lower right is-1, and the value in other directions is 0. Sort the values in the eight directions in ascending order. Then, select the largest value and the location where the terrain can be reached as the next step of the path. The most likely is to continue along the top left, and the least possible is the original return.

4. Walk along the wall

Similar to following the path, this method does not calculate the path between the start point and the end point. Walking along the wall is more like an exploration technique. Sometimes, it is necessary for a computer to control the role exploration environment to search for players, weapons, fuel, treasures, or anything that any game role can access. Making computer-controlled roles move randomly in the environment is the most common method for game developers. For example:

A simple method: move on the left. That is to say, every time giants always try to move to the left, so that they can make a more complete exploration of the environment. However, the left-side movement method does not guarantee that giants will enter every room in the game environment.

5. Navigation

Path searching is a very time-consuming computing task that consumes CPU resources. One way to reduce this problem is to calculate the path as soon as possible. To reduce this problem, you need to carefully place nodes in the game environment, and then use pre-calculated paths or simple path search methods to move between nodes. For example:

Note that each vertex in the graph can at least display the sight of another node. In this way, game-controlled roles can always use simple line of sight algorithms to reach any location in the figure. The next step is to define the relationship between these nodes.

With this path relationship, the shortest distance between two points can be achieved using Dijkstra algorithm or Floyd algorithm.

6. End
Each method discussed in this chapter has its own advantages and disadvantages, and the scope of use is often limited. The A * algorithm to be introduced in the next chapter can be applied to most path searching problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.