Method, device and storage medium for determining path of two-dimensional virtual scene

CN116899229BActive Publication Date: 2026-10-16NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310942588.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-28
Publication Date
2026-10-16
Estimated Expiration
2043-07-28

AI Technical Summary

Technical Problem

[0002]在2D游戏的虚拟场景中,用户可以通过选择终点网格位置,然后为用户控制的虚拟角色规划移动路径,由于二维虚拟场景是采用网格制作成的,而对于网格地图而言,在规划移动路径时,传统的搜索算法是从起点网格开始朝周围发散寻找终点网格,并没有给出寻找方向,计算量较大,为了降低计算量,提出了A星算法,A星算法给出了寻找方向,使得搜索可以向着终点网格方向进行,但是在搜索过程中,每个处于搜索方向上的网格均要遍历8个方向,即:需要遍历与该网格相邻的8个网格,以此确定出移动路径,由于上述方式判断逻辑较多,从而导致确定移动路径的效率相对较低

Benefits of technology

在本申请中,确定移动路径之前,先对二维虚拟场景进行预处理,确定出各虚拟障碍物对应的第一子目标角点网格,然后再基于第一子目标角点网格构建第一子目标角点连线图,然后在基于虚拟角色的起点网格、所述虚拟角色的终点网格和第一子目标角点连线图,确定该虚拟角色的移动路径,由于第一子目标角点连线图可以使虚拟角色避过虚拟障碍物,因此通过第一子目标角点连线图确定出来的移动路径是可以通行的,并且,由于第一子目标角点连线图是基于第一子目标角点网格确定的,因此在确定第一子目标角点连线图的过程中无需对不相关的网格进行搜索,进而有效缩减了搜索空间,并且在确定第一子目标角点连线图的过程中是基于第一直达连线构建的,由于在确定第一直达连线时可以减少网格的搜索方向,即:第一候选路径之外的其它路径,以及经过不可通行网格和其他第一子目标角点网格的方向是不需要搜索的,因此有利于减少网格搜索方向,进而有利于提高移动路径的确定效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116899229B_ABST
    Figure CN116899229B_ABST
Patent Text Reader

Abstract

The application provides a path determination method, device and equipment of a two-dimensional virtual scene and a storage medium, wherein the method comprises: traversing the passable grid, determining a first sub-target corner point grid of the two-dimensional virtual scene, constructing a first sub-target corner point connection line graph constituted by first direct connection lines between the first sub-target corner point grid according to the first sub-target corner point grid, determining a movement path of a virtual character based on a starting point grid of the virtual character, a terminal point grid of the virtual character and the first sub-target corner point connection line graph, and the above method is beneficial to improving the determination efficiency of the movement path.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, device, and storage medium for determining paths in a two-dimensional virtual scene. Background Technology

[0002] In the virtual scene of a 2D game, users can select the destination grid position and then plan the movement path for the virtual character they control. Since the 2D virtual scene is made of grids, and for grid maps, when planning the movement path, the traditional search algorithm starts from the starting grid and diverges outwards to find the destination grid without providing a search direction, resulting in a large amount of computation. To reduce the amount of computation, the A* algorithm was proposed. The A* algorithm provides a search direction, allowing the search to proceed towards the destination grid. However, during the search process, each grid in the search direction needs to be traversed in 8 directions, that is, it needs to traverse the 8 grids adjacent to that grid to determine the movement path. Because the above method involves a lot of judgment logic, the efficiency of determining the movement path is relatively low. Summary of the Invention

[0003] In view of this, embodiments of this application provide a path determination method, apparatus, device, and storage medium for a two-dimensional virtual scene, so as to improve the efficiency of determining movement paths in a two-dimensional virtual scene, thereby improving the pathfinding efficiency of virtual characters.

[0004] In a first aspect, embodiments of this application provide a path determination method for a two-dimensional virtual scene, the two-dimensional virtual scene including a passable grid and an impassable grid composed of virtual obstacles, the method comprising: The passable grid is traversed to determine the first sub-target corner grid of the two-dimensional virtual scene. The adjacent diagonal grids of the first sub-target corner grid are located in the impassable grids, and the grids adjacent to the adjacent diagonal grids in the horizontal and vertical directions of the first sub-target corner grid are passable grids. Based on the first sub-target corner grid, a first sub-target corner connection map is constructed, which is formed by the first direct connection between the first sub-target corner grids. The first candidate path between the two first sub-target corner grids corresponding to the first direct connection does not pass through the impassable grids and other first sub-target corner grids. The first candidate path is the path with the shortest distance between the two first sub-target corner grids corresponding to the first direct connection. The movement path of the virtual character is determined based on the starting grid of the virtual character, the ending grid of the virtual character, and the line drawing connecting the corner points of the first sub-target.

[0005] Optionally, the step of constructing a first sub-target corner point connection map composed of a first straight line connecting the first sub-target corner point grids includes: For any two first sub-target corner grids, determine all first candidate paths between the two first sub-target corner grids; In response to all first candidate paths not passing through the impassable grid and other first sub-target corner grids, the two first sub-target corner grids are connected using the first direct connection to obtain a first sub-target corner connection map composed of the first direct connection.

[0006] Optionally, determining the movement path of the virtual character based on the starting grid of the virtual character, the ending grid of the virtual character, and the line drawing connecting the first sub-target corner points includes: In response to the operation command to determine the endpoint grid, the target grid corresponding to the operation command is determined so as to use the target grid as the endpoint grid, and the starting grid is determined based on the grid where the virtual character is currently located; Identify the impassable grids located on the target path, wherein the target path includes a second candidate path from the starting grid to the ending grid, the second candidate path being the path with the shortest distance between the starting grid and the ending grid; The movement path of the virtual character is determined based on the starting grid, the ending grid, and the second sub-target corner connection diagram. The second sub-target corner connection diagram includes the first sub-target corner connection diagram formed by the first sub-target corner grid of the first sub-target corner connection diagram, which is composed of the first sub-target corner grid of the target impassable grid.

[0007] Optionally, determining the movement path of the virtual character based on the starting grid, the ending grid, and the line drawing connecting the corner points of the second sub-target includes: Based on the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram, a second direct connection is constructed between the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram. The third candidate path between the first sub-target corner grid corresponding to the second direct connection and the starting grid does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner connection diagram. The third candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the second direct connection and the starting grid. Based on the endpoint grid and the first sub-target corner grid in the second sub-target corner graph, a third direct connection is constructed between the endpoint grid and the first sub-target corner grid in the second sub-target corner graph. The fourth candidate path between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner graph. The fourth candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid. The movement path of the virtual character is determined based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection diagram.

[0008] Optionally, determining the movement path of the virtual character based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection map includes: The A* algorithm is used to find the shortest route from the starting grid to the ending grid by using the route map composed of the second direct connection, the third direct connection, and the second sub-target corner point connection map. When the virtual character moves along a grid path, the grid path with the fewest grids between the starting grid and the ending grid is determined according to the shortest route trend, and the grid path is used as the movement path. When the virtual character moves along a smooth path, the shortest route is smoothed, and the first sub-target corner points that can be connected by a straight line in the shortest route are connected to form a straight path, which is then used as the movement path.

[0009] Optionally, after obtaining the corner point connection diagram of the first sub-target, the method further includes: After detecting a change in the impassable grid in the two-dimensional virtual scene, determine the first sub-target corner grid affected by the change in the impassable grid; Based on the changes in the impassable grid, update the first direct connection corresponding to the first sub-target corner grid affected by the changes.

