Pathfinding method, device, electronic device and readable storage medium
By using mesh maps and polygon pathfinding algorithms in the game, the pathfinding pathfinding problem in the existing technology is solved and the visual effect is improved.
Patent Information
- Application Number
- CN202111332926.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-11
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2041-11-11
Smart Images

Figure CN114053713B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet technology, and in particular to a path-finding method, device, electronic device and storage medium. Background Art
[0002] With the development of game technology, game maps are getting bigger and bigger. Especially for SLG (Simulation Game, strategy game), smooth and efficient pathfinding can bring players a better user experience. In the game, whether it is a virtual character controlled by the player or a virtual character controlled by the system, it is a common behavior to find a way from one place to another, especially when completing various tasks, long-distance pathfinding is often required.
[0003] In the prior art, a polygonal pathfinding algorithm is usually used for pathfinding. However, although this method can improve the efficiency of pathfinding in larger scenes, due to the small number of pathfinding directions, the resulting pathfinding path is jagged, which in turn affects the visual effect. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a path-finding method, device, electronic device and storage medium.
[0005] In a first aspect, an embodiment of the present disclosure provides a pathfinding method, including:
[0006] In response to the pathfinding instruction, acquiring position information of the virtual object, wherein the position information includes an initial position and a target position of the virtual object in the virtual scene;
[0007] Based on the position information and a grid map of the virtual scene, determining a first pathfinding path from the initial position to the target position according to a first pathfinding direction; the grid map is composed of at least one polygonal cell;
[0008] The first pathfinding path is optimized according to a second pathfinding direction to obtain a target pathfinding path; the second pathfinding direction has more directions than the first pathfinding direction.
[0009] In the disclosed embodiment, since the first routing direction is less than the second routing direction, that is, when determining the first routing path from the initial position to the target position, the first routing direction with fewer directions is used for routing, thereby ensuring the efficiency of using a polygonal routing algorithm to determine the routing path; in addition, after obtaining the first routing path, the first routing path is optimized according to the second routing direction with more directions, that is, the jaggedness of the first routing path is optimized by using the second routing direction with more directions, so that the obtained target routing path is more beautiful and the visual effect of the obtained target routing path is improved.
[0010] According to the first aspect, in a possible implementation manner, the polygonal cell is a quadrilateral cell or a hexagonal cell.
[0011] In the disclosed embodiment, since the polygonal cells include quadrilateral cells or hexagonal cells, the visual effect of the path finding path can be improved while ensuring the path finding efficiency. Among them, the hexagonal grid map is like a honeycomb, and the hexagon is the highest polygon that can represent a plane in nature, which can greatly improve the game expression, attract more players, and enhance the user's visual experience.
[0012] According to the first aspect, in a possible implementation, the first path-finding direction includes the edge direction of the polygonal cell, and the second path-finding direction includes the edge direction of the polygonal cell and the vertex direction of the polygonal cell; wherein, the edge direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the midpoint of the edge of the polygonal cell, and the vertex direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the vertex of the polygonal cell.
[0013] In the disclosed embodiment, the visual aesthetics of the path finding path may be enhanced by optimizing the first path finding path in terms of the edge direction and vertex direction of the polygon.
[0014] According to the first aspect, in a possible implementation manner, optimizing the first pathfinding path according to the second pathfinding direction to obtain a target pathfinding path includes:
[0015] Determine a target polygonal cell according to each polygonal cell on the first pathfinding path;
[0016] Determine whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition;
[0017] In the case where the two neighbor polygonal cells meet the preset conditions, the two neighbor polygonal cells are processed according to the vertex directions of the neighbor polygonal cells to obtain the target pathfinding path.
[0018] In the disclosed embodiment, by traversing each polygonal cell on the first path finding path, not only the first path finding path can be optimized, but also the optimization accuracy can be guaranteed.
[0019] According to the first aspect, in a possible implementation manner, determining a target polygonal cell according to each polygonal cell on the first pathfinding path includes:
[0020] Determine a first sub-pathfinding path on the first pathfinding path, which is composed of a plurality of continuous polygonal cells along the edge direction or the vertex direction;
[0021] For each first sub-pathfinding path, the last polygon cell is selected as the target polygon cell.
[0022] In the disclosed embodiment, the last polygonal cell is selected as the target polygonal cell for each first sub-pathfinding path, so that the optimization efficiency can be improved while achieving path optimization.
[0023] According to the first aspect, in a possible implementation manner, determining whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition includes:
[0024] When the direction of the line connecting the center points of the two neighbor polygonal cells is the direction of the vertices of the neighbor polygonal cells and the polygonal cells connected between the two neighbor polygonal cells are not obstacles, it is determined that the two neighbor polygonal cells meet the preset condition.
[0025] In the embodiment of the present disclosure, when the polygonal cell connected between the two neighboring polygonal cells is not an obstacle, determining that the two neighboring polygonal cells meet the preset conditions can avoid determining an inaccessible cell as a path finding path, which may lead to a path finding error.
[0026] According to the first aspect, in a possible implementation manner, processing the two neighboring polygonal cells according to vertex directions of the neighboring polygonal cells to obtain the target pathfinding path includes:
[0027] Process the two vertices of the two neighboring polygonal cells that are closest to each other according to the shortest path to obtain a second pathfinding path, and directly use the second pathfinding path as the target pathfinding path; or
[0028] The two vertices of the two neighboring polygonal cells that are closest to each other are processed according to the shortest path to obtain a second pathfinding path, and the path in the edge direction and / or the path in the vertex direction in the second pathfinding path is simplified to obtain the target pathfinding path.
[0029] In the embodiments of the present disclosure, by processing the path according to the shortest path or simplifying the processing, the amount of information of the target path can be reduced, which is convenient for storage and transmission.
[0030] According to the first aspect, in a possible implementation, the simplifying the path in the edge direction and / or the path in the vertex direction in the second path finding path to obtain the target path finding path includes:
[0031] When the number of polygonal cells existing on the path in the side direction of the second path finding path is greater than a preset threshold, the other polygonal cells on the path in the side direction except the endpoints are removed; and / or,
[0032] When the number of polygonal cells existing on the path in the vertex direction of the second path finding path is greater than a preset threshold, other polygonal cells except the endpoints on the path in the vertex direction are eliminated.
[0033] In the disclosed embodiment, by eliminating polygonal cells other than endpoints, the information of the target path can be minimized, saving memory and the amount of data transmitted over the network.
[0034] According to the first aspect, in a possible implementation manner, the polygonal cell is a quadrilateral cell, and after the shortest path processing is performed to obtain the second path finding path, the method further includes:
[0035] Determine whether there is an available polygonal cell between a front adjacent cell and a rear spaced cell of each polygonal cell in the second pathfinding path, wherein the available polygonal cell is connected to the front adjacent cell and the rear spaced cell respectively;
[0036] In the case that there is an available polygonal cell between the front adjacent cell and the rear adjacent cell of the current polygonal cell, the current polygonal cell and the rear adjacent polygonal cell of the current polygonal cell are replaced with the available polygonal cell.
[0037] In the disclosed embodiment, the path finding path can be further optimized to further enhance the visual effect.
[0038] In a second aspect, an embodiment of the present disclosure provides a pathfinding device, including:
[0039] A position acquisition module, configured to acquire position information of a virtual object in response to a pathfinding instruction, wherein the position information includes an initial position and a target position of the virtual object in a virtual scene;
[0040] A path determination module, configured to determine a first path finding path from the initial position to the target position according to a first path finding direction based on the position information and a grid map of the virtual scene; the grid map being composed of at least one polygonal cell;
[0041] A path optimization module is used to optimize the first path finding path according to a second path finding direction to obtain a target path finding path; the second path finding direction has more directions than the first path finding direction.
[0042] According to the second aspect, in a possible implementation manner, the polygonal cell is a quadrilateral cell or a hexagonal cell.
[0043] According to the second aspect, in a possible implementation, the first path-finding direction includes the edge direction of the polygonal cell, and the second path-finding direction includes the edge direction of the polygonal cell and the vertex direction of the polygonal cell; wherein, the edge direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the midpoint of the edge of the polygonal cell, and the vertex direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the vertex of the polygonal cell.
[0044] According to the second aspect, in a possible implementation manner, the path optimization module is specifically configured to:
[0045] Determine a target polygonal cell according to each polygonal cell on the first pathfinding path;
[0046] Determine whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition;
[0047] In the case where the two neighbor polygonal cells meet the preset conditions, the two neighbor polygonal cells are processed according to the vertex directions of the neighbor polygonal cells to obtain the target pathfinding path.
[0048] According to the second aspect, in a possible implementation manner, the path optimization module is specifically configured to:
[0049] Determine a first sub-pathfinding path on the first pathfinding path, which is composed of a plurality of continuous polygonal cells along the edge direction or the vertex direction;
[0050] For each first sub-pathfinding path, select the last polygon cell as the target polygon cell.
[0051] According to the second aspect, in a possible implementation manner, the path optimization module is specifically configured to:
[0052] When the direction of the line connecting the center points of the two neighbor polygonal cells is the direction of the vertices of the neighbor polygonal cells and the polygonal cells connected between the two neighbor polygonal cells are not obstacles, it is determined that the two neighbor polygonal cells meet the preset condition.
[0053] According to the second aspect, in a possible implementation manner, the path optimization module is specifically configured to:
[0054] Process the two vertices of the two neighboring polygonal cells that are closest to each other according to the shortest path to obtain a second pathfinding path, and directly use the second pathfinding path as the target pathfinding path; or
[0055] The two vertices of the two neighboring polygonal cells that are closest to each other are processed according to the shortest path to obtain a second pathfinding path, and the path in the edge direction and / or the path in the vertex direction in the second pathfinding path is simplified to obtain the target pathfinding path.
[0056] According to the second aspect, in a possible implementation manner, the path optimization module is specifically configured to:
[0057] When the number of polygonal cells existing on the path in the side direction of the second path finding path is greater than a preset threshold, the other polygonal cells on the path in the side direction except the endpoints are removed; and / or,
[0058] When the number of polygonal cells existing on the path in the vertex direction of the second path finding path is greater than a preset threshold, other polygonal cells except the endpoints on the path in the vertex direction are eliminated.
[0059] According to the second aspect, in a possible implementation manner, the polygonal cell is a quadrilateral cell, and the path optimization module is specifically used for:
[0060] Determine whether there is an available polygonal cell between a front adjacent cell and a rear spaced cell of each polygonal cell in the second pathfinding path, wherein the available polygonal cell is connected to the front adjacent cell and the rear spaced cell respectively;
[0061] In the case that there is an available polygonal cell between the front adjacent cell and the rear adjacent cell of the current polygonal cell, the current polygonal cell and the rear adjacent polygonal cell of the current polygonal cell are replaced with the available polygonal cell.
[0062] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the path-finding method described in the first aspect is performed.
[0063] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the path-finding method as described in the first aspect is executed.
[0064] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0066] Figure 1 A schematic diagram of a path finding path in the prior art provided by an embodiment of the present disclosure is shown;
[0067] Figure 2 A schematic diagram showing an execution subject of a path-finding method provided by an embodiment of the present disclosure;
[0068] Figure 3 A flow chart of a path finding method provided by an embodiment of the present disclosure is shown;
[0069] Figure 4 A schematic diagram showing a virtual color perception position in a virtual scene provided by an embodiment of the present disclosure;
[0070] Figure 5 A schematic diagram showing a first path finding path provided by an embodiment of the present disclosure is shown;
[0071] Figure 6 A schematic diagram showing another first path finding path provided by an embodiment of the present disclosure is shown;
[0072] Figure 7 A flow chart of a method for optimizing a first pathfinding path provided by an embodiment of the present disclosure is shown;
[0073] Figure 8 Shows Figure 5 Schematic diagram of the first pathfinding path after preliminary optimization;
[0074] Fig. 9 Shows Figure 6Schematic diagram of the first pathfinding path after preliminary optimization;
[0075] Fig.10 Shows Figure 5 Schematic diagram of the first pathfinding path after sub-optimization;
[0076] Fig.11 Shows Figure 6 Schematic diagram of the first pathfinding path after sub-optimization;
[0077] Fig.12 Shows Figure 6 Schematic diagram of the first pathfinding path after re-optimization;
[0078] Fig.13 A schematic diagram of the structure of a path-finding device provided by an embodiment of the present disclosure is shown;
[0079] Fig.14 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0080] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0081] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0082] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0083] With the development of game technology, game maps are getting bigger and bigger, and smooth and efficient pathfinding can bring players a better user experience. In the game, whether it is a virtual character controlled by the player or a virtual character controlled by the system, it is a common behavior to find a way from one place to another, especially when completing various tasks, long-distance pathfinding is often required.
[0084] In the prior art, a polygonal pathfinding algorithm is usually used for pathfinding. However, although this method can improve the efficiency of pathfinding in larger scenes, due to the small number of pathfinding directions, the resulting pathfinding path is jagged, which in turn affects the visual effect.
[0085] Specifically, see Figure 1 As shown, the polygonal path finding algorithm in the prior art is used to obtain the path L, from Figure 1 It can be seen that there is sawtooth A in path L, which affects the visual effect of path L.
[0086] To solve the above problems, the present disclosure provides a pathfinding method, comprising: in response to a pathfinding instruction, obtaining position information of a virtual object, wherein the position information includes an initial position and a target position of the virtual object in a virtual scene; based on the position information and a grid map of the virtual scene, determining a first pathfinding path from the initial position to the target position according to a first pathfinding direction; the grid map is composed of at least one polygonal cell; optimizing the first pathfinding path according to a second pathfinding direction to obtain a target pathfinding path; the second pathfinding direction has more directions than the first pathfinding direction.
[0087] In the disclosed embodiment, since the first routing direction is less than the second routing direction, that is, when determining the first routing path from the initial position to the target position, the first routing direction with fewer directions is used for routing, thereby ensuring the efficiency of using a polygonal routing algorithm to determine the routing path; in addition, after obtaining the first routing path, the first routing path is optimized according to the second routing direction with more directions, that is, the jaggedness of the first routing path is optimized by using the second routing direction with more directions, so that the obtained target routing path is more beautiful and the visual effect of the obtained target routing path is improved.
[0088] See also Figure 2 , which is a schematic diagram of an execution subject of the path finding method provided in an embodiment of the present disclosure, wherein the execution subject of the method is an electronic device 100, wherein the electronic device 100 may include a terminal and a server. For example, the method may be applied to a terminal, and the terminal may be Figure 1 The smart phone 10, desktop computer 20, notebook computer 30, etc. shown in FIG. Figure 1The method can also be applied to the server 40, or can be applied to the implementation environment composed of the terminal and the server 40. The server 40 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data and artificial intelligence platforms.
[0089] It should be noted that, in some embodiments, the server 40 can communicate with the smart phone 10, the desktop computer 20 and the laptop computer 30 respectively through the network 50. The network 50 can include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0090] In addition, the path-finding method may also be software running in a terminal or a server, such as an application program with a path-finding function, etc. In some possible implementations, the path-finding method may be implemented by a processor calling computer-readable instructions stored in a memory.
[0091] See also Figure 3 As shown, it is a flow chart of the path finding method provided by the embodiment of the present disclosure, and the path finding method includes the following S101-S103:
[0092] S101, in response to a path-finding instruction, obtaining position information of a virtual object, wherein the position information includes an initial position and a target position of the virtual object in a virtual scene.
[0093] By way of example, the application scenarios to which the present application is applicable are introduced. The present application can be applied to the field of game technology, especially in the process of playing a game, when a virtual character controlled by a player user needs to find a way from the location of the virtual character to another place, for example, a virtual character in a virtual scene (game scene) needs to move to complete their respective tasks in the game scene, or go to certain marked places and specific locations, etc.
[0094] Generally, in games, virtual characters can be controlled by players or by the system (such as NPCs, wild monsters, virtual teammates, etc.). For virtual characters controlled by players, the player can manually control the virtual character to move to the destination, or the player can specify a destination (marked location) and the virtual character will move to the destination by itself; virtual characters controlled by the system imitate the player's control over the virtual character, and the system needs to control the virtual character to reach the specified destination and complete the corresponding task. For SLG games, virtual characters are usually troops controlled by players, and need to move from one destination to another specified destination to complete actions such as marching and fighting.
[0095] For the destination specified by the player and the virtual character controlled by the system, since there is no player operation to indicate the route of the virtual character, pathfinding is required in the game scene to ensure that the virtual character can reach the specified destination. In the process of pathfinding, factors such as the starting point, destination, and pathfinding range of the virtual character need to be comprehensively considered to ensure the availability and efficiency of the pathfinding route.
[0096] For example, see Figure 4 As shown, in the game scene, the player specifies that the virtual character 10 needs to move from the initial position (current position) to the target position C. At this time, the corresponding path-finding instructions will be generated according to the target position C specified by the player. Of course, for the virtual characters controlled by the system, the path-finding instructions can also be automatically generated by the system, which is not limited here.
[0097] S102, based on the position information and a grid map of the virtual scene, determining a first pathfinding path from the initial position to the target position according to a first pathfinding direction; the grid map is composed of at least one polygonal cell.
[0098] For example, please participate again Figure 4 In order to enable the virtual corner 10 on the grid map to avoid obstacles and reach the target position C, it is necessary to perform a pathfinding search on the grid map according to the first pathfinding direction to obtain a first pathfinding path. The grid map is composed of at least one polygonal cell, which can be a quadrilateral cell or a hexagonal cell, without specific limitation. Each polygonal cell can be regarded as a node. Specifically, the starting node corresponding to the initial position can be used as the initial current node. By performing a pathfinding search on all nodes adjacent to the current node, the first pathfinding path is finally determined. The first pathfinding path is a moving path that allows a moving object to avoid obstacles from the starting node to the ending node.
[0099] For example, see Figure 5 As shown, it is a schematic diagram of a first path finding path provided by an embodiment of the present disclosure, and the first path finding path L1 is obtained based on a hexagonal grid map. Figure 5 As shown, the first path finding path L1 is formed by following the first path finding direction ( Figure 5 The first path finding direction S1 is obtained by searching in the hexagonal grid map in the direction of the middle arrow) S1. The first path finding direction S1 includes the side direction of the polygonal cell, and the side direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the midpoint of the side of the polygonal cell. In the embodiment disclosed herein, the side direction of the polygonal cell refers to the side direction of the hexagon.
[0100] For example, see Figure 6As shown, it is a schematic diagram of another first path finding path provided by an embodiment of the present disclosure, and the first path finding path L2 is obtained based on a quadrilateral grid map. Figure 6 As shown, the first path finding path L2 is formed by following the first path finding direction ( Figure 6 The edge direction of the polygonal cell refers to the edge direction of the quadrilateral.
[0101] S103, optimizing the first pathfinding path according to a second pathfinding direction to obtain a target pathfinding path; the second pathfinding direction has more directions than the first pathfinding direction.
[0102] Exemplarily, after obtaining the first pathfinding path, it is necessary to optimize the first pathfinding path according to the second pathfinding direction so that the target pathfinding path is smoother. The second pathfinding direction has more directions than the first pathfinding direction, that is, the second pathfinding direction includes the vertex direction of the polygonal cell in addition to the edge direction of the polygonal cell; the vertex direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the vertex of the polygonal cell.
[0103] In the disclosed embodiment, since the first routing direction is less than the second routing direction, that is, when determining the first routing path from the initial position to the target position, the first routing direction with fewer directions is used for routing, thereby ensuring the efficiency of using a polygonal routing algorithm to determine the routing path; in addition, after obtaining the first routing path, the first routing path is optimized according to the second routing direction with more directions, that is, the jaggedness of the first routing path is optimized by using the second routing direction with more directions, so that the obtained target routing path is more beautiful and the visual effect of the obtained target routing path is improved.
[0104] In some embodiments, with respect to the above step S103, when the first pathfinding path is optimized according to the second pathfinding direction to obtain the target pathfinding path, refer to Figure 7 As shown, the following S1031 to S1036 may be included:
[0105] S1031, determine whether there are multiple continuous polygonal cells along the edge direction or the vertex direction on the first pathfinding path; if so, execute step S1032; if not, execute step S1033.
[0106] For example, please refer again to Figure 5, taking the first path L1 as an example, on the first path L1, cells (3,1) and (3,2) are two consecutive cells along the edge direction on the first path L1, cells (3,2), (4,3), (5,3), and (6,4) are four consecutive cells along the edge direction on the first path L1. Figure 5 It can be seen that when there are multiple continuous cells in the edge direction, the cells between the first cell (3,2) and the last cell (6,4) do not have jagged conditions. Therefore, during the optimization process, only the first cell (3,2) and the last cell (6,4) can be processed, which can improve the efficiency of the optimization process. Therefore, if yes, step S1032 can be executed to determine the first polygonal cell and the last polygonal cell among the multiple continuous polygonal cells in the edge direction or the vertex direction as target polygonal cells; if no, step S1033 can be executed to determine each polygonal cell on the first pathfinding path as a target polygonal cell. The target polygonal cell refers to the polygonal cell that needs to be optimized.
[0107] S1032: Determine the first polygonal cell and the last polygonal cell among a plurality of continuous polygonal cells in the edge direction or the vertex direction as target polygonal cells.
[0108] It should be noted that when the number of continuous polygonal cells is two, such as Figure 5 If the cells (3,1) and (3,2) in the polygon are the same, then the two consecutive polygon cells can be directly used as the target cells.
[0109] S1033: Determine each polygonal cell on the first pathfinding path as a target polygonal cell.
[0110] It should be noted that, in other embodiments, step S1031 and step S1032 may be omitted, and step S1033 may be directly executed, that is, each polygonal cell on the first pathfinding path is directly traversed.
[0111] It can be understood that in other embodiments, when determining the target cell, a first sub-pathfinding path composed of multiple continuous polygonal cells along the edge direction or the vertex direction on the first pathfinding path can also be determined; for each first sub-pathfinding path, the last polygonal cell is selected as the target polygonal cell.
[0112] S1034, determining whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition; if so, executing step S1035; if not, executing step S1036.
[0113] For example, see Figure 8 As shown, for Figure 5 When optimizing the first path finding path L1, the target polygonal cell (3, 2) is taken as an example to determine whether the two neighboring polygonal cells (3, 1) and (4, 3) adjacent to the target polygonal cell (3, 2) meet the preset conditions; when the direction of the line connecting the center points of the two neighboring polygonal cells (3, 1) and (4, 3) is the vertex direction of the neighboring polygonal cells, and the polygonal cells (3, 2) and (4, 2) connected between the two neighboring polygonal cells (3, 1) and (4, 3) are not obstacles, it is determined that the two neighboring polygonal cells (3, 1) and (4, 3) meet the preset conditions.
[0114] S1035: Process the two neighboring polygonal cells according to the vertex directions of the neighboring polygonal cells to obtain the target pathfinding path.
[0115] For example, please refer again to Figure 8 , the two vertices of the two neighboring polygonal cells (3,1) and (4,3) that are closest to each other can be processed according to the shortest path to obtain the target pathfinding path. The shortest path refers to the two vertices that are closest to the two neighboring polygonal cells (3,1) and (4,3). That is, when both cells (3,2) and (4,2) are passable, the common edge a (shortest path) of cells (3,2) and (4,2) is treated as a grid.
[0116] It should be noted that during the processing, the path finding path that is already a straight non-zigzag path remains unchanged, that is, the cell (4,3) to the cell (5,3) remains unchanged, and so on, until each target polygon cell on the first path finding path L1 is traversed.
[0117] It can be understood that in some embodiments, if the optimization process is performed by traversal, starting from the starting point, it is determined in turn whether the previous hexagonal cell and the next hexagonal cell adjacent to each hexagonal cell are connected by an edge of the hexagon. For example, cell (3,1) and cell (4,3) are connected by an edge a of cell (3.2). At this time, it is necessary to determine whether the cell (4,2) on the other side of the edge a is feasible (not an obstacle). If feasible, the edge a between cell (3.2) and cell (4,3) is regarded as a grid. After that, it is traversed in sequence until each polygonal cell on the first pathfinding path L1 is traversed, and the following is obtained. Figure 8 The path finding path L11 is shown.
[0118] like Figure 8 As shown, after optimizing the target polygonal cell on the first path finding path L1, 12-direction path finding in the edge direction and vertex direction can be realized, and the jagged path can be changed into a straight line.
[0119] Please refer again Figure 6 , the following takes the quadrilateral grid map as an example. Figure 6 For quadrilateral cells, the optimization process is similar to that for hexagonal cells. Please also refer to Fig. 9 After obtaining the first pathfinding path L2, we can start traversing from the starting point (1,1). For the target cell (2,1), if the adjacent previous cell (1,1) and the next adjacent cell (2,2) have adjacent vertices, then determine whether the cell (1,2) on the other side of the vertex can pass through. If it can pass through, merge the two cells (1,2) and (2,1), and treat the vertex b as a cell. By analogy, we can get the following: Fig. 9 Path finding path L21 is shown.
[0120] It should be noted that, in some embodiments, the above-obtained path L11 and path finding path L21 can be used as the final target path finding path; in other embodiments, the above-obtained path finding path L11 and path finding path L21 can also be used as the second path finding path, and then the path in the edge direction and / or the path in the vertex direction in the second path finding path can be simplified to obtain the target path finding path.
[0121] For example, please see Figure 8 and Fig.10After obtaining the path finding path L11, when the number of polygonal cells existing on the path in the edge direction of the path finding path L11 is greater than a preset threshold, other polygonal cells on the path in the edge direction except the endpoints may be eliminated, and / or, when the number of polygonal cells existing on the path in the vertex direction of the path finding path L11 is greater than a preset threshold, other polygonal cells on the path in the vertex direction except the endpoints may be eliminated.
[0122] For example, the cells on the path in the edge direction may be cells (6,5), cells (7,5) and cells (8,6), and the cells on the path in the vertex direction may be cells between cells (10,8) and cells (18,8). Thus, cells (7,5) and cells between cells (10,8) and cells (18,8) may be deleted, and the following may be obtained: Fig.10 That is, only the turning point information on the path finding path is retained, so that the information of the entire path finding path is minimized, thereby saving memory and the amount of data transmitted over the network.
[0123] Among them, the preset threshold can be set according to specific needs. In this implementation, the preset threshold is 2. In other implementations, the preset threshold can be more, which is not limited here.
[0124] In addition, it should be noted that for quadrilateral cells, when simplifying the path in the edge direction and / or the path in the vertex direction in the second path finding path, it is similar to hexagons, but also different. The simplification of quadrilaterals is described in detail below.
[0125] See also Fig. 9 and Fig.11 As shown in the figure, after obtaining the path L21, unlike the hexagonal cells, the quadrilateral cells may still have further optimization space. At this time, it is necessary to determine whether there is a passable cell connection between the previous cell of each polygonal cell and the second cell behind it (also called the rear interval cell). If so, the cell can be enabled for pathfinding. Fig. 9 The cell (4,4) before the cell (4,5) and the second cell (6,6) after it can be connected through the cell (5,5). If the cell (5,5) is accessible, the cell (5,5) can be used to replace the cell (4,5) and the cell (5,6), and then we get Fig.11 Pathfinding path L22 in.
[0126] Therefore, in some embodiments, after obtaining the second path finding path L21, it can be determined whether there is an available polygonal cell between the front adjacent cell and the rear interval cell of each polygonal cell in the second path finding path, wherein the available polygonal cell is connected to the front adjacent cell and the rear interval cell, respectively; when there is an available polygonal cell between the front adjacent cell and the rear interval adjacent cell of the current polygonal cell, the available polygonal cell is used to replace the current polygonal cell and the rear adjacent polygonal cell of the current polygonal cell.
[0127] Please refer to Fig.12 After obtaining the path L22, similar to the simplification process of the hexagon, the cells (2,2), (3,3), (4,4) and (5,5) on the path in the vertex direction can be deleted, and only the cells (1,1), (6,6) and (7,6) at the turning point are retained.
[0128] S1036: Do not process the target polygonal cell.
[0129] It can be understood that if it is determined that the two neighboring polygonal cells (3,1) and (4,3) adjacent to the target polygonal cell (3.2) do not meet the preset conditions, then there is no need to optimize the target polygonal cell (3.2). Figure 8 The cell (4,2) in is an obstacle and is impassable. At this time, edge a cannot be treated as a cell, that is, the target polygon cell (3.2) remains the same.
[0130] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0131] Based on the same technical concept, a pathfinding device corresponding to the pathfinding method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned pathfinding method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0132] Reference Figure 8 FIG. 5 is a schematic diagram of a path-finding device 500 provided in an embodiment of the present disclosure, wherein the device comprises:
[0133] A position acquisition module 501 is used to acquire position information of a virtual object in response to a path-finding instruction, wherein the position information includes an initial position and a target position of the virtual object in a virtual scene;
[0134] A path determination module 502 is used to determine a first path finding path from the initial position to the target position according to a first path finding direction based on the position information and a grid map of the virtual scene; the grid map is composed of at least one polygonal cell;
[0135] The path optimization module 503 is used to optimize the first path finding path according to a second path finding direction to obtain a target path finding path; the second path finding direction has more directions than the first path finding direction.
[0136] In a possible implementation manner, the polygonal cell is a quadrilateral cell or a hexagonal cell.
[0137] In a possible implementation, the first path-finding direction includes the edge direction of the polygonal cell, and the second path-finding direction includes the edge direction of the polygonal cell and the vertex direction of the polygonal cell; wherein the edge direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the midpoint of the edge of the polygonal cell, and the vertex direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the vertex of the polygonal cell.
[0138] In a possible implementation, the path optimization module 503 is specifically configured to:
[0139] Determine a target polygonal cell according to each polygonal cell on the first pathfinding path;
[0140] Determine whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition;
[0141] In the case where the two neighbor polygonal cells meet the preset conditions, the two neighbor polygonal cells are processed according to the vertex directions of the neighbor polygonal cells to obtain the target pathfinding path.
[0142] In a possible implementation, the path optimization module 503 is specifically configured to:
[0143] Determine a first sub-pathfinding path on the first pathfinding path, which is composed of a plurality of continuous polygonal cells along the edge direction or the vertex direction;
[0144] For each first sub-pathfinding path, select the last polygon cell as the target polygon cell.
[0145] In a possible implementation, the path optimization module 503 is specifically configured to:
[0146] When the direction of the line connecting the center points of the two neighbor polygonal cells is the direction of the vertices of the neighbor polygonal cells and the polygonal cells connected between the two neighbor polygonal cells are not obstacles, it is determined that the two neighbor polygonal cells meet the preset condition.
[0147] In a possible implementation, the path optimization module 503 is specifically configured to:
[0148] Process the two vertices of the two neighboring polygonal cells that are closest to each other according to the shortest path to obtain a second pathfinding path, and directly use the second pathfinding path as the target pathfinding path; or
[0149] The two vertices of the two neighboring polygonal cells that are closest to each other are processed according to the shortest path to obtain a second pathfinding path, and the path in the edge direction and / or the path in the vertex direction in the second pathfinding path is simplified to obtain the target pathfinding path.
[0150] In a possible implementation, the path optimization module 503 is specifically configured to:
[0151] When the number of polygonal cells existing on the path in the side direction of the second path finding path is greater than a preset threshold, the other polygonal cells on the path in the side direction except the endpoints are removed; and / or,
[0152] When the number of polygonal cells existing on the path in the vertex direction of the second path finding path is greater than a preset threshold, other polygonal cells except the endpoints on the path in the vertex direction are eliminated.
[0153] In a possible implementation, the path optimization module 503 is specifically configured to:
[0154] Determine whether there is an available polygonal cell between a front adjacent cell and a rear spaced cell of each polygonal cell in the second pathfinding path, wherein the available polygonal cell is connected to the front adjacent cell and the rear spaced cell respectively;
[0155] In the case that there is an available polygonal cell between the front adjacent cell and the rear adjacent cell of the current polygonal cell, the current polygonal cell and the rear adjacent polygonal cell of the current polygonal cell are replaced with the available polygonal cell.
[0156] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0157] Based on the same technical concept, the embodiment of the present disclosure also provides an electronic device. Fig.10 , which is a schematic diagram of the structure of an electronic device 700 provided in an embodiment of the present disclosure, including a processor 701, a memory 702, and a bus 703. The memory 702 is used to store execution instructions, including a memory 7021 and an external memory 7022; the memory 7021 is also called an internal memory, which is used to temporarily store the operation data in the processor 701 and the data exchanged with the external memory 7022 such as a hard disk. The processor 701 exchanges data with the external memory 7022 through the memory 7021.
[0158] In the embodiment of the present application, the memory 702 is specifically used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 701. That is, when the electronic device 700 is running, the processor 701 communicates with the memory 702 through the bus 703, so that the processor 701 executes the application code stored in the memory 702, and then executes the method described in any of the above embodiments.
[0159] Among them, the memory 702 can be, but is not limited to, random access memory (Random Access Memory, RAM), read only memory (Read Only Memory, ROM), programmable read-only memory (Programmable Read-Only Memory, PROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0160] The processor 701 may be an integrated circuit chip with signal processing capabilities. The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present invention may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0161] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 700. In other embodiments of the present application, the electronic device 700 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0162] The present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the path-finding method in the above method embodiment are executed. The storage medium may be a volatile or non-volatile computer-readable storage medium.
[0163] The embodiments of the present disclosure also provide a computer program product, which carries a program code. The instructions included in the program code can be used to execute the steps of the path-finding method in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.
[0164] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0165] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0166] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0167] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0168] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0169] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A path-finding method, characterized in that: include: In response to the pathfinding instruction, acquiring position information of the virtual object, wherein the position information includes an initial position and a target position of the virtual object in the virtual scene; Based on the position information and a grid map of the virtual scene, determining a first pathfinding path from the initial position to the target position according to a first pathfinding direction; the grid map is composed of at least one polygonal cell; Optimizing the first pathfinding path according to a second pathfinding direction to obtain a target pathfinding path; the second pathfinding direction has more directions than the first pathfinding direction; The first pathfinding direction includes the edge direction of the polygonal cell, and the second pathfinding direction includes the edge direction of the polygonal cell and the vertex direction of the polygonal cell; the edge direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the midpoint of the edge of the polygonal cell, and the vertex direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the vertex of the polygonal cell. The optimizing the first pathfinding path according to the second pathfinding direction to obtain a target pathfinding path includes: Determine a target polygonal cell according to each polygonal cell on the first pathfinding path, wherein the target polygonal cell is the last polygonal cell of at least one first sub-pathfinding path composed of a plurality of continuous polygonal cells along the edge direction or the vertex direction on the first pathfinding path; Determine whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition; When the two neighboring polygonal cells meet the preset conditions, the two neighboring polygonal cells are processed according to the vertex directions of the neighboring polygonal cells to obtain the target pathfinding path, The step of determining whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition comprises: When the direction of the line connecting the center points of the two neighbor polygonal cells is the direction of the vertices of the neighbor polygonal cells and all polygonal cells connected between the two neighbor polygonal cells are not obstacles, it is determined that the two neighbor polygonal cells meet the preset condition.
2. The method according to claim 1, characterized in that The polygonal cells are quadrilateral cells or hexagonal cells.
3. The method according to claim 1, characterized in that: The determining of the target polygonal cell according to each polygonal cell on the first pathfinding path comprises: Determine a first sub-pathfinding path on the first pathfinding path, which is composed of a plurality of continuous polygonal cells along the edge direction or the vertex direction; For each first sub-pathfinding path, select the last polygon cell as the target polygon cell.
4. The method according to claim 1 or 3, characterized in that: The step of processing the two neighboring polygonal cells according to the vertex directions of the neighboring polygonal cells to obtain the target pathfinding path includes: Process the two vertices of the two neighboring polygonal cells that are closest to each other according to the shortest path to obtain a second pathfinding path, and directly use the second pathfinding path as the target pathfinding path; or The two vertices of the two neighboring polygonal cells that are closest to each other are processed according to the shortest path to obtain a second pathfinding path, and the path in the edge direction and / or the path in the vertex direction in the second pathfinding path is simplified to obtain the target pathfinding path.
5. The method according to claim 4, characterized in that The step of simplifying the path in the edge direction and / or the path in the vertex direction in the second path finding path to obtain the target path finding path includes: When the number of polygonal cells existing on the path in the side direction of the second path finding path is greater than a preset threshold, the other polygonal cells on the path in the side direction except the endpoints are removed; and / or, When the number of polygonal cells existing on the path in the vertex direction of the second path finding path is greater than a preset threshold, other polygonal cells except the endpoints on the path in the vertex direction are eliminated.
6. The method according to claim 4, characterized in that The polygonal cell is a quadrilateral cell, and after the shortest path processing is performed to obtain the second path finding path, the method further includes: Determine whether there is an available polygonal cell between a front adjacent cell and a rear spaced cell of each polygonal cell in the second pathfinding path, wherein the available polygonal cell is connected to the front adjacent cell and the rear spaced cell respectively; In the case that there is an available polygonal cell between the front adjacent cell and the rear adjacent cell of the current polygonal cell, the current polygonal cell and the rear adjacent polygonal cell of the current polygonal cell are replaced with the available polygonal cell.
7. A path-finding device, characterized in that: include: A position acquisition module, configured to acquire position information of a virtual object in response to a pathfinding instruction, wherein the position information includes an initial position and a target position of the virtual object in a virtual scene; A path determination module, configured to determine a first path finding path from the initial position to the target position according to a first path finding direction based on the position information and a grid map of the virtual scene; the grid map being composed of at least one polygonal cell; a path optimization module, configured to optimize the first path finding path according to a second path finding direction to obtain a target path finding path; the second path finding direction has more directions than the first path finding direction, The first pathfinding direction includes the edge direction of the polygonal cell, and the second pathfinding direction includes the edge direction of the polygonal cell and the vertex direction of the polygonal cell; the edge direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the midpoint of the edge of the polygonal cell, and the vertex direction of the polygonal cell refers to the direction of the line connecting the center point of the polygonal cell and the vertex of the polygonal cell. When the path optimization module optimizes the first path finding path according to the second path finding direction to obtain a target path finding path, the path optimization module is used to: Determine a target polygonal cell according to each polygonal cell on the first pathfinding path, wherein the target polygonal cell is the last polygonal cell of at least one first sub-pathfinding path composed of a plurality of continuous polygonal cells along the edge direction or the vertex direction on the first pathfinding path; Determine whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition; When the two neighboring polygonal cells meet the preset conditions, the two neighboring polygonal cells are processed according to the vertex directions of the neighboring polygonal cells to obtain the target pathfinding path, The step of determining whether two neighboring polygonal cells adjacent to the target polygonal cell meet a preset condition comprises: When the direction of the line connecting the center points of the two neighbor polygonal cells is the direction of the vertices of the neighbor polygonal cells and all polygonal cells connected between the two neighbor polygonal cells are not obstacles, it is determined that the two neighbor polygonal cells meet the preset condition.
8. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, a path-finding method as described in any one of claims 1-6 is performed.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the path-finding method as described in any one of claims 1 to 6 is executed.
Citation Information
Patent Citations
Map path finding method, device, equipment and medium
CN112699208A
Program, information storage medium and game device
JP2010068872A