Map navigation method and device, electronic equipment and storage medium
By constructing a view map and calculating the distance and velocity direction information between the view grid and the player character, the problem of decreased navigation performance in large grid maps was solved, resulting in smoother navigation paths and a more realistic visual experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2023-11-16
- Publication Date
- 2026-07-24
AI Technical Summary
Navigation technology on large grid maps suffers from performance degradation in real-time games. Existing pathfinding algorithms such as A* and HPA* exhibit drastic performance drops on large maps, failing to meet real-time computation requirements and resulting in insufficiently smooth paths.
Map navigation information is generated by pre-calculation combined with map layering, and a vision map is constructed based on the player character's position. The distance and speed direction information between the vision grid and the player character are calculated to generate navigation information to improve the smoothness of the navigation path.
Navigation of objects within the player's field of view is smoother and the visual experience is more realistic. The smoothness requirement for navigation results of external objects is lower, reducing the amount of computation and improving the real-time navigation performance of large maps.
Smart Images

Figure CN117482519B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to a map navigation method, apparatus, electronic device, and storage medium. Background Technology
[0002] Grid maps are a commonly used map-building technique in computer games. Navigation technology on large grid maps is also a challenge in the field of real-time games. If the map is too large or there are too many units that need to find their way, the performance of real-time games will drop rapidly.
[0003] Currently, common real-time pathfinding algorithms include pathfinding data pre-computation and map layering. The pathfinding data pre-computation scheme involves calculating the pathfinding data for the map in advance, while the map layering scheme divides the map into different levels based on their level of abstraction to avoid excessive computation.
[0004] However, map layering algorithms only find local optima, resulting in less smooth pathfinding. Pre-computed pathfinding methods usually require a lot of memory, and if the map to be pre-computed is too large, this method is difficult to use directly. Summary of the Invention
[0005] The purpose of this application is to provide a map-based navigation method, apparatus, electronic device, and storage medium to improve the accuracy of local navigation.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows:
[0007] In a first aspect, embodiments of this application provide a map-based pathfinding method, including:
[0008] Obtain the position information of the player character in the current frame, including: map tile coordinates and grid coordinates within the tile;
[0009] Based on the player character's position information and the virtual camera's field of view, construct the field of view map corresponding to the player character in the current frame;
[0010] Determine the distance information between each grid in the field of view and the player character, and based on the distance information between each grid and the player character, determine the velocity direction information of each grid relative to the player character;
[0011] If the object to be navigated to in the current frame is located within the player character's field of view, then navigation information for the object to be navigated to in the current frame is generated based on the grid information of the object within the field of view and the velocity direction information of each grid relative to the player character.
[0012] Secondly, embodiments of this application also provide a map navigation device, including: an acquisition module, a construction module, a determination module, and a generation module;
[0013] The acquisition module is used to acquire the position information of the player character in the current frame, and the position information includes: map tile coordinates and grid coordinates within the tile;
[0014] The construction module is used to construct a field-of-view map corresponding to the player character in the current frame based on the player character's position information and the virtual camera's field of view.
[0015] The determining module is used to determine the distance information between each grid in the field of view and the player character, and to determine the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character;
[0016] The generation module is used to generate pathfinding navigation information for the current object to be pathfinded in the current frame if the object to be pathfinded in the current frame is located within the field of view corresponding to the player character, based on the grid information of the object to be pathfinded in the field of view and the velocity direction information of each grid relative to the player character.
[0017] Thirdly, embodiments of this application provide an electronic device, including: a processor, a storage medium, and a bus. The storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the map navigation method provided in the first aspect.
[0018] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the map pathfinding method as provided in the first aspect.
[0019] The beneficial effects of this application are:
[0020] This application provides a map pathfinding method, apparatus, electronic device, and storage medium. By acquiring the player character's position information in the current frame, a view map corresponding to the player character can be constructed. The distance between each view cell in the view map and the player character's view cell is calculated, and velocity direction information of each view cell relative to the player character's view cell is generated based on the distance. Therefore, when the object to be pathfinded is within the player's view map, the velocity direction information of the view cells relative to the player's view cell can be used for pathfinding navigation. Since the object to be pathfinded is close to the player character when it is within the view map, using the velocity direction information generated from the distance information for pathfinding navigation allows the generated velocity direction to point to the player character's location more quickly, resulting in smoother navigation. Consequently, when the object to be pathfinded follows the pathfinding navigation information, the pathfinding path is smoother, and the player character's visual experience is more realistic.
[0021] In addition, for objects that are not within the player's field of view, the navigation information of the objects can be obtained by searching for them based on the pre-generated pathfinding topology information of the game map. Since the objects are far away from the player when they are not within the player's field of view, the smoothness requirement for the pathfinding result is low. The pre-calculated pathfinding topology information can be used to quickly obtain the pathfinding navigation information, thereby reducing the amount of pathfinding data calculation and solving the problem of real-time navigation on large maps. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 A schematic flowchart illustrating a map-based pathfinding method provided in an embodiment of this application;
[0024] Figure 2 A schematic diagram of map grid coordinates provided in an embodiment of this application;
[0025] Figure 3 A flowchart illustrating another map-based pathfinding method provided in this application embodiment;
[0026] Figure 4 A schematic diagram of a field of view provided for an embodiment of this application;
[0027] Figure 5 A flowchart illustrating yet another map-based pathfinding method provided in this application embodiment;
[0028] Figure 6 This application provides a schematic diagram illustrating the distance display of field of view grids within a field of view in an embodiment of the present application.
[0029] Figure 7 A flowchart illustrating another map-based pathfinding method provided in this application embodiment;
[0030] Figure 8 A flowchart illustrating yet another map-based pathfinding method provided in this application embodiment;
[0031] Figure 9 A flowchart illustrating another map-based pathfinding method provided in this application embodiment;
[0032] Figure 10 A schematic diagram of a field grid and its adjacent grids provided for an embodiment of this application;
[0033] Figure 11 A schematic diagram illustrating the velocity direction information of a field of view grid provided in an embodiment of this application;
[0034] Figure 12 A flowchart illustrating another map-based pathfinding method provided in this application embodiment;
[0035] Figure 13 This is a schematic diagram of a map navigation device provided in an embodiment of this application;
[0036] Figure 14 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0038] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0039] It should be noted that the term "comprising" will be used in the embodiments of this application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.
[0040] In recent years, large maps have become increasingly common in 2D computer games, and these maps are typically represented by grid maps. Grid maps are a frequently used map-building technique in computer games, used to improve the performance of real-time games. Figure 1 Generally, tile-based processing is needed to address the issue of excessively large maps. Navigation technology for large grid maps is also a challenge in the field of real-time games; if the map is too large or there are too many units that need to find their way, the performance of real-time games will drop rapidly.
[0041] Common real-time pathfinding algorithms include Depth-First Search (DFS), Breadth-First Search (BFS), and heuristic pathfinding algorithms (such as A* (A-Star) and its variants). Compared to DFS and BFS, A* uses heuristics to estimate path distances. Although the final solution may not be the optimal path, it has better performance, making it more commonly used in real-time applications.
[0042] Real-time pathfinding algorithms experience a sharp performance drop when maps are enlarged. Solutions to the slow pathfinding computation on large maps include pathfinding data pre-computation and map layering (such as the common HPA (Hierarchical PathfindingA) algorithm). The pathfinding data pre-computation scheme involves calculating the map's pathfinding data in advance, while the map layering scheme divides the map into different levels based on its level of abstraction to avoid excessive computation.
[0043] However, as maps become increasingly large, the performance of common pathfinding algorithms such as A* begins to decline sharply, failing to meet the requirements of real-time computation. Map layering algorithms, such as HPA*, only find local optima, resulting in less smooth pathfinding. Pre-computed pathfinding methods typically require significant memory usage, making them unsuitable for directly employing methods that deal with excessively large pre-computed maps.
[0044] Among them, the A*:A* (A-Star) algorithm is a highly efficient direct search method for finding the shortest path in a static road network, and it is also an effective algorithm for solving many search problems. The closer the distance estimate in the algorithm is to the actual value, the faster the final search speed.
[0045] HPA*: HPA* is a hierarchical pathfinding algorithm based on A*, which speeds up pathfinding by dividing the map into layers.
[0046] Based on this, this application provides a map pathfinding method. In the pre-processing stage, map navigation information is generated through pre-calculation combined with map layering. In addition, during the real-time operation of the game, a view map corresponding to the player character is constructed based on the player character's position information. Based on the view map, a distance map and a velocity map between the view grid and the player character are obtained. When the object to be pathfinded is located within the player character's view map, navigation is performed according to the generated velocity map to improve the smoothness of the navigation path when navigating within the player character's field of vision. When the object to be pathfinded is not within the player character's view map, navigation can be performed according to the pre-generated map navigation information, improving the performance of real-time navigation of a large number of objects on a large map.
[0047] Figure 1 This is a flowchart illustrating a map-based pathfinding method provided in an embodiment of this application; the executing entity of this method can be a terminal device, server, processor, or other computer device. Figure 1 As shown, the method may include:
[0048] S101. Obtain the position information of the player character in the current frame. The position information includes: map tile coordinates and grid coordinates within the tile.
[0049] First, let's explain the application scenarios of this solution. This pathfinding method can be applied to scenarios where a large number of pathfinding objects are used for pathfinding on a large map. The player character can be the target of the search. By navigating a large number of pathfinding objects on the map, the player character's location can be found. The pathfinding objects can be virtual monsters in the game scene or other virtual objects. The purpose of the pathfinding objects is to find the player character.
[0050] Since the player character's position changes in real time, pathfinding can be performed in each frame using the method provided in this solution.
[0051] Optionally, the position information of the player character in the current frame can be obtained, wherein the position information may include: map tile coordinates and grid coordinates within the tile.
[0052] Figure 2This is a schematic diagram of map grid coordinates provided in an embodiment of this application. In this solution, the coordinate system of the 2D large map is based on map tiles. Specifically, the coordinates of a grid in the map have four dimensions, which can be: block coordinate X, block coordinate Y, grid coordinate X within the block, and grid coordinate Y within the block. In this solution, the starting point of the coordinates is always the lower left corner.
[0053] Figure 2 (a) in the diagram illustrates the grid coordinates within the block; Figure 2 (b) shows the map tile coordinates. A game map can be divided into multiple map tiles, each with corresponding map tile coordinates. A map tile can also contain multiple intra-tiles, each with corresponding coordinates. Therefore, based on the intra-tile where the player character is located, the player character's intra-tile coordinates and map tile coordinates can be obtained. Thus, the player character's position information can be represented using map tile coordinates and intra-tile coordinates.
[0054] S102. Based on the player character's position information and the virtual camera's field of view, construct the field of view map corresponding to the player character in the current frame.
[0055] The virtual camera's field of view can be predetermined. With the virtual camera's field of view remaining constant, regardless of the player character's position, the number of map tiles visible within the player character's field of view remains constant; only the observed map tiles themselves change, perhaps moving from the left to the right. Therefore, based on the player character's position information and the virtual camera's field of view, a view map corresponding to the player character in the current frame can be constructed.
[0056] When the virtual camera's field of view changes, or when the player character's position information changes, the player character's field of view can be reconstructed.
[0057] S103. Determine the distance information between each grid in the field of view and the player character, and determine the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character.
[0058] In some embodiments, the player character's position information can be converted into the field of view map to obtain the player character's field of view grid relative to the field of view map. This allows for the determination of the distance information from each other grid in the field of view map to the player character's field of view grid. Based on this distance information, the velocity direction information of each grid relative to the player character's field of view grid can be further calculated. The velocity direction information may include the direction from other grids towards the player character's field of view grid.
[0059] S104. If the object to be navigated to in the current frame is located within the player character's field of view, then the navigation information for the object to be navigated to in the current frame is generated based on the grid information of the object in the field of view and the velocity and direction information of each grid relative to the player character.
[0060] In one feasible approach, when navigating the object to be navigated, it can first be determined whether the object is located within the player character's field of view. If so, navigation information for the object can be generated based on the grid information of the object within the field of view and the velocity and direction information of each grid within the field of view relative to the player character. Based on the navigation information, the object can be navigated to find the player character.
[0061] It is worth noting that there may be multiple objects to be navigated in each frame. Taking the current object to be navigated in the current frame as an example, the current object to be navigated can be any object among all objects that need to be navigated in the current frame. As long as each object to be navigated is located within the player character's field of view, navigation information will be generated in the manner described above.
[0062] This embodiment calculates the velocity direction information of each cell in the player character's field of view relative to the player character's cell in real time. The velocity direction information is determined based on the distance gradient direction, so that the obtained velocity direction can point to the direction of the fastest distance decrease. Navigation is carried out according to the velocity direction, which can achieve the fastest navigation and more accurate navigation path. This makes navigation within the player character's field of view smoother and the pathfinding path of the object to be traversed more realistic.
[0063] In summary, the map pathfinding method provided in this embodiment can construct a view map corresponding to the player character by acquiring the player character's position information in the current frame, and calculate the distance between each view grid in the view map and the player character's view grid. Based on the distance, it generates velocity direction information of each view grid relative to the player character's view grid. Therefore, when the object to be pathfinded is within the player's view map, the velocity direction information of the view grid relative to the player's view grid can be used for pathfinding navigation. Since the object to be pathfinded is close to the player character when it is within the view map, using the velocity direction information generated from the distance information for pathfinding navigation allows the generated velocity direction to point to the player character's location more quickly, resulting in smoother navigation. Consequently, when the object to be pathfinded follows the pathfinding navigation information, the pathfinding path is smoother, and the player character's visual experience is more realistic.
[0064] Figure 3This is a flowchart illustrating another map pathfinding method provided in this application embodiment; optionally, in step S102, constructing the field-of-view map corresponding to the player character in the current frame based on the player character's position information and the virtual camera's field of view size may include:
[0065] S301. Determine the bounding box of the field of view based on the virtual camera's field of view; align the boundaries of the bounding box with the map grid.
[0066] Figure 4 This is a schematic diagram of a view map provided in an embodiment of this application; wherein, the inner dashed rectangle 1 represents the view range of the virtual object, while the outer thick rectangle 2 represents the bounding box of the view range. It can be seen that the boundary of the bounding box is aligned with the map grid, and the bounding box includes multiple complete map grids.
[0067] S302. Based on the bounding box of the field of view, determine the construction parameters of the field of view map corresponding to the player character; the construction parameters include: the number of rows and columns of the field of view map.
[0068] Therefore, based on the bounding box of the defined field of view, the construction parameters of the field of view map can be obtained. The area formed by the bounding box of the field of view is the field of view map corresponding to the player character. It can be seen that the bounding box of the field of view is rectangular, which can be considered as being composed of multiple rows and columns of map grids. With the bounding box of the field of view determined, the number of rows and columns of the bounding box can be directly determined. Therefore, the number of rows and columns constituting the bounding box can be used as the construction parameters of the field of view map. Thus, the number of rows in the bounding box is the number of rows in the field of view map, and the number of columns in the bounding box is the number of columns in the field of view map.
[0069] S303. Based on the player character's position information and construction parameters, construct the player character's corresponding field of view map.
[0070] Since the vision map being constructed is for the player character, it is also necessary to refer to the player character's position information to construct the vision map for the player character.
[0071] Optionally, in step S303, constructing the vision map corresponding to the player character based on the player character's position information and construction parameters may include: taking the map grid where the player character is located as the center, constructing an M-row N-column vision map according to the number of rows and columns of the vision map, and using the M-row N-column vision map as the vision map corresponding to the player character, where M is the number of rows and N is the number of columns.
[0072] Since the player character is always at the center of the view map, we can construct a view map with M rows and N columns, using the player character's position as the center. M represents the number of rows in the view map, and N represents the number of columns. Both the number of rows and columns must be positive odd numbers.
[0073] thereby Figure 4 Within the constructed field of view map, the field of view Figure X The coordinate range of the Y-axis grid is [0, M-1], and the coordinate range of the Y-axis grid is [0, N-1].
[0074] Figure 5 This is a flowchart illustrating another map pathfinding method provided in this application embodiment; optionally, in step S103, determining the distance information between each grid within the view map and the player character may include:
[0075] S501. Determine the coordinates of the player character relative to the target grid in the view map based on the size of the view map.
[0076] Since the player character is always at the center of the view map, given a fixed view map size, the player character's coordinates relative to the view map can be calculated using the following formulas: GX = ceil(M / 2) + 1, GY = ceil(N / 2) + 1; where GX represents the horizontal coordinate of the player character relative to the view map's grid, which is also the horizontal coordinate of the target grid mentioned above, and GY represents the vertical coordinate of the player character relative to the view map's grid, which is also the vertical coordinate of the target grid mentioned above. Ceil points upwards to the nearest integer. M is the number of rows in the view map mentioned earlier, and N is the number of columns.
[0077] S502. Take the target cell as the currently traversed cell, determine the adjacent cells of the currently traversed cell in the view map in turn, and determine the distance of the adjacent cells of the currently traversed cell based on the distance of the currently traversed cell.
[0078] The player character's field of view grid (i.e., the target grid) can be used as the initial grid for traversal. Since the distance from each field of view grid to the player character's field of view grid needs to be calculated, the distance of the player character's field of view grid is set to 0 by default, which means the distance of the target grid is 0.
[0079] Iterate through the adjacent cells of the target cell. Here, "adjacent" can refer to the four directly adjacent cells (up, down, left, and right), excluding diagonal adjacent cells. Increment the distance of the target cell by 1 to obtain the distance between the target cell and its adjacent cells.
[0080] S503. Determine the new cell currently being traversed from the adjacent cells, and determine the distance between the adjacent cells of the new cell currently being traversed based on the distance of the new cell currently being traversed.
[0081] Next, a new cell is selected from the adjacent cells of the target cell as the new cell to be traversed. Then, the adjacent cells of the new cell to be traversed are determined from the remaining cells. The distance of the new cell to be traversed is incremented by 1 to obtain the distance of the adjacent cells of the new cell to be traversed.
[0082] S504. Iterate until all the grids in the view map have been traversed, and use the distance of each grid as the distance information between each grid and the player character.
[0083] The process is repeated iteratively in the above manner until all the vision grids in the vision map have been traversed, the distance of each vision grid is obtained, and this distance is used as the distance information between the vision grid and the player character's vision grid.
[0084] The above method of determining distance can be implemented with reference to the breadth-first traversal algorithm. Each grid cell in the field of view can be regarded as a node. Starting from the node that has not been traversed, the adjacent nodes of the node are traversed in turn, and the distance between the adjacent nodes is the distance of the node plus 1. All nodes are traversed in turn.
[0085] Figure 6 This is a schematic diagram illustrating the distance of a field of view grid within a field of view, provided as an embodiment of this application.
[0086] The cells marked with 0 represent the player character's field of vision, while the numbers marked on the other cells represent the distance information of the corresponding cells.
[0087] Optionally, in step S502, taking the target cell as the currently traversed cell and sequentially determining the adjacent cells of the currently traversed cell may include: if the adjacent cells of the currently traversed cell have already been traversed, then the traversed cells are deleted from the adjacent cells of the currently traversed cell.
[0088] In some embodiments, when determining the adjacent cells of the currently traversed cell, since the same cell may simultaneously serve as the adjacent cell of different cells, it may have been traversed before and assigned distance information. Therefore, when it serves as the adjacent cell of the currently traversed cell, it will not be assigned a value again, but will be deleted from the adjacent cells, and its distance information will retain the value assigned the first time.
[0089] Reference Figure 6 For the player character's field of view tile marked with a 1, since the player character's field of view tile is also one of its adjacent tiles, if the distance information were calculated directly in the way described above, the distance information of the player character's field of view tile would be modified to 2, which is obviously incorrect. Therefore, the player character's field of view tile is removed from its adjacent tiles, and only the remaining three adjacent tiles are assigned a distance information of 2. The processing of all other tiles is similar.
[0090] Figure 7This is a flowchart illustrating another map pathfinding method provided in an embodiment of this application; optionally, in step S502, determining the distance between adjacent cells of the currently traversed cell based on the distance of the currently traversed cell may include:
[0091] S701. Based on the coordinates of adjacent cells, the player character's position information, and the position information of preset obstacles marked on the current game map, determine whether adjacent cells are obstacle cells.
[0092] In some embodiments, there may be obstacle grids in the field of view grid, and navigation needs to avoid obstacles when navigating.
[0093] Optionally, the coordinates of the field of view grids in the field of view map can be converted into map grid coordinates based on the coordinates of adjacent grids and the position information of the player character. Then, based on the converted map grid coordinates and the position information of obstacles in the game map, it can be determined whether the field of view grid is an obstacle grid.
[0094] This method is not limited to determining whether adjacent cells are obstacles; it can be used to determine any cell within the field of view.
[0095] S702. If the adjacent cell is not an obstacle cell, then determine the distance between the adjacent cells of the currently traversed cell based on the distance of the currently traversed cell.
[0096] When it is determined that an adjacent cell is not an obstacle cell, the distance of the currently traversed cell is incremented by 1 in the same way as before to obtain the distance of the adjacent cell.
[0097] S703. If an adjacent cell is an obstacle cell, then the distance between the adjacent cells is determined to be a preset distance.
[0098] When an adjacent cell is an obstacle cell, the distance between the adjacent cells is set to a preset distance, thus highlighting the obstacle cells within the view map. The preset distance can be empty.
[0099] Figure 8 This is a flowchart illustrating another map pathfinding method provided in this application embodiment; optionally, in step S701, determining whether an adjacent cell is an obstacle cell based on the coordinates of adjacent cells, the player character's position information, and the position information of preset obstacles marked in the current game map may include:
[0100] S801. Based on the coordinates of adjacent cells and the player character's position information, convert the coordinates of adjacent cells into map cell coordinates.
[0101] In this embodiment, adjacent grids can refer to any grid in the field of view that requires coordinate transformation, and the player character's position information refers to the player character's world coordinates, which include: the block coordinates where the player character is located and the grid coordinates within the block.
[0102] S802. If the map grid coordinates of an adjacent grid are consistent with the map grid coordinates of a preset obstacle marked in the game map, then the adjacent grid is determined to be an obstacle grid.
[0103] Typically, for a well-designed game map, the positions of obstacles in the game map are also pre-set. Therefore, after converting the coordinates of the view grid to the coordinates of the map grid, it can be determined whether the coordinates of the map grid corresponding to the view grid are consistent with the coordinates of the map grids where the pre-set obstacles are located. If they are consistent, the view grid can be considered as the obstacle grid.
[0104] Optionally, in step S801, converting the coordinates of adjacent cells into map cell coordinates based on the coordinates of adjacent cells and the player character's position information may include:
[0105] If the sum of the horizontal coordinates of the player character's in-block grid and the horizontal coordinates of the adjacent grid is greater than or equal to the width of a single map tile, then the sum of the horizontal coordinates of the player character's in-block grid and the horizontal coordinates of the adjacent grid is subtracted from the width value to obtain the horizontal coordinate of the in-block grid in the map tile coordinates of the adjacent grid; and the horizontal coordinate of the player character's map tile is incremented by 1 to obtain the horizontal coordinate of the map tile in the map tile coordinates of the adjacent grid.
[0106] If the sum of the horizontal coordinate of the player character's block and the horizontal coordinate of the adjacent block is less than a preset value, then the horizontal coordinate of the block in the map grid coordinates of the adjacent block is obtained based on the sum of the horizontal coordinate of the player character's block, the horizontal coordinate of the adjacent block, and the width value; and the horizontal coordinate of the player character's map block is reduced by 1 to obtain the horizontal coordinate of the map block in the map grid coordinates of the adjacent block.
[0107] If the sum of the player character's intra-block ordinate and the ordinate of the adjacent block is greater than or equal to the length of a single map block, then the length value is subtracted from the sum of the player character's intra-block ordinate and the ordinate of the adjacent block to obtain the intra-block ordinate of the map block in the coordinates of the adjacent block; and the player character's map block ordinate is incremented by 1 to obtain the map block ordinate of the map block in the coordinates of the adjacent block.
[0108] If the player character's in-block grid ordinate and the adjacent grid ordinate are less than a preset value, then the player character's in-block grid ordinate, the adjacent grid ordinate, and the length value are summed to obtain the in-block grid ordinate of the map grid corresponding to the adjacent grid; and the player character's map grid ordinate is reduced by 1 to obtain the map grid ordinate of the adjacent grid.
[0109] The following example illustrates the coordinate transformation relationship between view grids and map grids:
[0110] Assume the coordinates of the view grid to be converted are (VX, VY); the player character's block coordinates are (CX, CY); the player character's intra-block grid coordinates are (IX, IY); the width of a single map tile is W (in squares); and the length of a single map tile is H. The resulting map tile coordinates after the view grid conversion are: map tile coordinates (CVX, CVY); intra-block grid coordinates (IVX, IVY).
[0111] So, when IX+VX>=W, it means that the view cell that needs to be converted has moved to the right map tile, then IVX=IX+VX-W; CVX=CX+1.
[0112] When IX+VX<0, it means that the view cell that needs to be converted has moved to the map tile on the left. In this case, IVX = IX+VX+W; CVX = CX-1.
[0113] When IY+VY>=H, it means that the view cell that needs to be converted has moved to the map tile above. Therefore, IVY=IY+VY-H; CVY=CY+1.
[0114] When IY+VY<0, it means that the view cell that needs to be converted has moved to the map tile below, so IVY=IY+VY+H; CVY=CY-1.
[0115] Using the above method, the coordinates of the view grid can be converted to map grid coordinates according to the corresponding conversion formula. This allows us to determine whether a view grid is an obstacle grid.
[0116] Figure 9 This is a flowchart illustrating another map pathfinding method provided in an embodiment of this application; optionally, in step S103, determining the velocity direction information of each cell relative to the player character based on the distance information between each cell and the player character may include:
[0117] S901. Iterate through each cell in the view map in sequence, and determine the gradient vector of the currently traversed cell based on the distance information between each of the adjacent cells of the currently traversed cell.
[0118] Optionally, when calculating the velocity direction, it is also necessary to calculate the velocity direction of each cell in the field of view relative to the player character's field of view. That is, the velocity direction information of each cell points to the player character's field of view. This can be used to navigate to the object to be found so as to quickly locate the player character.
[0119] Each cell in the viewport can be traversed sequentially. For the cell currently being traversed, the velocity and direction information of that cell can be calculated based on the distance information of its neighboring cells.
[0120] First, the gradient vector of the currently traversed cell can be calculated based on the distance information between each of the adjacent cells of the currently traversed cell.
[0121] When calculating the gradient vector, the calculation can be performed using a predefined coordinate system. Combined with... Figure 6 As shown in the distance diagram, assuming the horizontal axis of the coordinate system points to the right and the vertical axis points upward, then for any field of view cell, the horizontal coordinate of its corresponding gradient vector can be the distance between the left and right adjacent cells of that field of view cell, while the vertical coordinate of the gradient vector can be the distance between the lower and upper adjacent cells of that field of view cell.
[0122] Figure 10 This is a schematic diagram of a field of view grid and its adjacent grids provided in an embodiment of this application. Taking the grid where the velocity direction information needs to be calculated as the grid with a distance of 3 in the diagram as an example, the horizontal coordinate of the gradient vector of this grid is 4-1 and the vertical coordinate is 3-2. That is, the gradient vector obtained is (3, 1).
[0123] S902. Normalize the gradient vector to obtain the velocity and direction information of the currently traversed grid relative to the player character.
[0124] After normalizing the gradient vector, we can obtain... Figure 10 The velocity and direction information of the grid at a distance of 3 is as follows: Figure 10 The directions marked in the text.
[0125] The velocity and direction information can be calculated for any grid cell in the manner described above.
[0126] Of course, the calculation of the gradient vector can also be adjusted adaptively when the orientation of the constructed coordinate system changes. For example, when the horizontal axis of the coordinate system points to the left and the vertical axis points downward, the horizontal coordinate of the gradient vector can still be obtained by subtracting the distance of the right adjacent cell from the distance of the left adjacent cell, and the vertical coordinate of the gradient vector can be obtained by subtracting the distance of the upper adjacent cell from the distance of the lower adjacent cell. However, the resulting gradient vector needs to be multiplied by -1 to make the velocity direction conform to the direction of the coordinate axis.
[0127] Figure 11 This is a schematic diagram illustrating the velocity direction information of a field of view grid provided in an embodiment of this application. The velocity direction of each field of view grid in the diagram points towards the field of view grid where the player character is located.
[0128] Optionally, the method may further include: if there are obstacle cells among the adjacent cells of the currently traversed cell, then determine the velocity direction information of the currently traversed cell relative to the player character based on the direction of the obstacle cells relative to the currently traversed cell.
[0129] The method described above for calculating velocity direction information using gradient vectors is applicable when all adjacent cells of a grid are normal cells and there are no obstacle cells.
[0130] This embodiment describes the case where adjacent cells are obstacle cells. When there are obstacle cells among the adjacent cells of the field of view cell where velocity direction information needs to be calculated, a direction pointing to the non-obstacle cell can be generated based on the direction of the obstacle cell.
[0131] Scenario 1: When there is only one adjacent cell that is an obstacle cell, if the obstacle cell is directly above or below the cell to be calculated, a leftward or rightward velocity direction can be generated as the velocity direction information of the cell to be calculated. If the obstacle cell is to the left or right of the cell to be calculated, an upward or downward velocity direction can be generated as the velocity direction information of the cell to be calculated.
[0132] Case 2: When there are two adjacent cells that are obstacles, a direction leading to any non-obstacle adjacent cell is generated as the velocity direction information of the cell to be calculated.
[0133] Figure 12 This is a flowchart illustrating another map pathfinding method provided in this application embodiment; optionally, in step S104, generating pathfinding navigation information for the current object to be pathfinded in the current frame based on the grid information of the object to be pathfinded within the view map and the velocity and direction information of each grid relative to the player character may include:
[0134] S1201. Based on the grid information of the object to be navigated in the view map, obtain the speed and direction information of the grid of the object to be navigated in the view map relative to the player character.
[0135] When the object to be traversed is within the player character's field of view, the coordinates of the object's map grid in the game map can be obtained first, and then converted into the field of view to obtain the coordinates of the object's field of view grid. Based on the velocity and direction information of each grid relative to the player character calculated above, the velocity and direction information of the object's field of view grid relative to the player character can be queried.
[0136] S1202: Use the velocity and direction information of the grid where the object to be navigated is located in the view map relative to the player character as the navigation information of the object to be navigated in the current frame.
[0137] Therefore, the velocity and direction information of the field of view grid of the object to be traversed relative to the player character can be used as the pathfinding navigation information for the current object to be traversed in the current frame.
[0138] In this embodiment, the pathfinding navigation information refers to the navigation direction. Providing a navigation direction to the object being navigated to is sufficient; it is not limited to specifying the next path point to the object. By following the navigation direction, the player character's location can be successfully found.
[0139] Optionally, in step S103, after determining the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character, it may further include: if the object to be traversed in the current frame is not within the player character's field of view, then the pathfinding navigation information of the object to be traversed in the current frame is determined based on the position information of the object to be traversed, the position information of the player character, and the pathfinding topology information corresponding to the pre-generated current game map; the pathfinding topology information includes the relative velocity direction information between any two map grids in the game map.
[0140] In some embodiments, when the object to be navigated is not within the player character's field of view, since the object is far away from the player character, as long as the object can be navigated to eventually find the player character, it is not important whether the path is smooth. In this case, the path navigation information of the object to be navigated can be directly obtained from the path navigation topology information of the pre-generated game map.
[0141] Optionally, before performing pathfinding and navigation in this solution, the pathfinding topology information corresponding to the game map can be calculated and stored using a pre-calculation method combined with map layering. For a specific game map, this step is performed in advance and only needs to be performed once, and can be called in real time during subsequent pathfinding processes.
[0142] Because a 2D large map contains a massive number of grids (e.g., a map size of 8192x8192 grids), directly pre-calculating the entire 2D map would result in a data size unacceptable to the game software package (e.g., pre-calculating paths on an 8192x8192 map would require 8192 x 8192 x 8192 x N storage, where N represents the data size of a single path). Therefore, in this embodiment, the HPA* algorithm can be used to layer the map before pre-calculation, reducing the pre-calculated data size to a size acceptable to the game package (assuming a map tile size of 128x128, for a large map of 8192x8192 grids, the data storage required after layering the map is only 64 x 64 x 64 x N + 128 x 128 x 64 x 64 x N). Here, 64 refers to the number of map tiles obtained after layering, and 128 refers to the number of map grids contained in a map tile. The calculated navigation data can be used for navigation across map tiles, but the navigation data calculated by HPA* is only locally optimal (i.e., not globally optimal; this path is not smooth or intelligent enough). Therefore, the navigation data pre-calculated in this step is only used for navigation of objects outside the player's field of view. The specific execution steps of HPA* calculation can be understood by referring to existing technologies, and will not be elaborated here.
[0143] Optionally, the pathfinding topology information corresponding to the game map may include the relative velocity and direction information between any two map cells in the game map. Then, based on the map cell where the object to be pathfinded is located and the map cell where the player character is located, the velocity and direction information of the object to be pathfinded relative to the player character can be retrieved.
[0144] In summary, the map pathfinding method provided in this embodiment can construct a view map corresponding to the player character by acquiring the player character's position information in the current frame, and calculate the distance between each view grid in the view map and the player character's view grid. Based on the distance, it generates velocity direction information of each view grid relative to the player character's view grid. Therefore, when the object to be pathfinded is within the player's view map, the velocity direction information of the view grid relative to the player's view grid can be used for pathfinding navigation. Since the object to be pathfinded is close to the player character when it is within the view map, using the velocity direction information generated from the distance information for pathfinding navigation allows the generated velocity direction to point to the player character's location more quickly, resulting in smoother navigation. Consequently, when the object to be pathfinded follows the pathfinding navigation information, the pathfinding path is smoother, and the player character's visual experience is more realistic.
[0145] In addition, for objects that are not within the player's field of view, the navigation information of the objects can be obtained by searching for them based on the pre-generated pathfinding topology information of the game map. Since the objects are far away from the player when they are not within the player's field of view, the smoothness requirement for the pathfinding result is low. The pre-calculated pathfinding topology information can be used to quickly obtain the pathfinding navigation information, thereby reducing the amount of pathfinding data calculation and solving the problem of real-time navigation on large maps.
[0146] The following describes the apparatus, device, and storage medium used to execute the map pathfinding method provided in this application. The specific implementation process and technical effects are described above and will not be repeated below.
[0147] Figure 13 This is a schematic diagram of a map navigation device provided in an embodiment of this application. The functions implemented by this map navigation device correspond to the steps performed by the above-described method. This device can be understood as the aforementioned terminal device, server, or server processor, or it can be understood as a component that implements the functions of this application under server control, independent of the aforementioned server or processor, such as... Figure 13 As shown, the device may include: an acquisition module 130, a construction module 131, a determination module 132, and a generation module 133;
[0148] The acquisition module 130 is used to acquire the position information of the player character in the current frame. The position information includes: map tile coordinates and grid coordinates within the tile.
[0149] Module 131 is used to construct the field-of-view map corresponding to the player character in the current frame based on the player character's position information and the virtual camera's field of view.
[0150] The determination module 132 is used to determine the distance information between each grid in the field of view and the player character, and to determine the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character;
[0151] The generation module 133 is used to generate pathfinding navigation information for the current object to be pathfinded in the current frame if the object to be pathfinded in the current frame is located within the player character's field of view. This information is based on the grid information of the object to be pathfinded in the field of view and the velocity direction information of each grid relative to the player character.
[0152] Optionally, module 131 is specifically used to determine the bounding box of the field of view based on the field of view of the virtual camera; the boundary of the bounding box is aligned with the map grid.
[0153] Based on the bounding box of the field of view, determine the construction parameters of the field of view map corresponding to the player character; the construction parameters include: the number of rows and columns of the field of view map;
[0154] Based on the player character's location information and construction parameters, construct the player character's corresponding field of vision map.
[0155] Optionally, module 131 is specifically used to construct an M-row N-column vision map centered on the map grid where the player character is located, according to the number of rows and columns of the vision map, and use the M-row N-column vision map as the vision map corresponding to the player character, where M is the number of rows and N is the number of columns.
[0156] Optionally, module 132 is specifically used to determine the coordinates of the player character relative to the target grid in the view map, based on the size of the view map;
[0157] The target cell is taken as the currently traversed cell. The adjacent cells of the currently traversed cell in the field of view are determined in turn. The distance of the currently traversed cell to the adjacent cells is determined based on the distance of the currently traversed cell.
[0158] Determine the new cell to be traversed from the adjacent cells, and determine the distance of the new cell to be traversed from the adjacent cells based on the distance of the new cell to be traversed.
[0159] The process is iterated until all the cells in the view map have been traversed, and the distance of each cell is determined as the distance information between each cell and the player character.
[0160] Optionally, the determining module 132 is specifically used to delete the traversed cell from the adjacent cells of the currently traversed cell if the adjacent cells of the currently traversed cell have been traversed.
[0161] Optionally, the determining module 132 is specifically used to determine whether an adjacent cell is an obstacle cell based on the coordinates of the adjacent cells, the position information of the player character, and the position information of the preset obstacles marked in the current game map;
[0162] If the adjacent cell is not an obstacle cell, then the distance between the adjacent cells of the currently traversed cell is determined based on the distance of the currently traversed cell.
[0163] If an adjacent cell is an obstacle cell, the distance between the adjacent cells is determined to be a preset distance.
[0164] Optionally, the determining module 132 is specifically used to convert the coordinates of adjacent grids into map grid coordinates based on the coordinates of adjacent grids and the position information of the player character;
[0165] If the map grid coordinates of an adjacent cell match the map grid coordinates of a preset obstacle marked on the game map, then the adjacent cell is determined to be an obstacle cell.
[0166] Optionally, module 132 is specifically used to: if the sum of the horizontal coordinates of the player character's intra-block grid and the horizontal coordinates of adjacent grids is greater than or equal to the width value of a single map tile, subtract the width value from the sum of the horizontal coordinates of the player character's intra-block grid and the horizontal coordinates of adjacent grids to obtain the horizontal coordinates of the intra-block grid in the map tile coordinates corresponding to the adjacent grid; and add 1 to the horizontal coordinates of the player character's map tile to obtain the horizontal coordinates of the map tile in the map tile coordinates corresponding to the adjacent grid.
[0167] If the sum of the horizontal coordinate of the player character's block and the horizontal coordinate of the adjacent block is less than a preset value, then the horizontal coordinate of the block in the map grid coordinates of the adjacent block is obtained based on the sum of the horizontal coordinate of the player character's block, the horizontal coordinate of the adjacent block, and the width value; and the horizontal coordinate of the player character's map block is reduced by 1 to obtain the horizontal coordinate of the map block in the map grid coordinates of the adjacent block.
[0168] If the sum of the player character's in-block y-coordinate and the y-coordinate of the adjacent block is greater than or equal to the length of a single map block, then the length value is subtracted from the sum of the player character's in-block y-coordinate and the y-coordinate of the adjacent block to obtain the in-block y-coordinate of the map block in the coordinates of the adjacent block; and the player character's map block y-coordinate is incremented by 1 to obtain the map block y-coordinate of the map block in the coordinates of the adjacent block.
[0169] If the player character's in-block grid ordinate and the adjacent grid ordinate are less than a preset value, then the player character's in-block grid ordinate, the adjacent grid ordinate, and the length value are summed to obtain the in-block grid ordinate of the map grid corresponding to the adjacent grid; and the player character's map grid ordinate is reduced by 1 to obtain the map grid ordinate of the adjacent grid.
[0170] Optionally, the determining module 132 is specifically used to sequentially traverse each cell in the view map and determine the gradient vector of the currently traversed cell based on the distance information of each adjacent cell of the currently traversed cell.
[0171] Normalize the gradient vector to obtain the velocity and direction information of the currently traversed grid relative to the player character.
[0172] Optionally, the determining module 132 is further configured to determine the velocity direction information of the currently traversed cell relative to the player character based on the direction of the obstacle cell relative to the currently traversed cell if there is an obstacle cell among the adjacent cells of the currently traversed cell.
[0173] Optionally, the generation module 133 is specifically used to obtain the velocity and direction information of the grid in which the object to be pathfinded is located relative to the player character, based on the grid information of the grid in which the object to be pathfinded is located within the view map.
[0174] The velocity and direction information of the grid where the object to be navigated is located relative to the player character within the view map is used as the navigation information for the object to be navigated in the current frame.
[0175] Optionally, the determining module 132 is further configured to determine the pathfinding navigation information of the current object to be pathfinded in the current frame, based on the position information of the object to be pathfinded, the position information of the player character, and the pathfinding topology information corresponding to the pre-generated current game map, if the object to be pathfinded in the current frame is not within the player character's field of view. The pathfinding topology information includes the relative velocity direction information between any two map grids in the game map.
[0176] These modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more digital signal processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). Alternatively, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a system-on-a-chip (SOC).
[0177] The modules described above can be connected or communicate with each other via wired or wireless connections. Wired connections can include metal cables, optical fibers, hybrid cables, or any combination thereof. Wireless connections can include connections via LAN, WAN, Bluetooth, ZigBee, or NFC, or any combination thereof. Two or more modules can be combined into a single module, and any module can be divided into two or more units. Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the method embodiments, and will not be repeated here.
[0178] Figure 14A schematic structural diagram of an electronic device provided by an embodiment of this application, including: a processor 801, a storage medium 802, and a bus 803. The storage medium 802 stores machine-readable instructions executable by the processor 801. When the electronic device runs a map pathfinding method as in an embodiment, the processor 801 communicates with the storage medium 802 through the bus 803, and the processor 801 executes the machine-readable instructions to perform the following steps:
[0179] Obtain the position information of the player character in the current frame, where the position information includes: map block coordinates and in-block grid coordinates;
[0180] Construct a field of view map corresponding to the player character in the current frame according to the position information of the player character and the field of view range of the virtual camera;
[0181] Determine the distance information between each grid in the field of view map and the player character, and determine the velocity direction information of each grid relative to the player character according to the distance information between each grid and the player character;
[0182] If the currently pathfinding object in the current frame is located within the field of view map corresponding to the player character, generate pathfinding navigation information for the currently pathfinding object in the current frame according to the grid information where the pathfinding object is located in the field of view map and the velocity direction information of each grid relative to the player character.
[0183] In a feasible implementation, when the processor 801 constructs the field of view map corresponding to the player character in the current frame according to the position information of the player character and the size of the field of view range of the virtual camera, it specifically is used for: determining the bounding box of the field of view range according to the field of view range of the virtual camera; the boundaries of the bounding box are aligned with the map grids;
[0184] Determine the construction parameters of the field of view map corresponding to the player character according to the bounding box of the field of view range; the construction parameters include: the number of rows and columns of the field of view map;
[0185] Construct the field of view map corresponding to the player character according to the position information of the player character and the construction parameters.
[0186] In a feasible implementation, when the processor 801 constructs the field of view map corresponding to the player character according to the position information of the player character and the construction parameters, it specifically is used for: centering on the map grid where the player character is located, constructing a field of view map with M rows and N columns respectively according to the number of rows and columns of the field of view map, and taking the field of view map with M rows and N columns as the field of view map corresponding to the player character, where M is the number of rows and N is the number of columns.
[0187] In a feasible implementation, when the processor 801 determines the distance information between each grid in the field of view map and the player character, it specifically is used for: determining the coordinates of the target grid of the player character relative to the field of view map according to the size of the field of view map;
[0188] Take the target grid as the currently traversed grid, and successively determine the adjacent grids of the currently traversed grid within the field of view map. Then, based on the distance of the currently traversed grid, determine the distances of the adjacent grids of the currently traversed grid.
[0189] Determine the newly traversed grid from the adjacent grids, and based on the distance of the newly traversed grid currently traversed, determine the distances of the adjacent grids of the newly traversed grid currently traversed.
[0190] Iteratively execute until all grids within the field of view map are traversed. Take the determined distance of each grid as the distance information between each grid and the player character.
[0191] In a feasible implementation, when the processor 801 executes taking the target grid as the currently traversed grid and successively determining the adjacent grids of the currently traversed grid, it is specifically used for: If the adjacent grid of the currently traversed grid has been traversed, delete the traversed grid from the adjacent grids of the currently traversed grid.
[0192] In a feasible implementation, when the processor 801 executes determining the distances of the adjacent grids of the currently traversed grid based on the distance of the currently traversed grid, it is specifically used for: Based on the coordinates of the adjacent grid, the position information of the player character, and the position information of the preset obstacles marked in the current game map, determine whether the adjacent grid is an obstacle grid.
[0193] If the adjacent grid is not an obstacle grid, determine the distances of the adjacent grids of the currently traversed grid based on the distance of the currently traversed grid.
[0194] If the adjacent grid is an obstacle grid, determine the distance of the adjacent grid as the preset distance.
[0195] In a feasible implementation, when the processor 801 executes determining whether the adjacent grid is an obstacle grid based on the coordinates of the adjacent grid, the position information of the player character, and the position information of the preset obstacles marked in the current game map, it is specifically used for: Based on the coordinates of the adjacent grid and the position information of the player character, convert the coordinates of the adjacent grid into map grid coordinates.
[0196] If the map grid coordinates corresponding to the adjacent grid are the same as the map grid coordinates of the preset obstacles marked in the game map, determine that the adjacent grid is an obstacle grid.
[0197] In a feasible implementation, when the processor 801 executes the conversion of the coordinates of an adjacent grid into map grid coordinates according to the coordinates of the adjacent grid and the position information of the player character, it is specifically used for: if the sum of the in-block grid abscissa of the player character and the abscissa of the adjacent grid is greater than or equal to the width value of a single map block, then subtract the width value from the sum of the in-block grid abscissa of the player character and the abscissa of the adjacent grid to obtain the in-block grid abscissa in the map grid coordinates corresponding to the adjacent grid; and add 1 to the map block abscissa of the player character to obtain the map block abscissa in the map grid coordinates corresponding to the adjacent grid.
[0198] If the sum of the in-block grid abscissa of the player character and the abscissa of the adjacent grid is less than a preset value, then obtain the in-block grid abscissa in the map grid coordinates corresponding to the adjacent grid according to the sum of the in-block grid abscissa of the player character, the abscissa of the adjacent grid, and the width value; and subtract 1 from the map block abscissa of the player character to obtain the map block abscissa in the map grid coordinates corresponding to the adjacent grid.
[0199] If the sum of the in-block grid ordinate of the player character and the ordinate of the adjacent grid is greater than or equal to the length value of a single map block, then subtract the length value from the sum of the in-block grid ordinate of the player character and the ordinate of the adjacent grid to obtain the in-block grid ordinate in the map grid coordinates corresponding to the adjacent grid; and add 1 to the map block ordinate of the player character to obtain the map block ordinate in the map grid coordinates corresponding to the adjacent grid.
[0200] If the in-block grid ordinate of the player character and the ordinate of the adjacent grid are less than a preset value, then obtain the in-block grid ordinate in the map grid coordinates corresponding to the adjacent grid according to the sum of the in-block grid ordinate of the player character, the ordinate of the adjacent grid, and the length value; and subtract 1 from the map block ordinate of the player character to obtain the map block ordinate in the map grid coordinates corresponding to the adjacent grid.
[0201] In a feasible implementation, when the processor 801 executes the determination of the velocity direction information of each grid relative to the player character according to the distance information between each grid and the player character, it is specifically used for: traversing each grid in the field of view map in sequence, and determining the gradient vector of the currently traversed grid according to the distance information of each adjacent grid of the currently traversed grid.
[0202] Perform normalization processing on the gradient vector to obtain the velocity direction information of the currently traversed grid relative to the player character.
[0203] In a feasible implementation, the processor 801 is further used for: if there is an obstacle grid among the adjacent grids of the currently traversed grid, then determine the velocity direction information of the currently traversed grid relative to the player character according to the direction of the obstacle grid relative to the currently traversed grid.
[0204] In a feasible implementation, when the processor 801 generates the pathfinding navigation information of the object to be pathfinding in the current frame according to the grid information of the object to be pathfinding in the field of view map and the velocity direction information of each grid relative to the player character, it is specifically used for: obtaining the velocity direction information of the grid where the object to be pathfinding is located in the field of view map relative to the player character according to the grid information of the object to be pathfinding in the field of view map;
[0205] Taking the velocity direction information of the grid where the object to be pathfinding is located in the field of view map relative to the player character as the pathfinding navigation information of the object to be pathfinding in the current frame.
[0206] In a feasible implementation, after the processor 801 determines the velocity direction information of each grid relative to the player character according to the distance information between each grid and the player character, it is further used for: if the object to be pathfinding in the current frame is not within the field of view map corresponding to the player character, determining the pathfinding navigation information of the object to be pathfinding in the current frame according to the position information of the object to be pathfinding, the position information of the player character, and the pre-generated pathfinding topology information corresponding to the current game map; the pathfinding topology information includes the relative velocity direction information between any two map grids in the game map.
[0207] In the above manner, the electronic device can construct the field of view map corresponding to the player character by obtaining the position information of the player character in the current frame, calculate the distance between each field of view grid in the field of view map and the field of view grid where the player character is located, and generate the velocity direction information of each field of view grid relative to the field of view grid of the player character based on the distance. Thus, when the object to be pathfinding is within the field of view of the player, the velocity direction information of the field of view grid relative to the field of view grid of the player can be used for pathfinding navigation of the object to be trained. Since the object to be pathfinding is relatively close to the player character when it is within the field of view map, using the velocity direction information generated by the distance information for pathfinding navigation enables the generated velocity direction to point to the position of the player character faster, and the navigation is smoother. Therefore, when the object to be pathfinding follows the pathfinding navigation information for pathfinding, the pathfinding path is smoother and the visual experience of the player character is more realistic.
[0208] In addition, for the object to be pathfinding that is not within the field of view map of the player character, the pathfinding navigation information of the object to be pathfinding can be found and obtained according to the pre-generated pathfinding topology information corresponding to the game map. Since the object to be pathfinding is far from the player character when it is not within the field of view of the player character, the requirement for the smoothness of the pathfinding result is relatively low. The pathfinding navigation information can be quickly obtained with the pre-calculated pathfinding topology information, and the pathfinding data calculation amount is reduced, solving the problem of real-time navigation of large maps.
[0209] Among them, the storage medium 802 stores program codes. When the program codes are executed by the processor 801, the processor 801 is caused to execute various steps in the map pathfinding method according to various exemplary embodiments of the present application described in the above "Exemplary Method" section of this specification.
[0210] The processor 801 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
[0211] As a non-volatile computer-readable storage medium, the storage medium 802 can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The memory can include at least one type of storage medium. For example, it can include flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (RAM), a static random access memory (SRAM), a programmable read-only memory (PROM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic memory, a magnetic disk, an optical disk, and so on. The memory is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The storage medium 802 in the embodiments of the present application can also be a circuit or any other device capable of implementing a storage function, for storing program instructions and / or data.
[0212] Optionally, the embodiments of the present application further provide a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the processor executes the following steps:
[0213] Obtain the position information of the player character in the current frame, where the position information includes: map block coordinates and grid coordinates within the block;
[0214] Construct a field of view map corresponding to the player character in the current frame based on the position information of the player character and the field of view range of the virtual camera;
[0215] Determine the distance information between each grid in the field of view map and the player character, and determine the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character;
[0216] If the currently pathfinding object in the current frame is within the field of view map corresponding to the player character, generate pathfinding navigation information for the currently pathfinding object in the current frame based on the grid information where the pathfinding object is located in the field of view map and the velocity direction information of each grid relative to the player character.
[0217] In a feasible implementation, when the processor constructs the field of view map corresponding to the player character in the current frame according to the position information of the player character and the size of the field of view range of the virtual camera, it specifically is used for: determining the bounding box of the field of view range according to the field of view range of the virtual camera; the boundaries of the bounding box are aligned with the map grids;
[0218] Determine the construction parameters of the field of view map corresponding to the player character according to the bounding box of the field of view range; the construction parameters include: the number of rows and columns of the field of view map;
[0219] Construct the field of view map corresponding to the player character according to the position information of the player character and the construction parameters.
[0220] In a feasible implementation, when the processor constructs the field of view map corresponding to the player character according to the position information of the player character and the construction parameters, it specifically is used for: centering on the map grid where the player character is located, constructing a field of view map with M rows and N columns respectively according to the number of rows and columns of the field of view map, and taking the field of view map with M rows and N columns as the field of view map corresponding to the player character, where M is the number of rows and N is the number of columns.
[0221] In a feasible implementation, when the processor determines the distance information between each grid in the field of view map and the player character, it specifically is used for: determining the coordinates of the target grid of the player character relative to the field of view map according to the size of the field of view map;
[0222] Taking the target grid as the currently traversed grid, sequentially determine the adjacent grids of the currently traversed grid in the field of view map, and determine the distance of the adjacent grids of the currently traversed grid according to the distance of the currently traversed grid;
[0223] Determine the newly traversed cell from adjacent cells, and based on the distance of the newly traversed cell currently being traversed, determine the distances of the adjacent cells of the newly traversed cell currently being traversed;
[0224] Iteratively execute until all cells within the field of view map have been traversed, and use the determined distance of each cell as the distance information between each cell and the player character.
[0225] In a feasible implementation, when the processor executes taking the target cell as the cell currently being traversed and sequentially determines the adjacent cells of the cell currently being traversed, it is specifically used for: if the adjacent cell of the cell currently being traversed has been traversed, delete the traversed cell from the adjacent cells of the cell currently being traversed.
[0226] In a feasible implementation, when the processor executes determining the distances of the adjacent cells of the cell currently being traversed based on the distance of the cell currently being traversed, it is specifically used for: based on the coordinates of the adjacent cell, the position information of the player character, and the position information of the preset obstacles marked in the current game map, determine whether the adjacent cell is an obstacle cell;
[0227] If the adjacent cell is not an obstacle cell, determine the distances of the adjacent cells of the cell currently being traversed based on the distance of the cell currently being traversed;
[0228] If the adjacent cell is an obstacle cell, determine the distance of the adjacent cell as the preset distance.
[0229] In a feasible implementation, when the processor executes determining whether the adjacent cell is an obstacle cell based on the coordinates of the adjacent cell, the position information of the player character, and the position information of the preset obstacles marked in the current game map, it is specifically used for: based on the coordinates of the adjacent cell and the position information of the player character, convert the coordinates of the adjacent cell into map cell coordinates;
[0230] If the map cell coordinates corresponding to the adjacent cell are the same as the map cell coordinates of the preset obstacles marked in the game map, determine that the adjacent cell is an obstacle cell.
[0231] In a feasible implementation, when the processor executes converting the coordinates of the adjacent cell into map cell coordinates based on the coordinates of the adjacent cell and the position information of the player character, it is specifically used for: if the sum of the in-block cell abscissa of the player character and the abscissa of the adjacent cell is greater than or equal to the width value of a single map block, subtract the width value from the sum of the in-block cell abscissa of the player character and the abscissa of the adjacent cell to obtain the in-block cell abscissa in the map cell coordinates corresponding to the adjacent cell; and add 1 to the map block abscissa of the player character to obtain the map block abscissa in the map cell coordinates corresponding to the adjacent cell;
[0232] If the sum of the abscissa of the grid within the block of the player character and the abscissa of the adjacent grid is less than a preset value, then based on the sum of the abscissa of the grid within the block of the player character, the abscissa of the adjacent grid, and the width value, obtain the abscissa of the grid within the block in the map grid coordinates corresponding to the adjacent grid; and subtract 1 from the map block abscissa of the player character to obtain the map block abscissa in the map grid coordinates corresponding to the adjacent grid.
[0233] If the sum of the ordinate of the grid within the block of the player character and the ordinate of the adjacent grid is greater than or equal to the length value of a single map block, then subtract the length value from the sum of the ordinate of the grid within the block of the player character and the ordinate of the adjacent grid to obtain the ordinate of the grid within the block in the map grid coordinates corresponding to the adjacent grid; and add 1 to the map block ordinate of the player character to obtain the map block ordinate in the map grid coordinates corresponding to the adjacent grid.
[0234] If the ordinate of the grid within the block of the player character and the ordinate of the adjacent grid are less than a preset value, then based on the sum of the ordinate of the grid within the block of the player character, the ordinate of the adjacent grid, and the length value, obtain the ordinate of the grid within the block in the map grid coordinates corresponding to the adjacent grid; and subtract 1 from the map block ordinate of the player character to obtain the map block ordinate in the map grid coordinates corresponding to the adjacent grid.
[0235] In a feasible implementation, when the processor executes to determine the velocity direction information of each grid relative to the player character according to the distance information between each grid and the player character, it is specifically used to: sequentially traverse each grid in the field of view map, and determine the gradient vector of the currently traversed grid according to the distance information of the adjacent grids of the currently traversed grid.
[0236] Perform normalization processing on the gradient vector to obtain the velocity direction information of the currently traversed grid relative to the player character.
[0237] In a feasible implementation, the processor is further used to: if there is an obstacle grid among the adjacent grids of the currently traversed grid, then determine the velocity direction information of the currently traversed grid relative to the player character according to the direction of the obstacle grid relative to the currently traversed grid.
[0238] In a feasible implementation, when the processor executes to generate the pathfinding navigation information of the currently pathfinding object in the current frame according to the grid information of the object to be pathfinding in the field of view map and the velocity direction information of each grid relative to the player character, it is specifically used to: according to the grid information of the object to be pathfinding in the field of view map, obtain the velocity direction information of the grid where the object to be pathfinding is located in the field of view map relative to the player character.
[0239] Use the speed direction information of the grid where the path - finding object is located in the field - of - view map relative to the player character as the path - finding navigation information of the current path - finding object in the current frame.
[0240] In a feasible implementation, after the processor determines the speed direction information of each grid relative to the player character according to the distance information between each grid and the player character, it is further used to: if the current path - finding object in the current frame is not within the field - of - view map corresponding to the player character, then determine the path - finding navigation information of the current path - finding object in the current frame according to the position information of the path - finding object, the position information of the player character, and the pre - generated path - finding topology information corresponding to the current game map; the path - finding topology information includes the relative speed direction information between any two map grids in the game map.
[0241] In the above - mentioned manner, the electronic device can construct the field - of - view map corresponding to the player character by obtaining the position information of the player character in the current frame, calculate the distance between each field - of - view grid in the field - of - view map and the field - of - view grid where the player character is located, and generate the speed direction information of each field - of - view grid relative to the player character's field - of - view grid based on the distance. Thus, when the path - finding object is within the player's field - of - view map, the speed direction information of the field - of - view grid relative to the player's field - of - view grid can be used for path - finding navigation of the object to be trained. Since the path - finding object is relatively close to the player character when it is within the field - of - view map, using the speed direction information generated by the distance information for path - finding navigation makes the generated speed direction point to the position of the player character faster, and the navigation is smoother. Therefore, when the path - finding object follows the path - finding navigation information for path - finding, the path - finding path is smoother and the visual experience of the player character is more realistic.
[0242] In addition, for the path - finding object that is not within the field - of - view map of the player character, the path - finding navigation information of the path - finding object can be found and obtained according to the pre - generated path - finding topology information corresponding to the game map. Since the path - finding object is far from the player character when it is not within the field - of - view range of the player character, the requirement for the smoothness of the path - finding result is relatively low. The pre - calculated path - finding topology information can quickly obtain the path - finding navigation information and reduce the amount of path - finding data calculation, thus solving the problem of real - time navigation of large maps.
[0243] In the embodiments of the present application, when the computer program is run by the processor, it can also execute other machine - readable instructions to execute the methods described in other parts of the embodiments. For the specific method steps and principles of execution, refer to the description of the embodiments and will not be elaborated in detail here.
[0244] In several embodiments provided by this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0245] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0246] In addition, in each embodiment of this application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of a combination of hardware and software functional units.
[0247] The above integrated units implemented in the form of software functional units can be stored in a computer-readable storage medium. The above software functional units stored in a storage medium include several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to execute some steps of the methods described in each embodiment of this application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (English: Read-Only Memory, abbreviated as: ROM), random access memories (English: Random Access Memory, abbreviated as: RAM), magnetic disks or optical discs that can store program codes.
Claims
1. A map-based pathfinding method, characterized in that, include: Obtain the position information of the player character in the current frame, including: map tile coordinates and grid coordinates within the tile; Based on the player character's position information and the virtual camera's field of view, construct the field of view map corresponding to the player character in the current frame; Determine the distance information between each grid in the field of view and the player character, and based on the distance information between each grid and the player character, determine the velocity direction information of each grid relative to the player character; If the object to be navigated to in the current frame is located within the player character's field of view, then navigation information for the object to be navigated to in the current frame is generated based on the grid information of the object within the field of view and the velocity direction information of each grid relative to the player character.
2. The method according to claim 1, characterized in that, The step of constructing the field-of-view map corresponding to the player character in the current frame based on the player character's position information and the virtual camera's field of view includes: Based on the field of view of the virtual camera, determine the bounding box of the field of view; the boundary of the bounding box is aligned with the map grid. Based on the bounding box of the field of view, the construction parameters of the field of view map corresponding to the player character are determined; the construction parameters include: the number of rows and columns of the field of view map; Based on the player character's location information and the construction parameters, construct the player character's corresponding field of vision map.
3. The method according to claim 2, characterized in that, The step of constructing the vision map corresponding to the player character based on the player character's position information and the construction parameters includes: Centered on the map grid where the player character is located, construct an M-row N-column vision map according to the number of rows and columns of the vision map. Use the M-row N-column vision map as the vision map corresponding to the player character, where M is the number of rows and N is the number of columns.
4. The method according to any one of claims 1-3, characterized in that, Determining the distance information between each grid within the view map and the player character includes: Based on the size of the view map, determine the coordinates of the player character relative to the target grid in the view map; The target cell is taken as the currently traversed cell. The adjacent cells of the currently traversed cell within the field of view are determined sequentially. The distance between the adjacent cells of the currently traversed cell is determined based on the distance of the currently traversed cell. Determine the new cell to be traversed from the adjacent cells, and determine the distance between the adjacent cells of the new cell to be traversed based on the distance of the new cell to be traversed. The process is iterated until all the cells in the field of view have been traversed, and the distance of each cell is determined as the distance information between each cell and the player character.
5. The method according to claim 4, characterized in that, The step of taking the target cell as the currently traversed cell and sequentially determining the adjacent cells of the currently traversed cell includes: If the adjacent cells of the currently traversed cell have already been traversed, then the traversed cells are removed from the adjacent cells of the currently traversed cell.
6. The method according to claim 4, characterized in that, Determining the distance between adjacent cells of the currently traversed cell based on the distance of the currently traversed cell includes: Based on the coordinates of the adjacent grid, the position information of the player character, and the position information of the preset obstacles marked in the current game map, determine whether the adjacent grid is an obstacle grid; If the adjacent cell is not an obstacle cell, then the distance between the adjacent cells of the currently traversed cell is determined based on the distance of the currently traversed cell. If the adjacent cell is an obstacle cell, then the distance between the adjacent cells is determined to be a preset distance.
7. The method according to claim 6, characterized in that, The step of determining whether an adjacent cell is an obstacle cell based on the coordinates of the adjacent cells, the player character's position information, and the position information of preset obstacles marked on the current game map includes: Based on the coordinates of the adjacent grid cells and the player character's position information, the coordinates of the adjacent grid cells are converted into map grid coordinates; If the map grid coordinates corresponding to the adjacent grid are consistent with the map grid coordinates of a preset obstacle marked in the game map, then the adjacent grid is determined to be an obstacle grid.
8. The method according to claim 7, characterized in that, The step of converting the coordinates of the adjacent grid cells into map grid coordinates based on the coordinates of the adjacent grid cells and the player character's position information includes: If the sum of the horizontal coordinate of the player character's intra-block grid and the horizontal coordinate of the adjacent grid is greater than or equal to the width of a single map tile, then the sum of the horizontal coordinate of the player character's intra-block grid and the horizontal coordinate of the adjacent grid is subtracted from the width value to obtain the horizontal coordinate of the intra-block grid in the map tile coordinates corresponding to the adjacent grid; and the horizontal coordinate of the player character's map tile is incremented by 1 to obtain the horizontal coordinate of the map tile in the map tile coordinates corresponding to the adjacent grid. If the sum of the horizontal coordinate of the player character's block grid and the horizontal coordinate of the adjacent grid is less than a preset value, then the horizontal coordinate of the block grid in the map grid coordinates corresponding to the adjacent grid is obtained based on the sum of the horizontal coordinate of the player character's block grid, the horizontal coordinate of the adjacent grid, and the width value; and the horizontal coordinate of the player character's map grid is subtracted by 1 to obtain the horizontal coordinate of the map grid in the map grid coordinates corresponding to the adjacent grid. If the sum of the player character's intra-block ordinate and the ordinate of the adjacent block is greater than or equal to the length of a single map tile, then the sum of the player character's intra-block ordinate and the ordinate of the adjacent block is subtracted from the length to obtain the intra-block ordinate of the map tile coordinates corresponding to the adjacent block; and the player character's map tile ordinate is incremented by 1 to obtain the map tile ordinate of the map tile coordinates corresponding to the adjacent block. If the vertical coordinate of the player character's block grid and the vertical coordinate of the adjacent grid are less than the preset value, then the vertical coordinate of the block grid in the map grid coordinates corresponding to the adjacent grid is obtained based on the sum of the vertical coordinate of the player character's block grid, the vertical coordinate of the adjacent grid, and the length value; and the vertical coordinate of the player character's map grid is subtracted by 1 to obtain the vertical coordinate of the map grid in the map grid coordinates corresponding to the adjacent grid.
9. The method according to claim 1, characterized in that, The step of determining the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character includes: The gradient vector of the currently traversed cell is determined by sequentially traversing each cell in the field of view and based on the distance information between each of the adjacent cells of the currently traversed cell. The gradient vector is normalized to obtain the velocity direction information of the currently traversed grid relative to the player character.
10. The method according to claim 9, characterized in that, Also includes: If there are obstacle cells among the adjacent cells of the currently traversed cell, the velocity direction information of the currently traversed cell relative to the player character is determined based on the direction of the obstacle cells relative to the currently traversed cell.
11. The method according to claim 1, characterized in that, The step of generating pathfinding navigation information for the current object in the current frame based on the grid information of the object to be pathfinded within the view map and the velocity and direction information of each grid relative to the player character includes: Based on the grid information of the object to be navigated in the view map, obtain the velocity and direction information of the grid of the object to be navigated in the view map relative to the player character; The velocity and direction information of the grid in which the object to be navigated is located within the view map relative to the player character is used as the navigation information for the object to be navigated in the current frame.
12. The method according to claim 1, characterized in that, After determining the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character, the method further includes: If the object to be traversed in the current frame is not within the player character's field of view, then the pathfinding navigation information of the object to be traversed in the current frame is determined based on the position information of the object to be traversed, the position information of the player character, and the pathfinding topology information corresponding to the pre-generated current game map; the pathfinding topology information includes the relative velocity direction information between any two map grids in the game map.
13. A map-based wayfinding device, characterized in that, include: Get module, build module, determine module, generate module; The acquisition module is used to acquire the position information of the player character in the current frame, and the position information includes: map tile coordinates and grid coordinates within the tile; The construction module is used to construct a field-of-view map corresponding to the player character in the current frame based on the player character's position information and the virtual camera's field of view. The determining module is used to determine the distance information between each grid in the field of view and the player character, and to determine the velocity direction information of each grid relative to the player character based on the distance information between each grid and the player character; The generation module is used to generate pathfinding navigation information for the current object to be pathfinded in the current frame if the object to be pathfinded in the current frame is located within the field of view corresponding to the player character, based on the grid information of the object to be pathfinded in the field of view and the velocity direction information of each grid relative to the player character.
14. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores program instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the program instructions to perform the map navigation method as described in any one of claims 1 to 12.
15. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, performs the map pathfinding method as described in any one of claims 1 to 12.