[0010] Optionally, when a newly added impassable grid is detected in the two-dimensional virtual scene, the determination of the first sub-target corner grid affected by the change in the impassable grid includes: The traversable grids surrounding the newly added impassable grids in each direction are traversed to determine the second sub-target corner grids that do not meet the requirements of the first sub-target corner grids, so that the second sub-target corner grids are used as the affected first sub-target corner grids.

[0011] Optionally, updating the first direct connection corresponding to the corner grid of the affected first sub-target based on the changes in the impassable grid includes: Delete the first direct line corresponding to the corner point grid of the second sub-target to obtain the corner point connection diagram of the second sub-target; Based on the second sub-target corner point connection diagram and the third sub-target corner point grid corresponding to the newly added impassable grid, construct the third sub-target corner point connection diagram.

[0012] Optionally, the step of constructing a third sub-target corner connection map based on the second sub-target corner connection map and the third sub-target corner grid corresponding to the newly added impassable grid includes: Based on the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram, a fourth direct connection is constructed between the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram to update the second sub-target corner connection diagram and obtain the third sub-target corner connection diagram. The fifth candidate path between the two sub-target corner grids corresponding to the fourth direct connection does not pass through the impassable grid, the newly added impassable grid, or other sub-target corner grids. The fifth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fourth direct connection.

[0013] Optionally, when it is detected that an impassable mesh has been deleted in the two-dimensional virtual scene, the determination of the first sub-target corner mesh affected by the change in the impassable mesh includes: Determine the fourth sub-target corner grid in the first sub-target corner grid that is related to the first straight line connecting the deleted impassable grid, so that the fourth sub-target corner grid is regarded as the first sub-target corner grid affected by the change of the impassable grid.

[0014] Optionally, updating the first direct connection corresponding to the corner grid of the affected first sub-target based on the changes in the impassable grid includes: Delete the first direct line corresponding to the corner point grid of the fourth sub-target to obtain the corner point connection diagram of the fourth sub-target; Based on the first sub-target corner point grid included in the fourth sub-target corner point connection diagram, construct the fifth sub-target corner point connection diagram.

[0015] Optionally, constructing the fifth sub-target corner point connection map based on the first sub-target corner point grid included in the fourth sub-target corner point connection map includes: Based on the fourth sub-target corner grids included in the fourth sub-target corner grid connection map, a fifth direct connection is constructed between the fourth sub-target corner grids included in the fourth sub-target corner grid connection map to update the fourth sub-target corner grid connection map and obtain a fifth sub-target corner grid connection map. The sixth candidate path between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map does not pass through the impassable grids and other sub-target corner grids. The sixth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map.

[0016] Secondly, embodiments of this application provide a path determination device for a two-dimensional virtual scene, wherein the two-dimensional virtual scene includes a passable grid and an impassable grid composed of virtual obstacles, and the device includes: The determining unit is used to traverse the passable grid and determine the first sub-target corner point in the two-dimensional virtual scene. The diagonal grid corresponding to the corner point grid where the first sub-target corner point is located includes the grid located in the impassable grid, and the grids adjacent to the corner point grid that are closer to the virtual obstacle in the horizontal and vertical directions are located in the passable grid. The construction unit is used to construct a first sub-target corner point connection map based on the first sub-target corner point, which is formed by the first direct line connecting the first sub-target corner points. Among all the first candidate paths obtained according to the grid distribution of the two first sub-target corner points corresponding to the first direct line, none of them pass through the impassable grid or the grid where the other first sub-target corner points are located. The first candidate path is the path with the shortest distance between the two first sub-target corner point grids corresponding to the first direct line. The path unit is used to determine the movement path of the virtual character based on the starting grid of the virtual character, the ending grid set for the virtual character, and the line drawing connecting the corner points of the first sub-target.

[0017] Optionally, when the construction unit is configured to construct a first sub-target corner point connection diagram consisting of a first direct connection between the first sub-target corner point grids based on the first sub-target corner point grid, it includes: For any two first sub-target corner grids, determine all first candidate paths between the two first sub-target corner grids; In response to all first candidate paths not passing through the impassable grid and other first sub-target corner grids, the two first sub-target corner grids are connected using the first direct connection to obtain a first sub-target corner connection map composed of the first direct connection.

[0018] Optionally, when the path unit is used to determine the movement path of the virtual character based on the virtual character's starting grid, the virtual character's ending grid, and the first sub-target corner point connection map, it includes: In response to the operation command to determine the endpoint grid, the target grid corresponding to the operation command is determined so as to use the target grid as the endpoint grid, and the starting grid is determined based on the grid where the virtual character is currently located; Identify the impassable grids located on the target path, wherein the target path includes a second candidate path from the starting grid to the ending grid, the second candidate path being the path with the shortest distance between the starting grid and the ending grid; The movement path of the virtual character is determined based on the starting grid, the ending grid, and the second sub-target corner connection diagram. The second sub-target corner connection diagram includes the first sub-target corner connection diagram formed by the first sub-target corner grid of the first sub-target corner connection diagram, which is composed of the first sub-target corner grid of the target impassable grid.

[0019] Optionally, when the path unit determines the movement path of the virtual character based on the starting grid, the ending grid, and the second sub-target corner point connection diagram, it includes: Based on the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram, a second direct connection is constructed between the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram. The third candidate path between the first sub-target corner grid corresponding to the second direct connection and the starting grid does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner connection diagram. The third candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the second direct connection and the starting grid. Based on the endpoint grid and the first sub-target corner grid in the second sub-target corner graph, a third direct connection is constructed between the endpoint grid and the first sub-target corner grid in the second sub-target corner graph. The fourth candidate path between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner graph. The fourth candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid. The movement path of the virtual character is determined based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection diagram.

[0020] Optionally, when the path unit determines the movement path of the virtual character based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection map, it includes: The A* algorithm is used to find the shortest route from the starting grid to the ending grid by using the route map composed of the second direct connection, the third direct connection, and the second sub-target corner point connection map. When the virtual character moves along a grid path, the grid path with the fewest grids between the starting grid and the ending grid is determined according to the shortest route trend, and the grid path is used as the movement path. When the virtual character moves along a smooth path, the shortest route is smoothed, and the first sub-target corner points that can be connected by a straight line in the shortest route are connected to form a straight path, which is then used as the movement path.

[0021] Optionally, the building unit is further configured to: After obtaining the first sub-target corner point connection diagram, after detecting a change in the impassable grid in the two-dimensional virtual scene, the first sub-target corner point grid affected by the change in the impassable grid is determined. Based on the changes in the impassable grid, update the first direct connection corresponding to the first sub-target corner grid affected by the changes.

[0022] Optionally, when the building unit is used to determine the first sub-target corner grid affected by the change in the impassable grid, it includes: When a new impassable grid is detected in the two-dimensional virtual scene, the passable grids surrounding the new impassable grid in each direction are traversed to determine the second sub-target corner grid that does not meet the requirements of the first sub-target corner grid, so that the second sub-target corner grid is used as the affected first sub-target corner grid.

[0023] Optionally, when the building unit updates the first direct connection corresponding to the first sub-target corner grid affected by changes in the impassable grid, it includes: Delete the first direct line corresponding to the corner point grid of the second sub-target to obtain the corner point connection diagram of the second sub-target; Based on the second sub-target corner point connection diagram and the third sub-target corner point grid corresponding to the newly added impassable grid, construct the third sub-target corner point connection diagram.

[0024] Optionally, when the construction unit constructs the third sub-target corner connection map based on the second sub-target corner connection map and the third sub-target corner grid corresponding to the newly added impassable grid, it includes: Based on the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram, a fourth direct connection is constructed between the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram to update the second sub-target corner connection diagram and obtain the third sub-target corner connection diagram. The fifth candidate path between the two sub-target corner grids corresponding to the fourth direct connection does not pass through the impassable grid, the newly added impassable grid, or other sub-target corner grids. The fifth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fourth direct connection.

[0025] Optionally, when the building unit is used to determine the first sub-target corner grid affected by the change in the impassable grid, it includes: When it is detected that an impassable grid has been deleted in the two-dimensional virtual scene, a fourth sub-target corner grid is determined that is related to the first straight line connecting the deleted impassable grid in the first sub-target corner grid, so that the fourth sub-target corner grid is regarded as the first sub-target corner grid affected by the change of the impassable grid.

[0026] Optionally, when the building unit updates the first direct connection corresponding to the first sub-target corner grid affected by changes in the impassable grid, it includes: Delete the first direct line corresponding to the corner point grid of the fourth sub-target to obtain the corner point connection diagram of the fourth sub-target; Based on the first sub-target corner point grid included in the fourth sub-target corner point connection diagram, construct the fifth sub-target corner point connection diagram.

[0027] Optionally, when the construction unit constructs the fifth sub-target corner connection map based on the first sub-target corner grid included in the fourth sub-target corner connection map, it includes: Based on the fourth sub-target corner grids included in the fourth sub-target corner grid connection map, a fifth direct connection is constructed between the fourth sub-target corner grids included in the fourth sub-target corner grid connection map to update the fourth sub-target corner grid connection map and obtain a fifth sub-target corner grid connection map. The sixth candidate path between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map does not pass through the impassable grids and other sub-target corner grids. The sixth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map.

[0028] 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 a path determination method for a two-dimensional virtual scene as described in any of the first aspects.

[0029] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs a path determination method for a two-dimensional virtual scene as described in any of the first aspects.

[0030] The technical solutions provided by the embodiments of this application may include the following beneficial effects: In this application, before determining the movement path, the two-dimensional virtual scene is preprocessed to determine the first sub-target corner point grid corresponding to each virtual obstacle. Then, a first sub-target corner point connection diagram is constructed based on the first sub-target corner point grid. Finally, based on the virtual character's starting grid, the virtual character's ending grid, and the first sub-target corner point connection diagram, the movement path of the virtual character is determined. Since the first sub-target corner point connection diagram allows the virtual character to avoid virtual obstacles, the movement path determined by the first sub-target corner point connection diagram is passable. The line graph is determined based on the first sub-target corner point grid. Therefore, in the process of determining the first sub-target corner point line graph, there is no need to search irrelevant grids, which effectively reduces the search space. Furthermore, the process of determining the first sub-target corner point line graph is based on the first direct connection. Since the search direction of the grid can be reduced when determining the first direct connection, that is, other paths besides the first candidate path, as well as directions passing through impassable grids and other first sub-target corner point grids, do not need to be searched. This helps to reduce the grid search direction and thus improves the efficiency of determining the movement path.

[0031] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0032] 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.

[0033] Figure 1 This is a schematic diagram of a two-dimensional virtual scene proposed in an embodiment of this application; Figure 2 A flowchart illustrating a path determination method for a two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 3 This is a schematic diagram of a two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 4 This is a schematic diagram of a two-dimensional virtual scene after rasterization, provided in Embodiment 1 of this application; Figure 5 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 6 A schematic diagram of a first sub-target corner point connection diagram provided in Embodiment 1 of this application; Figure 7 A flowchart illustrating another path determination method for a two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 8 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 9 A flowchart illustrating another path determination method for a two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 10 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 11 A flowchart illustrating another virtual scene path determination method provided in Embodiment 1 of this application; Figure 12 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 13 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 14 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 15 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 16 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 17 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application; Figure 18 This is a schematic diagram of the structure of a path determination device for a two-dimensional virtual scene provided in Embodiment 2 of this application; Figure 19 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of this application. Detailed Implementation

[0034] 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. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally 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 represents selected embodiments of this 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.

[0035] For ease of understanding, the following explanations are provided in advance: Figure 1 This is a schematic diagram of a two-dimensional virtual scene proposed in an embodiment of this application, as shown below. Figure 1 As shown, the two-dimensional virtual scene is composed of a grid. Figure 1 There are 8 adjacent grids to the grid marked B, such as... Figure 1 The virtual character moves according to the grid distribution of the two-dimensional virtual scene. If the virtual character is currently in the grid marked B, it can move from grid B to any of the eight grids mentioned above. Each move can only be to an adjacent grid. When it needs to move to the target grid, if the target grid and grid B are in the same row and there is a five grids in between, then it needs to move five grids in a row to reach the target grid. In this movement mode, the virtual character cannot move freely and needs to move according to the grid arrangement.

[0036] Figure 1 As shown, in the existing technology, when using the A* algorithm to determine the next grid cell where identifier B is located, it is necessary to traverse... Figure 1 The algorithm needs to traverse 8 directions to find all the grids with filled patterns. Therefore, even though the A* algorithm provides the search direction, there are still relatively many judgment logics in the process of searching a certain grid, which reduces the efficiency of determining the movement path.

[0037] To address the aforementioned issues, this application proposes a path determination method, apparatus, device, and storage medium for a two-dimensional virtual scene. By determining a first sub-target corner point grid, the search space is reduced. Then, the first direct connection between the first sub-target corner point grids is used to reduce the search direction of the grid. The first sub-target corner point connection map constructed by the first direct connection can enable the virtual character to avoid obstacles, thereby improving the path determination efficiency when the movement path is obtained based on the first sub-target corner point connection map.

[0038] Example 1 Figure 2 This is a flowchart illustrating a path determination method for a two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 2 As shown, the two-dimensional virtual scene includes passable grids and impassable grids composed of virtual obstacles. Virtual obstacles are set within the impassable grids; that is, grids occupied by virtual obstacles can be considered impassable grids. The method includes the following steps: Step 201: Traverse the passable grid to determine the first sub-target corner grid of the two-dimensional virtual scene, wherein the adjacent diagonal grids of the first sub-target corner grid are located in the impassable grids, and the grids adjacent to the adjacent diagonal grids in the horizontal and vertical directions of the first sub-target corner grid are passable grids.

[0039] Step 202: Based on the first sub-target corner grid, construct a first sub-target corner connection map consisting of the first direct connection between the first sub-target corner grids. Each first candidate path between the two first sub-target corner grids corresponding to the first direct connection does not pass through the impassable grids and other first sub-target corner grids. The first candidate path is the path with the shortest distance between the two first sub-target corner grids corresponding to the first direct connection.

[0040] Step 203: Determine the movement path of the virtual character based on the starting grid of the virtual character, the ending grid of the virtual character, and the line drawing connecting the corner points of the first sub-target.

[0041] Specifically, Figure 3 This is a schematic diagram of a two-dimensional virtual scene provided in Embodiment 1 of this application. Figure 4 This is a schematic diagram of a two-dimensional virtual scene after rasterization, as provided in Embodiment 1 of this application. Figure 3As shown, the two-dimensional virtual scene includes virtual obstacle A and virtual obstacle B. Taking virtual obstacle A as an example, virtual obstacle A can be virtual objects such as buildings, mountains, and rivers in the game. Virtual obstacle A occupies several grids in the two-dimensional virtual scene. Some grids may be completely occupied, while others may only be partially occupied. Regardless of the proportion of a grid occupied by virtual obstacle A, if the grid overlaps with virtual obstacle A, the virtual character cannot pass through that grid. Multiple grids occupied by virtual obstacle A constitute impassable grids. Figure 3 It includes virtual obstacle A and virtual obstacle B, therefore Figure 3 It includes two impassable grids. Figure 3 The other areas are accessible grids. Figure 3 After rasterizing a 2D virtual scene, the result is as follows: Figure 4 The content shown is as follows: Figure 4 As shown, the grids covered by virtual obstacles A and B are impassable grids, while the area formed by other grids is a passable grid.

[0042] Figure 5 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 5 As shown, for Figure 4 By traversing the passable grid in the data, we can determine the following: Figure 5 The first sub-target corner grid shown in S0-S7 requires determining whether a grid can be considered a first sub-target corner grid. First, it's necessary to determine if the adjacent diagonal grids (i.e., the grids adjacent to the grid on its lower right, upper right, lower left, and upper left can all be considered adjacent diagonal grids) are impassable. Furthermore, it's crucial to determine if the two grids adjacent to the grid horizontally and vertically can enclose the adjacent diagonal grid, and if these two grids are located within a passable grid. If the diagonal grid is impassable, and the aforementioned two grids can enclose the adjacent diagonal grid, and both are within a passable grid, then the grid containing this grid can be considered a first sub-target corner grid. This first sub-target corner grid is diagonally distributed with one corner of the grid area containing the virtual obstacle. Figure 5The grids containing S0-S7 are diagonally distributed with the grid area containing the virtual obstacle. Taking S0 as an example, the grid containing S0 is the first sub-target corner grid. The diagonal grid of this first sub-target corner grid is occupied by the virtual obstacle A. Therefore, this diagonal grid is located in a non-passable grid. Furthermore, among the grids adjacent to the grid containing S0, the grid S8, which is closer to the virtual obstacle A in the horizontal direction, is located in a passable grid. Among the grids adjacent to the grid containing S0, the grid S9, which is closer to the virtual obstacle A in the vertical direction, is also located in a passable grid. The two grids S8 and S9 sandwich the adjacent diagonal grid of S0. Therefore, the grid containing S0 can be regarded as the first sub-target corner grid.

[0043] Since the first sub-target corner grid can define the range of virtual obstacles (i.e., impassable grids), after determining all the first sub-target corner grids in the 2D virtual scene, a first sub-target corner connection map can be constructed using these grids. When constructing the first sub-target corner connection map, the following constraints must be met: two first sub-target corner grids can be directly connected by a straight line, that is, they can be connected by the first direct line. Furthermore, all first candidate paths obtained from the two first sub-target corner grids connected by this first direct line, according to the grid distribution of the 2D virtual scene, do not pass through impassable grids or other first sub-target corner grids. The first candidate path is the path with the shortest distance between the two first sub-target corner grids corresponding to the first direct line. The shortest distance means the shortest distance when moving according to the grid distribution of the 2D virtual scene. Figure 5 Taking S0 as an example, the first sub-target corner grids that can establish a direct connection with S0 include S1 and S3. Direct connections between S0 and S2, S5, S6, and S7 will pass through impassable grids. Although S0 and S4 can be connected by a direct connection, the first candidate path includes a path passing through S1. Therefore, a direct connection cannot be established between S0 and S2, S4, S5, S6, and S7. Thus, the constructed first sub-target corner connection diagram can be as follows: Figure 6 As shown, Figure 6 This is a schematic diagram of a first sub-target corner point connection diagram provided in Embodiment 1 of this application. The first sub-target corner point connection diagram constructed in S0-S7 is as follows: Figure 6 The figure shown is formed by the dashed lines. Figure 6 Any dotted line in the diagram represents a first straight line, such as... Figure 6As shown, the constructed first sub-target corner point connection map is built around virtual obstacles. When the virtual character is navigating, if the path is followed according to the path given in the first sub-target corner point connection map, it will help reduce the path length, allowing the virtual character to reach the destination quickly without touching virtual obstacles. Furthermore, any first direct path can provide a search direction, thus reducing the number of logical judgments in the pathfinding process and improving pathfinding efficiency.

[0044] It should be noted that the process of constructing the first sub-target corner point connection map can be completed on the game server when it is not providing services to users, such as during a game update, or it can be constructed during the game after the user sets the endpoint grid of the virtual character. After obtaining the first sub-target corner point connection map, the movement path of the virtual character is determined based on the starting grid of the virtual character in the virtual scene, the endpoint grid set for the virtual character, and the obtained first sub-target corner point connection map.

[0045] In one feasible implementation, when performing step 202, all first candidate paths between any two first sub-target corner grids can be determined first. Then, in response to all first candidate paths not passing through the impassable grids and other first sub-target corner grids, the two first sub-target corner grids are connected using the first direct connection to obtain the first sub-target corner connection diagram composed of the first direct connection.

[0046] In a feasible implementation plan Figure 7 A flowchart illustrating another path determination method for a two-dimensional virtual scene provided in Embodiment 1 of this application is shown below. Figure 7 As shown, step 203 can be achieved through the following steps: Step 701: Respond to the operation command to determine the endpoint grid, determine the target grid corresponding to the operation command, so as to use the target grid as the endpoint grid, and determine the starting grid based on the grid where the virtual character is currently located.

[0047] Step 702: Determine the target impassable grid located on the target path, wherein the target path includes each second candidate path from the starting grid to the ending grid, and the second candidate path is the path with the shortest distance between the starting grid and the ending grid.

[0048] Step 703: Determine the movement path of the virtual character based on the starting grid, the ending grid, and the second sub-target corner point connection diagram, wherein the second sub-target corner point connection diagram includes the first sub-target corner point connection diagram formed by the first sub-target corner point grid of the first sub-target corner point connection diagram.

[0049] Specifically, to further improve the efficiency of users in determining paths during gameplay, the first sub-target corner point connection map can be constructed before the user sets the destination grid. For example, the first sub-target corner point connection map can be constructed during game updates. Then, after the user sets the destination grid, the constructed first sub-target corner point connection map can be used directly to determine the movement path.

[0050] When determining the movement path, the user needs to first determine the location where the virtual character will go (i.e., the user-defined endpoint grid). After the user sets the above location on the two-dimensional virtual scene, this location is used as the user-defined endpoint grid. The current position of the virtual character on the two-dimensional virtual scene is obtained and used as the starting grid. Then, the target virtual obstacles (i.e., target impassable grids) that can affect the movement path from the starting grid to the endpoint grid are determined. Since the movement path is generally along the shortest path, when determining the target virtual obstacles, all the second candidate paths from the starting grid to the endpoint grid obtained according to the grid distribution of the two-dimensional virtual scene can be determined first (i.e., the shortest path from the starting grid to the endpoint grid obtained according to the grid distribution of the two-dimensional virtual scene). Then, the virtual obstacles that overlap with all the second candidate paths are determined and used as the target virtual obstacles. Figure 8 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 8 As shown, the virtual character is currently located in grid C, and the user sets grid D as the destination grid. Then, virtual obstacles A and B will overlap with the shortest path from grid C to grid D. Therefore, virtual obstacles A and B can be used as target virtual obstacles.

[0051] After identifying the target virtual obstacles, a second sub-target corner point connection map (which is a part of the first sub-target corner point connection map) can be determined based on the aforementioned starting grid, ending grid, and the second sub-target corner point connection map. For example... Figure 8 As stated, if Figure 8The diagram also includes virtual obstacle E (not shown in the figure), and virtual obstacle E does not overlap with the shortest path from grid C to grid D. In this case, the first sub-target corner connection diagram formed by the first sub-target corner grids of virtual obstacle A and virtual obstacle B can be used as the second sub-target corner connection diagram (the second sub-target corner connection diagram can be referenced). Figure 6 The first sub-target corner point connection diagram is shown. Then, the movement path of the virtual character is determined based on the obtained second sub-target corner point connection diagram. Since the second sub-target corner point connection diagram is formed around the target virtual obstacle, the movement path obtained based on the second sub-target corner point connection diagram will not affect the movement of the virtual character. In addition, the shortest path from the starting grid to the ending grid can also be obtained.

[0052] In a feasible implementation plan Figure 9 A flowchart illustrating another path determination method for a two-dimensional virtual scene provided in Embodiment 1 of this application is shown below. Figure 9 As shown, step 703 can be achieved through the following steps: Step 901: Based on the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram, construct a second direct connection between the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram. In each of the third candidate paths between the first sub-target corner grid corresponding to the second direct connection and the starting grid, no path passes through the impassable grid or other first sub-target corner grids in the second sub-target corner connection diagram. The third candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the second direct connection and the starting grid.

[0053] Step 902: Based on the endpoint grid and the first sub-target corner grid in the second sub-target corner connection diagram, construct a third direct connection between the endpoint grid and the first sub-target corner grid in the second sub-target corner connection diagram. In each of the fourth candidate paths between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid, the fourth candidate path does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner connection diagram. The fourth candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid.

[0054] Step 903: Determine the movement path of the virtual character based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection diagram.

[0055] Specifically, after obtaining the starting grid, ending grid, and the connection map of the second sub-target corner point, for the starting grid, a second direct connection map is determined between the starting grid and the first sub-target corner point in the connection map of the second sub-target corner point. The constructed second direct connection map needs to meet the following conditions: the two grids corresponding to the second direct connection map can be directly connected by a straight line, that is: they can be directly connected by the second direct connection, and all third candidate paths (i.e., the shortest paths) obtained according to the grid distribution of the two grids connected by the second direct connection do not pass through the impassable grid and other first sub-target corner point grids in the connection map of the second sub-target corner point. Figure 10 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 10 As shown, grid C is the starting grid and grid D is the ending grid. The line diagram connecting the corner points of the second sub-targets corresponding to virtual obstacle A and virtual obstacle B is shown below. Figure 10 The diagram showing the connection between the first sub-target corner points S0-S7 is shown below. Figure 10 As shown, grid C can be directly connected to S0 and S1 via a second direct connection (e.g. Figure 10 The dashed line between S0 and grid C is shown, and Figure 10 (As shown by the dashed line between S1 and grid C), and the second direct line between grid C and S0 does not pass through virtual obstacles A and B, nor does it pass through the grids containing S1-S7.

[0056] The third direct connection is Figure 10 The dashed lines between grids D and S5, and between grids D and S6, are shown. For the third direct connection, please refer to... Figure 10 The details regarding the second direct connection will not be elaborated here.

[0057] After obtaining the second direct line, the third direct line, and the line connecting the second sub-target corner point, it can be done as follows: Figure 10 The graph shown provides the shortest path from the starting grid to the ending grid, and this shortest path is not blocked by virtual obstacles.

[0058] In a feasible implementation plan Figure 11 A flowchart illustrating another path determination method for a virtual scene provided in Embodiment 1 of this application is shown below. Figure 11 As shown, step 903 can be achieved through the following steps: Step 1101: Use the A* algorithm to find the route map composed of the second direct connection, the third direct connection, and the second sub-target corner point connection map, and determine the shortest route from the starting grid to the ending grid.

[0059] Step 1102: When the virtual character moves along a grid path, determine the grid path with the fewest grids between the starting grid and the ending grid according to the shortest route trend, and use the grid path as the movement path.

[0060] Step 1103: When the virtual character moves along a smooth path, the shortest route is smoothed, and the first sub-target corner points that can be connected by a straight line in the shortest route are connected to obtain a straight path, which is then used as the movement path.

[0061] Specifically, the A* algorithm can find the shortest path from the starting grid to the ending grid. This shortest path is constructed by connecting direct lines. However, during the game's pathfinding process, the movement path needs to be planned according to the virtual character's movement method. This ensures that the final path not only conforms to the shortest path but also satisfies the virtual character's movement pattern. For example, when the virtual character can move freely in any direction, the obtained shortest path can be smoothed by connecting the first sub-target corner grids that can be connected by direct lines, resulting in a straight path. This minimizes the distance of the final movement path. When the virtual character moves along this path, it moves along... When the virtual character moves along a straight path, that is, along a smooth path, or when the virtual character moves according to the grid distribution of the two-dimensional virtual scene, that is, the virtual character can only move to adjacent grids, and can only move one grid at a time, then the grid path that requires the fewest grids to be moved from the starting grid to the ending grid needs to be determined based on the shortest path obtained above. This grid path is then used as the movement path for the virtual character. When the virtual character moves along this movement path, it moves according to the grid distribution on the movement path, that is, the virtual character moves according to the grid path distribution.

[0062] For example: Figure 12 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 12 As shown, the determined shortest path is as follows: Figure 12 As shown by the dotted lines, when the virtual character moves along a grid path, the determined movement path is as follows: Figure 13 The diagram shows the filled grid, and the paths formed by grids C, D, S0, S1, S4, and S5. Figure 13 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application. When the virtual character moves along a smooth path, the determined movement path is as follows: Figure 14The solid line in the middle, along with the paths formed by grids C, D, S0, S4, and S5, are shown. Figure 14 A schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, namely: Figure 14 Yes Figure 12 The path is obtained by smoothing the dashed lines in the image.

[0063] It should be noted that the two-dimensional virtual scene in this application is constructed in the form of a grid, but the walking method of the virtual character can be set according to its own needs. That is, the virtual character can walk according to part of the grid, i.e., walk along a grid path, or walk freely in any direction, i.e., walk along a smooth path. No specific limitation is made here.

[0064] In a feasible implementation, after obtaining the first sub-target corner point connection map, it is possible to first detect changes in the impassable grids in the two-dimensional virtual scene, determine the first sub-target corner point grids affected by the changes in the impassable grids, and then update the first direct connection line corresponding to the affected first sub-target corner point grids based on the changes in the impassable grids.

[0065] Specifically, after the first sub-target corner point connection map is constructed, if the impassable meshes in the 2D virtual scene change, such as adding or deleting virtual obstacles, the impassable meshes will be added or deleted. This will cause the first sub-target corner point connection map in the 2D virtual scene to change accordingly. For example, some first sub-target corner point meshes may no longer meet the definition requirements, or some first direct connections may no longer meet the requirements. In this case, the first direct connections need to be updated based on the original first sub-target corner point connection map so that the updated connection map conforms to the changed 2D virtual scene.

[0066] In a feasible implementation, when a new impassable grid is detected in the two-dimensional virtual scene, when performing the step of determining the first sub-target corner grid affected by the change of the impassable grid, the passable grids surrounding the new impassable grid in each direction are traversed to determine the second sub-target corner grid that does not meet the requirements of the first sub-target corner grid, so as to take the second sub-target corner grid as the affected first sub-target corner grid.

[0067] Specifically, the two-dimensional virtual scene can be updated. During the update, new virtual obstacles (i.e., new impassable grids) can be added to the two-dimensional virtual scene. The new virtual obstacles will affect the previously obtained first sub-target corner point connection map. At this time, it is necessary to traverse the passable grids surrounding the new impassable grids to determine the second sub-target corner point grids that do not meet the requirements of the first sub-target corner point grids, so as to use the second sub-target corner point grids as the affected first sub-target corner point grids.

[0068] In one feasible implementation, when performing the step of updating the first direct connection corresponding to the first sub-target corner grid affected by the change of the impassable grid, the first direct connection corresponding to the second sub-target corner grid is first deleted to obtain the second sub-target corner connection map. Then, based on the second sub-target corner connection map and the third sub-target corner grid corresponding to the newly added impassable grid, the third sub-target corner connection map is constructed.

[0069] In a feasible implementation, when constructing the third sub-target corner point connection map based on the second sub-target corner point connection map and the third sub-target corner point grid corresponding to the newly added impassable grid, a fourth direct connection is constructed between the third sub-target corner point grid and the first sub-target corner point grid in the second sub-target corner point connection map, so as to update the second sub-target corner point connection map to obtain the third sub-target corner point connection map. The fifth candidate paths between the two sub-target corner point grids corresponding to the fourth direct connection do not pass through the impassable grid, the newly added impassable grid, or other sub-target corner point grids. The fifth candidate path is the path with the shortest distance between the two sub-target corner point grids corresponding to the fourth direct connection.

[0070] The following example illustrates the process of adding impassable grids: Figure 15 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 15 As shown, after detecting the addition of a new virtual obstacle F in the 2D virtual scene (the grid occupied by virtual obstacle F is the newly added impassable grid), the grid surrounding the new virtual obstacle F is traversed to determine whether there is a second sub-target corner grid in the first sub-target corner grid of virtual obstacle A and virtual obstacle B that does not meet the requirements of the first sub-target corner grid (the requirements of the first sub-target corner grid can be referred to...). Figure 5If the relevant content exists, it means that the newly added virtual obstacle F has disrupted the previously obtained first sub-target corner point connection diagram. In this case, the first direct connection related to the second sub-target corner point grid in the previously obtained first sub-target corner point connection diagram needs to be deleted to obtain the second sub-target corner point connection diagram. Then, based on the second sub-target corner point connection diagram, a fourth direct connection is constructed between the second sub-target corner point grids S8-S10 included in the newly added virtual obstacle F and the first sub-target corner point grid in the second sub-target corner point connection diagram, thus obtaining the third sub-target corner point connection diagram. The principle for constructing the fourth direct connection can refer to the rules for constructing the first direct connection. The constructed third sub-target corner point connection diagram is as follows: Figure 15 As shown by the dashed line in the image.

[0071] After obtaining the corner point connection map of the third sub-target, the movement path can be determined based on the corner point connection map of the third sub-target during pathfinding.

[0072] Figure 16 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 16 As shown, when the newly added virtual obstacle F does not affect the first sub-target corner grid in the first sub-target corner connection diagram, but only affects the first direct connection, then the affected first direct connection is deleted. Then, the first sub-target corner grid corresponding to the affected first direct connection, the newly added virtual obstacle F, and the direct connection between S8 and S11 are constructed to obtain a new sub-target corner connection diagram. The new sub-target corner connection diagram can be referenced. Figure 16 A diagram of lines formed by the dashed lines.

[0073] Figure 17 This is a schematic diagram of another two-dimensional virtual scene provided in Embodiment 1 of this application, as shown below. Figure 17 As shown, when the newly added virtual obstacle F neither affects the first sub-target corner grid in the first sub-target corner connection diagram nor the first direct connection, a new sub-target corner connection diagram can be constructed based on the complete first sub-target corner connection diagram, as shown below. Figure 17 As shown, based on the complete first sub-target corner point connection diagram, direct connections are constructed between the sub-target corner points S8-S11 in the newly added virtual obstacle F and the first sub-target corner point grid in the first sub-target corner point connection diagram. The final new sub-target corner point connection diagram is as follows. Figure 17 A diagram of lines formed by the dashed lines.

[0074] In one feasible implementation, when it is detected that an impassable grid has been deleted in the two-dimensional virtual scene, when performing the step of determining the first sub-target corner grid affected by the change of the impassable grid, a fourth sub-target corner grid related to the first straight line corresponding to the deleted impassable grid is determined in the first sub-target corner grid, so that the fourth sub-target corner grid is regarded as the first sub-target corner grid affected by the change of the impassable grid.

[0075] Specifically, in a two-dimensional virtual scene, not only can new virtual obstacles be added, but also existing virtual obstacles can be deleted (i.e., impassable grids can be deleted). After deleting a virtual obstacle, the first direct connection related to the deleted virtual obstacle needs to be deleted. Then, the sub-target corner grids related to the deleted first direct connection are determined, i.e., the fourth sub-target corner grids, so that direct connections can be constructed between the fourth sub-target corner grids, thereby updating the connection map.

[0076] In one feasible implementation, when updating the first direct connection corresponding to the first sub-target corner grid affected by the change in the impassable grid, the first direct connection corresponding to the fourth sub-target corner grid can be deleted first to obtain the fourth sub-target corner connection map. Then, the fifth sub-target corner connection map can be constructed based on the first sub-target corner grid included in the fourth sub-target corner connection map.

[0077] In a feasible implementation, when performing the step of constructing a fifth sub-target corner point connection map based on the first sub-target corner point grid included in the fourth sub-target corner point connection map, a fifth direct connection between the fourth sub-target corner point grids included in the fourth sub-target corner point connection map is constructed based on the fourth sub-target corner point grids included in the fourth sub-target corner point connection map to update the fourth sub-target corner point connection map to obtain the fifth sub-target corner point connection map. The sixth candidate paths between the two sub-target corner point grids corresponding to the fifth sub-target corner point connection map do not pass through the impassable grids or other sub-target corner point grids. The sixth candidate path is the path with the shortest distance between the two sub-target corner point grids corresponding to the fifth sub-target corner point connection map.

[0078] The principles for constructing new direct connections can be referenced from those for constructing the first direct connection, and will not be elaborated upon here. Figure 16 For example, after deleting the virtual obstacle F, the newly constructed sub-target corner connection diagram can be referenced. Figure 6 As shown.

[0079] It should be added that, Figure 1 , Figure 3 , Figures 4-6 , Figure 8 , Figure 10 , Figures 12-17 The grid size is the same in all cases.

[0080] Example 2 Figure 18 This is a schematic diagram of a path determination device for a two-dimensional virtual scene provided in Embodiment 2 of this application. The two-dimensional virtual scene includes a passable grid and an impassable grid composed of virtual obstacles. The device includes: The determining unit 1801 is used to traverse the passable grid and determine the first sub-target corner point in the two-dimensional virtual scene. The diagonal grid corresponding to the corner point grid where the first sub-target corner point is located includes the grid located in the impassable grid, and the grids adjacent to the corner point grid that are closer to the virtual obstacle in the horizontal and vertical directions are located in the passable grid. The construction unit 1802 is used to construct a first sub-target corner point connection map based on the first sub-target corner point, which is formed by the first direct line connecting the first sub-target corner points. Among all the first candidate paths obtained according to the grid distribution of the two first sub-target corner points corresponding to the first direct line, none of them pass through the impassable grid or the grid where the other first sub-target corner points are located. The first candidate path is the path with the shortest distance between the two first sub-target corner point grids corresponding to the first direct line. Path unit 1803 is used to determine the movement path of the virtual character based on the starting grid of the virtual character, the ending grid set for the virtual character, and the line drawing of the first sub-target corner point.

[0081] In one feasible implementation, when the construction unit 1802 is used to construct a first sub-target corner connection map consisting of a first direct connection between the first sub-target corner grids based on the first sub-target corner grid, it includes: For any two first sub-target corner grids, determine all first candidate paths between the two first sub-target corner grids; In response to all first candidate paths not passing through the impassable grid and other first sub-target corner grids, the two first sub-target corner grids are connected using the first direct connection to obtain a first sub-target corner connection map composed of the first direct connection.

[0082] In one feasible implementation, when the path unit 1803 determines the movement path of the virtual character based on the virtual character's starting grid, the virtual character's ending grid, and the first sub-target corner point connection map, it includes: In response to the operation command to determine the endpoint grid, the target grid corresponding to the operation command is determined so as to use the target grid as the endpoint grid, and the starting grid is determined based on the grid where the virtual character is currently located; Identify the impassable grids located on the target path, wherein the target path includes each second candidate path from the starting grid to the ending grid, and the second candidate path is the path with the shortest distance between the starting grid and the ending grid; The movement path of the virtual character is determined based on the starting grid, the ending grid, and the second sub-target corner connection diagram. The second sub-target corner connection diagram includes the first sub-target corner connection diagram formed by the first sub-target corner grid of the first sub-target corner connection diagram, which is composed of the first sub-target corner grid of the target impassable grid.

[0083] In one feasible implementation, when the path unit 1803 determines the movement path of the virtual character based on the starting point grid, the ending point grid, and the second sub-target corner point connection diagram, it includes: Based on the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram, a second direct connection is constructed between the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram. In each of the third candidate paths between the first sub-target corner grid corresponding to the second direct connection and the starting grid, the third candidate path does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner connection diagram. The third candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the second direct connection and the starting grid. Based on the endpoint grid and the first sub-target corner grid in the second sub-target corner connection diagram, a third direct connection is constructed between the endpoint grid and the first sub-target corner grid in the second sub-target corner connection diagram. In each of the fourth candidate paths between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid, the path does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner connection diagram. The fourth candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid. The movement path of the virtual character is determined based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection diagram.

[0084] In one feasible implementation, when the path unit 1803 determines the movement path of the virtual character based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection map, it includes: The A* algorithm is used to find the shortest route from the starting grid to the ending grid by using the route map composed of the second direct connection, the third direct connection, and the second sub-target corner point connection map. When the virtual character moves along a grid path, the grid path with the fewest grids between the starting grid and the ending grid is determined according to the shortest route trend, and the grid path is used as the movement path. When the virtual character moves along a smooth path, the shortest route is smoothed, and the first sub-target corner points that can be connected by a straight line in the shortest route are connected to form a straight path, which is then used as the movement path.

[0085] In one feasible implementation, the building unit 1802 is further configured to: After obtaining the first sub-target corner point connection diagram, after detecting a change in the impassable grid in the two-dimensional virtual scene, the first sub-target corner point grid affected by the change in the impassable grid is determined. Based on the changes in the impassable grid, update the first direct connection corresponding to the first sub-target corner grid affected by the changes.

[0086] In one feasible implementation, when the building unit 1802 is used to determine the first sub-target corner grid affected by the change of the impassable grid, it includes: When a new impassable grid is detected in the two-dimensional virtual scene, the passable grids surrounding the new impassable grid in each direction are traversed to determine the second sub-target corner grid that does not meet the requirements of the first sub-target corner grid, so that the second sub-target corner grid is used as the affected first sub-target corner grid.

[0087] In one feasible implementation, when the building unit 1802 updates the first direct connection corresponding to the affected first sub-target corner grid based on changes in the impassable grid, it includes: Delete the first direct line corresponding to the corner point grid of the second sub-target to obtain the corner point connection diagram of the second sub-target; Based on the second sub-target corner point connection diagram and the third sub-target corner point grid corresponding to the newly added impassable grid, construct the third sub-target corner point connection diagram.

[0088] In a feasible implementation, the construction unit 1802 is used to construct a third sub-target corner connection map based on the second sub-target corner connection map and the third sub-target corner grid corresponding to the newly added impassable grid, including: Based on the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram, a fourth direct connection is constructed between the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram to update the second sub-target corner connection diagram and obtain the third sub-target corner connection diagram. The fifth candidate paths between the two sub-target corner grids corresponding to the fourth direct connection do not pass through the impassable grid, the newly added impassable grid, or other sub-target corner grids. The fifth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fourth direct connection.

[0089] In one feasible implementation, when the building unit 1802 is used to determine the first sub-target corner grid affected by the change of the impassable grid, it includes: When it is detected that an impassable grid has been deleted in the two-dimensional virtual scene, a fourth sub-target corner grid is determined that is related to the first straight line connecting the deleted impassable grid in the first sub-target corner grid, so that the fourth sub-target corner grid is regarded as the first sub-target corner grid affected by the change of the impassable grid.

[0090] In one feasible implementation, when the building unit 1802 updates the first direct connection corresponding to the affected first sub-target corner grid based on changes in the impassable grid, it includes: Delete the first direct line corresponding to the corner point grid of the fourth sub-target to obtain the corner point connection diagram of the fourth sub-target; Based on the first sub-target corner point grid included in the fourth sub-target corner point connection diagram, construct the fifth sub-target corner point connection diagram.

[0091] In one feasible implementation, when the construction unit 1802 constructs a fifth sub-target corner connection map based on the first sub-target corner grid included in the fourth sub-target corner connection map, it includes: Based on the fourth sub-target corner grids included in the fourth sub-target corner grid connection map, a fifth direct connection is constructed between the fourth sub-target corner grids included in the fourth sub-target corner grid connection map to update the fourth sub-target corner grid connection map and obtain a fifth sub-target corner grid connection map. In this map, each sixth candidate path between two sub-target corner grids corresponding to the fifth sub-target corner grid connection map does not pass through the impassable grids and other sub-target corner grids. The sixth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map.

[0092] For an explanation of the principle of Embodiment 2, please refer to the relevant description of Embodiment 1, which will not be described in detail here.

[0093] Example 3 Figure 19 The present invention provides a schematic diagram of the structure of an electronic device according to Embodiment 3 of this application, including: a processor 1901, a storage medium 1902 and a bus 1903. The storage medium 1902 stores machine-readable instructions executable by the processor 1901. When the electronic device runs the state generation method in the game described above, the processor 1901 communicates with the storage medium 1902 through the bus 1903. The processor 1901 executes the machine-readable instructions to perform the method shown in Embodiment 1.

[0094] For details on the specific implementation methods, steps, and principles, please refer to the description in Example 1, which will not be repeated here.

[0095] Example 4 Embodiment 4 of this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the methods and steps shown in Embodiment 1.

[0096] For details on the specific implementation methods, steps, and principles, please refer to the description in Example 1, which will not be repeated here.

[0097] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0098] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0099] In addition, the functional units in the embodiments provided in this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0100] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0101] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0102] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application. All should be covered within the protection scope of this application. Therefore, the protection scope of this application should be determined by the protection scope of the claims.

Claims

1. A path determination method for a two-dimensional virtual scene, characterized in that, The two-dimensional virtual scene includes passable grids and impassable grids composed of virtual obstacles, and the method includes: The passable grid is traversed to determine the first sub-target corner grid of the two-dimensional virtual scene. The adjacent diagonal grids of the first sub-target corner grid are located in the impassable grids, and the grids adjacent to the adjacent diagonal grids in the horizontal and vertical directions of the first sub-target corner grid are passable grids. Based on the first sub-target corner grid, a first sub-target corner connection map is constructed, which is formed by the first direct connection between the first sub-target corner grids. The first candidate path between the two first sub-target corner grids corresponding to the first direct connection does not pass through the impassable grids and other first sub-target corner grids. The first candidate path is the path with the shortest distance between the two first sub-target corner grids corresponding to the first direct connection. Based on the starting grid of the virtual character, the ending grid of the virtual character, and the line drawing connecting the corner points of the first sub-target, the movement path of the virtual character is determined. The method further includes, after obtaining the corner point connection diagram of the first sub-target, the following: After detecting a change in the impassable grid in the two-dimensional virtual scene, determine the first sub-target corner grid affected by the change in the impassable grid; Based on the changes in the impassable grid, update the first direct connection corresponding to the first sub-target corner grid affected by the changes. When a new impassable grid is detected in the two-dimensional virtual scene, the determination of the first sub-target corner grid affected by the change in the impassable grid includes: The traversable grids surrounding the newly added impassable grids in each direction are traversed to determine the second sub-target corner grids that do not meet the requirements of the first sub-target corner grids, so that the second sub-target corner grids are used as the affected first sub-target corner grids.

2. The method as described in claim 1, characterized in that, The step of constructing a first sub-target corner point connection map based on the first sub-target corner point grid, consisting of the first direct connection between the first sub-target corner point grids, includes: For any two first sub-target corner grids, determine all first candidate paths between the two first sub-target corner grids; In response to all first candidate paths not passing through the impassable grid and other first sub-target corner grids, the two first sub-target corner grids are connected using the first direct connection to obtain a first sub-target corner connection map composed of the first direct connection.

3. The method as described in claim 1, characterized in that, The method of determining the movement path of the virtual character based on the starting grid of the virtual character, the ending grid of the virtual character, and the line drawing connecting the corner points of the first sub-target includes: In response to the operation command to determine the endpoint grid, the target grid corresponding to the operation command is determined so as to use the target grid as the endpoint grid, and the starting grid is determined based on the grid where the virtual character is currently located; Identify the impassable grids located on the target path, wherein the target path includes a second candidate path from the starting grid to the ending grid, the second candidate path being the path with the shortest distance between the starting grid and the ending grid; The movement path of the virtual character is determined based on the starting grid, the ending grid, and the second sub-target corner connection diagram. The second sub-target corner connection diagram includes the first sub-target corner connection diagram formed by the first sub-target corner grid of the first sub-target corner connection diagram, which is composed of the first sub-target corner grid of the target impassable grid.

4. The method as described in claim 3, characterized in that, Determining the movement path of the virtual character based on the starting grid, the ending grid, and the line drawing connecting the corner points of the second sub-target includes: Based on the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram, a second direct connection is constructed between the starting grid and the first sub-target corner grid in the second sub-target corner connection diagram. The third candidate path between the first sub-target corner grid corresponding to the second direct connection and the starting grid does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner connection diagram. The third candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the second direct connection and the starting grid. Based on the endpoint grid and the first sub-target corner grid in the second sub-target corner graph, a third direct connection is constructed between the endpoint grid and the first sub-target corner grid in the second sub-target corner graph. The fourth candidate path between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid does not pass through the impassable grid and other first sub-target corner grids in the second sub-target corner graph. The fourth candidate path is the path with the shortest distance between the first sub-target corner grid corresponding to the third direct connection and the endpoint grid. The movement path of the virtual character is determined based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection diagram.

5. The method as described in claim 4, characterized in that, Determining the movement path of the virtual character based on the second direct connection line, the third direct connection line, and the second sub-target corner point connection diagram includes: The A* algorithm is used to find the shortest route from the starting grid to the ending grid by using the route map composed of the second direct connection, the third direct connection, and the second sub-target corner point connection map. When the virtual character moves along a grid path, the grid path with the fewest grids between the starting grid and the ending grid is determined according to the shortest route trend, and the grid path is used as the movement path. When the virtual character moves along a smooth path, the shortest route is smoothed, and the first sub-target corner points that can be connected by a straight line in the shortest route are connected to form a straight path, which is then used as the movement path.

6. The method as described in claim 1, characterized in that, The step of updating the first direct connection corresponding to the first sub-target corner grid affected by changes in the impassable grid includes: Delete the first direct line corresponding to the corner point grid of the second sub-target to obtain the corner point connection diagram of the second sub-target; Based on the second sub-target corner point connection diagram and the third sub-target corner point grid corresponding to the newly added impassable grid, construct the third sub-target corner point connection diagram.

7. The method as described in claim 6, characterized in that, The step of constructing a third sub-target corner point connection map based on the second sub-target corner point connection map and the third sub-target corner point grid corresponding to the newly added impassable grid includes: Based on the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram, a fourth direct connection is constructed between the third sub-target corner grid and the first sub-target corner grid in the second sub-target corner connection diagram to update the second sub-target corner connection diagram and obtain the third sub-target corner connection diagram. The fifth candidate path between the two sub-target corner grids corresponding to the fourth direct connection does not pass through the impassable grid, the newly added impassable grid, or other sub-target corner grids. The fifth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fourth direct connection.

8. The method as described in claim 1, characterized in that, When it is detected that an impassable grid has been deleted in the two-dimensional virtual scene, the determination of the first sub-target corner grid affected by the change in the impassable grid includes: Determine the fourth sub-target corner grid in the first sub-target corner grid that is related to the first straight line connecting the deleted impassable grid, so that the fourth sub-target corner grid is regarded as the first sub-target corner grid affected by the change of the impassable grid.

9. The method as described in claim 8, characterized in that, The step of updating the first direct connection corresponding to the first sub-target corner grid affected by changes in the impassable grid includes: Delete the first direct line corresponding to the corner point grid of the fourth sub-target to obtain the corner point connection diagram of the fourth sub-target; Based on the first sub-target corner point grid included in the fourth sub-target corner point connection diagram, construct the fifth sub-target corner point connection diagram.

10. The method as described in claim 9, characterized in that, The step of constructing a fifth sub-target corner point connection map based on the first sub-target corner point grid included in the fourth sub-target corner point connection map includes: Based on the fourth sub-target corner grids included in the fourth sub-target corner grid connection map, a fifth direct connection is constructed between the fourth sub-target corner grids included in the fourth sub-target corner grid connection map to update the fourth sub-target corner grid connection map and obtain a fifth sub-target corner grid connection map. The sixth candidate path between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map does not pass through the impassable grids and other sub-target corner grids. The sixth candidate path is the path with the shortest distance between the two sub-target corner grids corresponding to the fifth sub-target corner grid connection map.

11. A path determination device for a two-dimensional virtual scene, characterized in that, The two-dimensional virtual scene includes passable grids and impassable grids composed of virtual obstacles, and the device includes: The determining unit is used to traverse the passable grid and determine the first sub-target corner point in the two-dimensional virtual scene. The diagonal grid corresponding to the corner point grid where the first sub-target corner point is located includes the grid located in the impassable grid, and the grids adjacent to the corner point grid that are closer to the virtual obstacle in the horizontal and vertical directions are located in the passable grid. The construction unit is used to construct a first sub-target corner point connection map based on the first sub-target corner point, which is formed by the first direct line connecting the first sub-target corner points. Among all the first candidate paths obtained according to the grid distribution of the two first sub-target corner points corresponding to the first direct line, none of them pass through the impassable grid or the grid where the other first sub-target corner points are located. The first candidate path is the path with the shortest distance between the two first sub-target corner point grids corresponding to the first direct line. A path unit is used to determine the movement path of the virtual character based on the starting grid of the virtual character, the ending grid set for the virtual character, and the line drawing connecting the corner points of the first sub-target. The building unit is further configured to: After obtaining the first sub-target corner point connection diagram, after detecting a change in the impassable grid in the two-dimensional virtual scene, the first sub-target corner point grid affected by the change in the impassable grid is determined. Based on the changes in the impassable grid, update the first direct connection corresponding to the first sub-target corner grid affected by the changes. When the construction unit is used to determine the first sub-target corner grid affected by the change of the impassable grid, it includes: When a new impassable grid is detected in the two-dimensional virtual scene, the passable grids surrounding the new impassable grid in each direction are traversed to determine the second sub-target corner grid that does not meet the requirements of the first sub-target corner grid, so that the second sub-target corner grid is used as the affected first sub-target corner grid.

12. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable 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 machine-readable instructions to perform a path determination method for a two-dimensional virtual scene as described in any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the path determination method for a two-dimensional virtual scene as described in any one of claims 1 to 10.

Citation Information

Patent Citations

  • Obstacle avoidance itinerant method and system of mowing robot

    CN114035572A

  • Rapid robot path planning method based on sparse views

    CN115220448A