Pathfinding method and device of game building, electronic equipment and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-21
- Publication Date
- 2026-08-11
AI Technical Summary
目前通常使用导航网格(Navigation Mesh)这种数据结构来描述建筑中可行走的区域,如果玩家改变建筑的外观,采用导航网格进行寻路的计算过程复杂、会占用过多的计算资源、导致运行效率低并且会影响玩家的游戏体验
[0054] This invention provides a pathfinding method, apparatus, electronic device, and storage medium for game buildings. The method involves acquiring the position of each component within a game building; generating graph data of the game building based on the position of each component, including the connectivity relationships between multiple components; then performing path planning based on a preset algorithm and the graph data to obtain the walking areas of all components traversed along each path, resulting in a set of walking areas; finally, for each set of walking areas, determining multiple waypoints based on each walking area to obtain the corresponding route, thus obtaining the route corresponding to each set of walking areas. By employing a graph data structure more closely aligned with the game building scene to store the connectivity relationships between components, the computational complexity is reduced, thereby improving game performance and optimizing the gaming experience.
Smart Images

Figure CN115888109B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of online game technology, and more specifically, to a pathfinding method, device, electronic device, and storage medium for game buildings. Background Technology
[0002] In online games, players can freely place game-provided components to create buildings. Pathfinding within these buildings provides routes for NPCs (Non-Player Characters). Currently, a navigation mesh is commonly used to describe walkable areas within buildings. However, if players alter the building's appearance, the pathfinding calculations using a navigation mesh become complex, consume excessive computing resources, lead to low efficiency, and negatively impact the player's gaming experience. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a pathfinding method, device, electronic device and storage medium for game buildings.
[0004] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0005] In a first aspect, the present invention provides a pathfinding method for game buildings, the method comprising:
[0006] Get the position of each component in the game building;
[0007] Based on the location of each component, graph data of the game building is generated, and the graph data includes the connectivity relationships between multiple components;
[0008] Path planning is performed based on the preset algorithm and the graph data to obtain the walking area of all components passed through in each path, thus obtaining a set of each walking area;
[0009] For each set of walking areas, multiple waypoints are determined based on each walking area in the set to obtain the corresponding route, thus obtaining the route corresponding to each set of walking areas.
[0010] In an optional implementation, the components include a foundation component, a slab component, and a sloping roof component;
[0011] The step of generating the graph data of the game building based on the position of each component includes:
[0012] Take any one of the aforementioned foundation components as the target foundation component;
[0013] Based on the location of the target foundation component, all connected components of the target foundation component are obtained; wherein, all connected components of the target foundation component include each foundation component, each layer plate component, and each sloping roof component connected to the target foundation component;
[0014] Traverse each of the foundation components to obtain all connected components of each foundation component;
[0015] The graph data of the game building is generated based on all connected components of each of the foundation components.
[0016] In an optional implementation, the component further includes a wall component; one of the components belongs to a voxel in the game structure;
[0017] The step of obtaining all connected components of the target foundation component based on its location includes:
[0018] The voxel above the target foundation component is taken as the first voxel, and each preset direction is obtained;
[0019] For each preset direction, if the first voxel does not have the wall component in the preset direction, then the voxel adjacent to the first voxel in the preset direction is taken as the second voxel and the preset direction is taken as the target direction corresponding to the second voxel, so as to obtain each second voxel and its corresponding target direction.
[0020] Based on each second voxel and its corresponding target direction, all connected components of the target foundation component in each target direction are determined, thereby obtaining all connected components of the target foundation component.
[0021] In an optional implementation, the step of determining all connected components of the target foundation component in each target direction based on each second voxel and its corresponding target direction includes:
[0022] Take any one of the second voxels as the target voxel and the target direction corresponding to the target voxel as the direction to be processed, and take the direction opposite to the direction to be processed as the reference direction;
[0023] Obtain a third voxel located above the target voxel. If the third voxel does not have the wall assembly in the reference direction but has the sloping roof assembly, then obtain the first connecting assembly.
[0024] If the target voxel does not have the wall assembly in the reference direction but has the sloping roof assembly, then a second connecting assembly is obtained;
[0025] If the target voxel does not have the wall assembly in the reference direction and the layer assembly is present in the target voxel, then a third connecting assembly is obtained, and the first connecting assembly, the second connecting assembly, and the third connecting assembly are taken as all connecting assemblies of the target foundation assembly in the direction to be processed.
[0026] If the target voxel has no wall component in the target direction and the foundation component exists in the target voxel, then a fourth connecting component is obtained, and the first connecting component and the fourth connecting component are taken as all connecting components of the target foundation component in the direction to be processed.
[0027] By traversing each of the second voxels, all connected components of the target foundation component in each target direction are obtained.
[0028] In an optional implementation, all walking areas in the walking area set are arranged according to a preset walking order;
[0029] The step of determining multiple waypoints for each walking region in the set of walking regions to obtain the corresponding route includes:
[0030] Obtain the first walking region and the last walking region from the set of walking regions, and take the center point of the first walking region as the starting point and the center point of the last walking region as the ending point;
[0031] According to the preset walking sequence, each corner point from the starting point to the ending point is determined based on each walking area to obtain all path points; all path points include the starting point, the ending point and each corner point.
[0032] By sequentially connecting each path point according to the preset walking order, the route corresponding to the walking area set is obtained.
[0033] In an optional implementation, the walking area includes two exit endpoints;
[0034] The step of determining each corner point from the starting point to the ending point based on each walking area includes:
[0035] The first walking area is taken as the first target area and the starting point is taken as the reference point;
[0036] Two reference line segments are obtained by connecting the reference point with the two exit endpoints of the first target area;
[0037] The second target region is obtained by acquiring the next walking area of the first target region;
[0038] Two undetermined points are obtained by acquiring the two exit endpoints of the second target area;
[0039] Determine whether one of the two undetermined points is a target point located outside the area covered by the two reference line segments;
[0040] If the target point exists and the second target area is not the tail walking area, then the exit endpoint of the reference line segment near the target point is taken as the corner point, and the corner point is taken as the reference point and the second target area is taken as the first target area. Then, the above steps of connecting the two exit endpoints of the reference point and the first target area to obtain two reference line segments are repeated until the second target area is the tail walking area to obtain each corner point.
[0041] If the target point does not exist and the second target area is not the tail walking area, then after taking the second target area as the first target area, repeat the above steps of obtaining the second target area by acquiring the next walking area of the first target area until the second target area is the tail walking area to obtain each corner point.
[0042] Secondly, the present invention provides a pathfinding device for game buildings, the device comprising:
[0043] The acquisition module is used to acquire the position of each component in the game building;
[0044] A generation module is used to generate graph data of the game building based on the position of each component, the graph data including the connectivity relationships between multiple components;
[0045] The planning module is used to perform path planning based on a preset algorithm and the graph data, obtain the walking area of all components passed through in each path, and obtain a set of each walking area;
[0046] The pathfinding module is used to determine multiple waypoints for each walking area set to obtain the corresponding route, thereby obtaining the route corresponding to each walking area set.
[0047] In an optional implementation, the components include a foundation component, a layered slab component, and a sloping roof component; the generation module is specifically used for:
[0048] Take any one of the aforementioned foundation components as the target foundation component;
[0049] Based on the location of the target foundation component, all connected components of the target foundation component are obtained; wherein, all connected components of the target foundation component include each foundation component, each layer plate component, and each sloping roof component connected to the target foundation component;
[0050] Traverse each of the foundation components to obtain all connected components of each foundation component;
[0051] The graph data of the game building is generated based on all connected components of each of the foundation components.
[0052] Thirdly, the present invention provides an electronic device including a processor and a memory, the memory storing a computer program, wherein when the processor executes the computer program, it implements the method described in any of the foregoing embodiments.
[0053] Fourthly, the present invention provides a storage medium storing a computer program, which, when executed by a processor, implements the method described in any one of the foregoing embodiments.
[0054] This invention provides a pathfinding method, apparatus, electronic device, and storage medium for game buildings. The method involves acquiring the position of each component within a game building; generating graph data of the game building based on the position of each component, including the connectivity relationships between multiple components; then performing path planning based on a preset algorithm and the graph data to obtain the walking areas of all components traversed along each path, resulting in a set of walking areas; finally, for each set of walking areas, determining multiple waypoints based on each walking area to obtain the corresponding route, thus obtaining the route corresponding to each set of walking areas. By employing a graph data structure more closely aligned with the game building scene to store the connectivity relationships between components, the computational complexity is reduced, thereby improving game performance and optimizing the gaming experience.
[0055] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0056] To more clearly illustrate the technical solutions of the embodiments of the present invention, 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 the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0057] Figure 1 A block diagram of an electronic device provided in an embodiment of the present invention is shown;
[0058] Figure 2 This illustration shows a flowchart of a pathfinding method for game buildings provided in an embodiment of the present invention;
[0059] Figure 3An example diagram of a pathfinding method for game buildings provided in an embodiment of the present invention is shown;
[0060] Figure 4 This diagram illustrates yet another example of the pathfinding method for game buildings provided in this embodiment of the invention;
[0061] Figure 5 This diagram illustrates yet another example of the pathfinding method for game buildings provided in this embodiment of the invention;
[0062] Figure 6 This diagram illustrates yet another example of the pathfinding method for game buildings provided in this embodiment of the invention;
[0063] Figure 7 This illustration shows another flowchart of the pathfinding method for game buildings provided in an embodiment of the present invention;
[0064] Figure 8 This illustration shows another flowchart of the pathfinding method for game buildings provided in an embodiment of the present invention;
[0065] Figure 9 This diagram illustrates yet another example of the pathfinding method for game buildings provided in this embodiment of the invention;
[0066] Figure 10 This diagram illustrates yet another example of the pathfinding method for game buildings provided in this embodiment of the invention;
[0067] Figure 11 This diagram illustrates a functional module of a pathfinding device for game buildings provided in an embodiment of the present invention.
[0068] Icons: 100 - Electronic device; 110 - Bus; 120 - Processor; 130 - Memory; 150 - I / O module; 170 - Communication interface; 300 - Pathfinding device for game buildings; 310 - Acquisition module; 330 - Generation module; 350 - Planning module; 370 - Pathfinding module. Detailed Implementation
[0069] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0070] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0071] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0072] In online games, players can freely place game-provided components to create buildings. Pathfinding within these buildings provides routes for NPCs (Non-Player Characters). Currently, navigation meshes are commonly used to describe walkable areas within buildings. However, if players alter the building's appearance, the pathfinding calculation using navigation meshes becomes complex, consumes excessive computing resources, leads to low efficiency, and negatively impacts the player's gaming experience. Therefore, this invention provides a pathfinding method for game buildings to address these issues.
[0073] Please refer to Figure 1 This is a block diagram of an electronic device 100 provided in an embodiment of the present invention. The electronic device 100 includes a bus 110, a processor 120, a memory 130, an I / O module 150, and a communication interface 170.
[0074] Bus 110 may be a circuit that interconnects the aforementioned components and transmits communication (e.g., control messages) between them.
[0075] The processor 120 can receive commands from the other components (such as memory 130, I / O module 150, communication interface 170, etc.) via bus 110, interpret the received commands, and perform calculations or data processing according to the interpreted commands.
[0076] The processor 120 can be an integrated circuit chip with signal processing capabilities. The processor 120 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0077] The memory 130 may store commands or data received from the processor 120 or other components (such as I / O module 150, communication interface 170, etc.) or commands or data generated by the processor 120 or other components.
[0078] The memory 130 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), or electrically erasable programmable read-only memory (EEPROM).
[0079] The I / O module 150 can receive commands or data input by the user via input-output means (e.g., sensors, keyboard, touch screen, etc.), and can transmit the received commands or data to the processor 120 or memory 130 via the bus 110. It is also used to display various information received, stored, and processed from the aforementioned components (e.g., multimedia data, text data), and can display video, images, data, etc., to the user.
[0080] Communication interface 170 can be used to communicate with other node devices for signaling or data.
[0081] Understandable Figure 1 The structure shown is only a schematic diagram of the electronic device 100. The electronic device 100 may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0082] The electronic devices provided in this embodiment of the invention can be smartphones, personal computers, tablets, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. This embodiment of the invention does not impose any limitations on these. It should be understood that the electronic device has an application installed for creating game structures, and the electronic device executes the pathfinding method for game structures provided in this embodiment of the invention while running the application.
[0083] The above-mentioned electronic device 100 will be used as the execution subject to execute the various steps of the various methods provided in the embodiments of the present invention and achieve the corresponding technical effects.
[0084] Please see Figure 2 , Figure 2 This is a flowchart illustrating a pathfinding method for game buildings provided in an embodiment of the present invention.
[0085] Step S202: Obtain the position of each component in the game building;
[0086] In this embodiment, players can assemble game buildings using components provided by the game. Optionally, four types of components can be provided, such as foundation components, wall components, shelf components, and sloping roof components.
[0087] For ease of understanding, several example figures are provided in the embodiments of the present invention. Please refer to them. Figures 3 to 6 .like Figure 3 The image shows the foundation components; as shown Figure 4 The image shows the foundation assembly and the slab assembly; as shown Figure 5 The diagram shows the foundation components and the sloping roof components; as shown Figure 6 The foundation components and wall components are shown.
[0088] Understandably, each component in a game building has basic information, including its position, category, and orientation. For example, this basic information can be represented using `BlockIndex(x,y,z,w)`, where `x`, `y`, and `z` represent the component's three-dimensional coordinates within the game building; `w` represents the component's category and orientation. Specifically, `w` could be defined as: 0 for foundation, 1 for a wall facing backward, 2 for a wall facing right, 3 for a wall facing forward, 4 for a wall facing left, 5 for a sloping roof facing backward, 6 for a sloping roof facing right, 7 for a sloping roof facing forward, 8 for a sloping roof facing left, and 9 for a shelf. Using `BlockIndex` to store this basic information occupies less space and facilitates network transmission and data storage.
[0089] The location of each component can be determined by obtaining basic information about each component in the game building.
[0090] Step S204: Generate graph data of the game building based on the position of each component. The graph data includes the connectivity relationships between multiple components.
[0091] In this embodiment, the foundation component, the floor slab component, and the sloping roof component allow the game character to walk, but the wall component does not. This can be understood as the first three components being interconnected, while the wall component is not interconnected with any of the first three components. For any given component, its location determines all connected components, and this process is repeated to iterate through each component, obtaining the connectivity relationships between multiple components to generate the graph data of the game building.
[0092] It is understood that the embodiments of the present invention use nodes in image data to represent components and edges in graph data to represent the connection between two components. That is, by using a data structure that is more in line with the game building scene to store the connection relationship between components, information redundancy can be avoided and storage space can be saved. Furthermore, the game's running efficiency can be improved and the game experience can be optimized.
[0093] Step S206: Perform path planning based on the preset algorithm and graph data to obtain the walking area of all components passed through in each path, and obtain a set of each walking area;
[0094] In this embodiment, the preset algorithm can be the A* algorithm, also known as the A-Star algorithm. The A* algorithm is used to plan paths based on the connectivity between components in the graph data, which can obtain the walking areas of all components passed through in each path, thus obtaining a set of each walking area.
[0095] The path component can be understood as the component contained in the path. Since each component is a cube, the path is formed by a certain surface of each path component. This surface is the walking area, and the walking area is rectangular.
[0096] Step S208: For each set of walking areas, determine multiple waypoints based on each walking area in the set to obtain the corresponding route, thus obtaining the route corresponding to each set of walking areas.
[0097] In this embodiment, for any set of walking areas, multiple waypoints can be determined for each walking area in the set, and connecting these waypoints yields the corresponding route. By traversing each set of walking areas in a similar manner, the route corresponding to each set of walking areas can be obtained.
[0098] As can be seen from the above steps, the location of each component in the game building is obtained; and graph data of the game building is generated based on the location of each component. The graph data includes the connectivity relationships between multiple components; then, path planning is performed according to a preset algorithm and the graph data to obtain the walking areas of all components passed through in each path, resulting in a set of walking areas; finally, for each set of walking areas, multiple waypoints are determined based on each walking area to obtain the corresponding route, resulting in the route corresponding to each set of walking areas. By adopting a graph data structure that is more closely aligned with the game building scene to store the connectivity relationships between components, the computational complexity is reduced, thereby improving the game's running efficiency and optimizing the game experience.
[0099] Optionally, for step S204 above, this embodiment of the invention provides a possible implementation method, please refer to [link to relevant documentation]. Figure 7 .
[0100] Step S204-1: Select any one of the foundation components as the target foundation component;
[0101] Step S204-3: Based on the location of the target foundation component, obtain all connected components of the target foundation component; wherein, all connected components of the target foundation component include each foundation component, each layer plate component, and each inclined roof component connected to the target foundation component;
[0102] Step S204-5: Traverse each foundation component to obtain all connected components of each foundation component;
[0103] Step S204-7: Generate the graph data of the game building based on all connected components of each foundation component.
[0104] Understandably, the methods for obtaining all connected components of each foundation component are similar, so the following example will use any one foundation component as the target foundation component.
[0105] In this embodiment, since the foundation component, the slab component, and the sloping roof component can be interconnected, each foundation component, each slab component, and each sloping roof component connected to the target foundation component can be determined based on the location of the target foundation component, so as to obtain all the connected components of the target foundation component.
[0106] By processing each foundation component in a similar manner as described above, all connected components of each foundation component can be obtained. Then, each foundation component and all its connected components are treated as nodes, and the nodes representing the foundation components and all the nodes representing its connected components are connected to represent the connection between the foundation components and all its connected components through connecting edges, thus generating the graph data of the game building.
[0107] Understandably, compared to a navigation mesh data structure, graph data does not require recording the vertex information of the triangles in each connected component. Since the surface of each connected component in this embodiment is rectangular, the extent of the surface can be determined based on its center point. Therefore, compared to a navigation mesh, graph data is more suitable for the data storage needs of pathfinding scenarios in game architecture.
[0108] Optionally, for the above steps S204-3, the present invention provides a possible implementation method.
[0109] Step S204-3-1: Take the voxel above the target foundation component as the first voxel and obtain each preset direction;
[0110] Step S204-3-5: For each preset direction, if there is no wall component in the preset direction for the first voxel, then the voxel adjacent to the first voxel in the preset direction is taken as the second voxel and the preset direction is taken as the target direction corresponding to the second voxel, so as to obtain each second voxel and its corresponding target direction.
[0111] Step S204-3-7: Based on each second voxel and its corresponding target direction, determine all connected components of the target foundation component in each target direction, and obtain all connected components of the target foundation component.
[0112] Understandably, the preset orientation can be any of the four directions around the voxel: forward, backward, left, and right. Game structures consist of multiple voxels, which are the smallest unit of division in three-dimensional space. Each component can be placed within a voxel. For example, a voxel can hold one foundation component, meaning a foundation component will fill one voxel. A voxel can hold a maximum of four wall components, four sloping roof components, and one shelf component, meaning a voxel can hold a maximum of nine components.
[0113] In this embodiment, the voxel located above the target foundation component can be obtained to obtain the first voxel, and each preset direction, namely the four directions of front, back, left, and right, can be obtained. Then, it is determined whether the first voxel has a wall component in each preset direction.
[0114] If the first voxel has a wall component in a certain preset direction, it means that the connectivity between the target foundation component and other components in that preset direction will be blocked by this wall component, that is, there is no connecting component for the target foundation component in that preset direction.
[0115] If the first voxel does not have a wall component in a certain preset direction, it indicates that the connectivity between the target foundation component and other components in that preset direction will not be obstructed. That is, the target foundation component has a connected component in that preset direction. Then, the voxel adjacent to the first voxel in that preset direction is obtained to obtain the second voxel, and the preset direction is taken as the target direction corresponding to the second voxel.
[0116] For each preset direction, the process is repeated in a similar manner to obtain each second voxel and its corresponding target direction. Finally, based on each second voxel and its corresponding target direction, all connected components of the target foundation component in each target direction are determined, thus obtaining all connected components of the target foundation component.
[0117] Optionally, for step S204-3-7 above, the present invention provides a possible implementation method.
[0118] Step S204-3-7-1: Take any second voxel as the target voxel and the target direction corresponding to the target voxel as the direction to be processed, and take the direction opposite to the direction to be processed as the reference direction;
[0119] Step S204-3-7-3: Obtain the third voxel located above the target voxel. If the third voxel has no wall component and has a sloping top component in the reference direction, then obtain the first connected component.
[0120] Step S204-3-7-5: If the target voxel has no wall component and has a sloping top component in the reference direction, then the second connected component is obtained;
[0121] Step S204-3-7-7A: If the target voxel has no wall component in the reference direction and there is a layer plate component in the target voxel, then the third connected component is obtained, and the first connected component, the second connected component and the third connected component are taken as all connected components of the target foundation component in the direction to be processed.
[0122] Step S204-3-7-7B: If the target voxel has no wall component in the target direction and there is a foundation component in the target voxel, then the fourth connected component is obtained, and the first connected component and the fourth connected component are taken as all connected components of the target foundation component in the direction to be processed.
[0123] Step S204-3-7-9: Traverse each second voxel to obtain all connected components of the target foundation component in each target direction.
[0124] It is understandable that the way to determine all connected components of the target foundation component in each target direction is similar, so the following example will be given using any second voxel as the target voxel and the target direction corresponding to the target voxel as the direction to be processed.
[0125] For ease of understanding, an example is provided in this embodiment of the invention. For instance, the second voxel adjacent to the first voxel in the right direction is taken as the target voxel, and the target direction corresponding to the target voxel, i.e., the right direction, is taken as the direction to be processed.
[0126] The direction opposite to the direction to be processed (i.e., the right direction) can be used as the reference direction, i.e., the reference direction is the left direction; then, the voxel located above the target voxel is obtained to get the third voxel. If the third voxel does not have a wall component in the left direction and the third voxel has a sloping top component in the left direction, then the sloping top component is used as the first connected component.
[0127] If the target voxel has no wall assembly in the left direction but has a sloping roof assembly in the left direction, then the sloping roof assembly is designated as the second connected assembly. If the target voxel has no wall assembly in the left direction but has a layer assembly in the target voxel, then the layer assembly is designated as the third connected assembly. Finally, the first, second, and third connected assemblies are designated as all connected assemblies of the target foundation assembly in the right direction.
[0128] If the target voxel has no wall components in the left direction but has a foundation component, then that foundation component is designated as the fourth connected component. Finally, the first and fourth connected components are designated as all connected components of the target foundation component in the right direction.
[0129] By processing each second voxel and its corresponding target direction in a similar manner as described above, all connected components of the target foundation component in each target direction can be obtained, that is, all connected components of the target foundation component can be obtained.
[0130] Optionally, for step S208 above, which involves determining multiple waypoints based on each walking area in the walking area set to obtain the corresponding route, this embodiment of the invention provides a possible implementation method. Please refer to [link to relevant documentation]. Figure 8 .
[0131] Step S208-1: Obtain the first walking region and the last walking region from the walking region set, and take the center point of the first walking region as the starting point and the center point of the last walking region as the ending point.
[0132] Step S208-3: According to the preset walking sequence, determine each corner point from the starting point to the ending point for each walking area to obtain all path points; all path points include the starting point, the ending point and each corner point;
[0133] Step S208-5: Connect each path point in sequence according to the preset walking order to obtain the route corresponding to the walking area set.
[0134] In this embodiment, all walking areas in the walking area set are arranged according to a preset walking order. The first walking area in the walking area set can be designated as the first walking area and the last walking area as the last walking area, with the center point of the first walking area as the starting point and the center point of the last walking area as the ending point. Then, according to the preset walking order, each corner point from the starting point to the ending point is determined for each walking area, and the starting point, the ending point, and each corner point are all used as path points, thus obtaining all path points. Finally, each path point is connected sequentially according to the preset walking order to obtain the route corresponding to the walking area set.
[0135] Optionally, for the process of determining each corner point from the starting point to the ending point based on each walking area in step S208-3 above, the present invention provides a possible implementation method.
[0136] Step S208-3-1: Take the first walking area as the first target area and the starting point as the reference point;
[0137] Step S208-3-3: Connect the reference point with the two exit endpoints of the first target area to obtain two reference line segments;
[0138] Step S208-3-5: Obtain the next walking area after the first target area to obtain the second target area;
[0139] Step S208-3-7: Obtain the two exit endpoints of the second target area to obtain two undetermined points;
[0140] Step S208-3-9: Determine whether there is a target point among the two undetermined points that is located outside the area covered by the two reference line segments;
[0141] Step S208-3-11A: If there is a target point and the second target area is not a tail-walking area, then take the exit endpoint of the reference line segment near the target point as the corner point, and take the corner point as the reference point and the second target area as the first target area. Repeat the above steps of connecting the two exit endpoints of the reference point and the first target area to obtain two reference line segments until the second target area is a tail-walking area and each corner point is obtained.
[0142] Step S208-3-11B: If there is no target point and the second target area is not a tail walking area, then after taking the second target area as the first target area, repeat the above steps of obtaining the second target area by obtaining the next walking area of the first target area until the second target area is a tail walking area to obtain each corner point.
[0143] In this embodiment, each walking area has two exit endpoints, which represent the exits of that walking area. It should be understood that the two exit endpoints are slightly smaller than the side length of the walking area to prevent the game character from clipping through.
[0144] For ease of understanding, several example figures are provided in the embodiments of the present invention. Please refer to them. Figures 9 to 10 .like Figure 9 The image shows a route from point S to point R within a game building. This route corresponds to a set of 7 walkable areas. Figure 10 The regions shown are 1 to 7, each with two exit endpoints, ai and bi, where i ranges from 1 to 7.
[0145] The following will combine Figures 9 to 10 The steps S208-3-1 to S208-3-11B above will be explained.
[0146] In steps S208-3-1 and S208-3-3, the initial walking area, i.e., area 1, is taken as the first target area, and the starting point, i.e., point S, is taken as the reference point. Point S is then connected to the two exit endpoints of the first target area, i.e., point a1 and point b1, to obtain two reference line segments. These two reference line segments can be represented by lineleft and lineright, i.e., lineleft is the line segment connecting point S and point a1, and lineright is the line segment connecting point S and point b1.
[0147] In steps S208-3-5 and S208-3-7, the next walking area after the first target area is obtained to obtain the second target area, namely area 2, and the two exit endpoints of area 2 are obtained to obtain two undetermined points, namely points a2 and b2.
[0148] In step S208-3-9, it is determined whether there is a target point outside the area covered by the two undetermined points, namely a2 and b2. If a target point exists and the second target area is not the tail target area, then step S208-3-11A is executed; if no target point exists and the second target area is not the tail target area, then step S208-3-11B is executed.
[0149] The area covered by two reference line segments can be understood as the area corresponding to the angle formed by the two segments. For example... Figure 10As shown, since point a2 is not within the area covered by the two reference line segments, i.e., point a2 is the target point, there is a target point and region 2 is not the last walking region. Then, execute step S208-3-11A, that is, take the exit endpoint of the reference line segment that is close to the target point, i.e., point a2, i.e., point a1, as the corner point, and take the corner point, i.e. point a1, as the reference point and the second target region, i.e. region 2, as the first target region, and repeat steps S208-3-3 to S208-3-9.
[0150] Then, connect the reference point a1 with the two exit endpoints of the first target area (area 2), a2 and b2, to obtain two new reference line segments: lineleft (connecting a1 and a2) and lineright (connecting a1 and b2). Next, obtain the next walking area of the first target area to obtain the second target area (area 3), and obtain the two exit endpoints of area 3 to obtain two undetermined points, a3 and b3.
[0151] Next, determine whether either of the two undetermined points, a3 and b3, exists as a target point outside the area covered by the two reference line segments, lineleft and lineright. For example... Figure 10 As shown, points a3 and b3 are not within the area covered by the two reference line segments, meaning that points a3 and b3 are both target points. Therefore, there are target points and region 3 is not the last region. Then, execute step S208-3-11A, which means taking the exit endpoint of the reference line segment (lineleft) that is close to the target points (a3 and b3), i.e., point a2, as the corner point, and taking the corner point (a2) as the reference point and the second target region (region 3) as the first target region. Then, repeat steps S208-3-3 to S208-3-9.
[0152] Processing in a similar manner until the second target area is area 7, we can obtain each corner point, namely points a1, a2, a3, a4, b5, and b6. Finally, connecting the starting point (point S), each corner point, and the ending point (point R) sequentially yields the route corresponding to the walking area set from area 1 to area 7, as shown below. Figure 9 As shown.
[0153] To perform the corresponding steps in the above embodiments and various possible methods, an implementation of a pathfinding device for game buildings is given below. Please refer to... Figure 11 , Figure 11This is a functional block diagram of a pathfinding device 300 for a game building provided in this embodiment of the invention. It should be noted that the basic principle and technical effects of the pathfinding device 300 for a game building provided in this embodiment are the same as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments. The pathfinding device 300 for a game building includes:
[0154] Module 310 is used to obtain the position of each component in the game building;
[0155] The generation module 330 is used to generate graph data of the game building based on the position of each component. The graph data includes the connectivity relationships between multiple components.
[0156] The planning module 350 is used to perform path planning based on a preset algorithm and graph data, obtain the walking area of all components passed through in each path, and obtain a set of each walking area;
[0157] The pathfinding module 370 is used to determine multiple waypoints for each walking area set to obtain the corresponding route, thus obtaining the route corresponding to each walking area set.
[0158] Optionally, the generation module 330 is specifically used for: taking any one foundation component as the target foundation component; obtaining all connected components of the target foundation component based on its location; wherein, all connected components of the target foundation component include each foundation component, each slab component, and each sloping roof component connected to the target foundation component; traversing each foundation component to obtain all connected components of each foundation component; and generating graph data of the game building based on all connected components of each foundation component.
[0159] Optionally, the generation module 330 is specifically used to: take the voxel above the target foundation component as the first voxel and obtain each preset direction; for each preset direction, if there is no wall component in the first voxel in the preset direction, take the voxel adjacent to the first voxel in the preset direction as the second voxel and take the preset direction as the target direction corresponding to the second voxel, to obtain each second voxel and its corresponding target direction; based on each second voxel and its corresponding target direction, determine all connected components of the target foundation component in each target direction, to obtain all connected components of the target foundation component.
[0160] Optionally, the generation module 330 is specifically used for: taking any second voxel as the target voxel and the target direction corresponding to the target voxel as the direction to be processed, and taking the direction opposite to the direction to be processed as the reference direction; obtaining the third voxel located above the target voxel; if the third voxel has no wall component and has a sloping roof component in the reference direction, then obtaining the first connected component; if the target voxel has no wall component and has a sloping roof component in the reference direction, then obtaining the second connected component; if the target voxel has no wall component in the reference direction and has a shelf component in the target voxel, then obtaining the third connected component, and taking the first connected component, the second connected component, and the third connected component as all connected components of the target foundation component in the direction to be processed; if the target voxel has no wall component in the target direction and has a foundation component in the target voxel, then obtaining the fourth connected component, and taking the first connected component and the fourth connected component as all connected components of the target foundation component in the direction to be processed; traversing each second voxel to obtain all connected components of the target foundation component in each target direction.
[0161] Optionally, the pathfinding module 370 is specifically used to: obtain the first walking area and the last walking area from the walking area set, and take the center point of the first walking area as the starting point and the center point of the last walking area as the ending point; determine each corner point from the starting point to the ending point according to the preset walking order, and obtain all path points; all path points include the starting point, the ending point and each corner point; connect each path point in sequence according to the preset walking order to obtain the route corresponding to the walking area set.
[0162] Optionally, the pathfinding module 370 is specifically used for: taking the initial walking area as the first target area and the starting point as the reference point; connecting the reference point with the two exit endpoints of the first target area to obtain two reference line segments; obtaining the next walking area of the first target area to obtain the second target area; obtaining the two exit endpoints of the second target area to obtain two undetermined points; determining whether there is a target point located outside the area covered by the two reference line segments among the two undetermined points; if there is a target point and the second target area is not the tail walking area, then taking the exit endpoint of the reference line segment near the target point as a corner point, and taking the corner point as a reference point and the second target area as the first target area, repeating the above steps of connecting the reference point with the two exit endpoints of the first target area to obtain two reference line segments until the second target area is the tail walking area to obtain each corner point; if there is no target point and the second target area is not the tail walking area, then taking the second target area as the first target area, repeating the above steps of obtaining the next walking area of the first target area to obtain the second target area until the second target area is the tail walking area to obtain each corner point.
[0163] This invention also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the pathfinding method for game buildings disclosed in this invention.
[0164] This invention also provides a storage medium storing a computer program, which, when executed by a processor, implements the pathfinding method for game buildings disclosed in this invention.
[0165] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0166] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0167] If the aforementioned functions are implemented as software functional modules 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 invention, essentially, 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 invention. 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.
[0168] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A pathfinding method for game buildings, characterized in that, The method includes: Obtain the position of each component in the game building, wherein the components include foundation components, floor slab components, and sloping roof components; Take any one of the aforementioned foundation components as the target foundation component; Based on the location of the target foundation component, all connected components of the target foundation component are obtained; wherein, all connected components of the target foundation component include each foundation component, each layer plate component, and each sloping roof component connected to the target foundation component; Traverse each of the foundation components to obtain all connected components of each foundation component; The graph data of the game building is generated based on all connected components of each of the foundation components; Path planning is performed based on the preset algorithm and the graph data to obtain the walking area of all components passed through in each path, thus obtaining a set of each walking area; For each set of walking areas, multiple waypoints are determined based on each walking area in the set to obtain the corresponding route, thus obtaining the route corresponding to each set of walking areas.
2. The method according to claim 1, characterized in that, The components also include wall components; one of the components belongs to a voxel in the game structure; The step of obtaining all connected components of the target foundation component based on its location includes: The voxel above the target foundation component is taken as the first voxel, and each preset direction is obtained; For each preset direction, if the first voxel does not have the wall component in the preset direction, then the voxel adjacent to the first voxel in the preset direction is taken as the second voxel and the preset direction is taken as the target direction corresponding to the second voxel, so as to obtain each second voxel and its corresponding target direction. Based on each second voxel and its corresponding target direction, all connected components of the target foundation component in each target direction are determined, thereby obtaining all connected components of the target foundation component.
3. The method according to claim 2, characterized in that, The step of determining all connected components of the target foundation component in each target direction based on each second voxel and its corresponding target direction includes: Take any one of the second voxels as the target voxel and the target direction corresponding to the target voxel as the direction to be processed, and take the direction opposite to the direction to be processed as the reference direction; Obtain a third voxel located above the target voxel. If the third voxel does not have the wall assembly in the reference direction but has the sloping roof assembly, then obtain the first connecting assembly. If the target voxel does not have the wall assembly in the reference direction but has the sloping roof assembly, then a second connecting assembly is obtained; If the target voxel does not have the wall assembly in the reference direction and the layer assembly is present in the target voxel, then a third connecting assembly is obtained, and the first connecting assembly, the second connecting assembly, and the third connecting assembly are taken as all connecting assemblies of the target foundation assembly in the direction to be processed. If the target voxel has no wall component in the target direction and the foundation component exists in the target voxel, then a fourth connecting component is obtained, and the first connecting component and the fourth connecting component are taken as all connecting components of the target foundation component in the direction to be processed. By traversing each of the second voxels, all connected components of the target foundation component in each target direction are obtained.
4. The method according to claim 1, characterized in that, All walking areas in the set of walking areas are arranged in a preset walking order; The step of determining multiple waypoints for each walking region in the set of walking regions to obtain the corresponding route includes: Obtain the first walking region and the last walking region from the set of walking regions, and take the center point of the first walking region as the starting point and the center point of the last walking region as the ending point; According to the preset walking sequence, each corner point from the starting point to the ending point is determined based on each walking area to obtain all path points; all path points include the starting point, the ending point and each corner point. By sequentially connecting each path point according to the preset walking order, the route corresponding to the walking area set is obtained.
5. The method according to claim 4, characterized in that, The walking area includes two exit endpoints; The step of determining each corner point from the starting point to the ending point based on each walking area includes: The first walking area is taken as the first target area and the starting point is taken as the reference point; Two reference line segments are obtained by connecting the reference point with the two exit endpoints of the first target area; The second target region is obtained by acquiring the next walking area of the first target region; Two undetermined points are obtained by acquiring the two exit endpoints of the second target area; Determine whether one of the two undetermined points is a target point located outside the area covered by the two reference line segments; If the target point exists and the second target area is not the tail walking area, then the exit endpoint of the reference line segment near the target point is taken as the corner point, and the corner point is taken as the reference point and the second target area is taken as the first target area. Then, the above steps of connecting the two exit endpoints of the reference point and the first target area to obtain two reference line segments are repeated until the second target area is the tail walking area to obtain each corner point. If the target point does not exist and the second target area is not the tail walking area, then after taking the second target area as the first target area, repeat the above steps of obtaining the second target area by acquiring the next walking area of the first target area until the second target area is the tail walking area to obtain each corner point.
6. A pathfinding device for game buildings, characterized in that, The device includes: The acquisition module is used to acquire the position of each component in the game building, wherein the components include foundation components, floor slab components, and sloping roof components; A generation module is used to select any one of the foundation components as the target foundation component; obtain all connected components of the target foundation component based on its position; wherein, all connected components of the target foundation component include each foundation component, each slab component, and each sloping roof component connected to the target foundation component; traverse each foundation component to obtain all connected components of each foundation component; and generate the graph data of the game building based on all connected components of each foundation component. The planning module is used to perform path planning based on a preset algorithm and the graph data, obtain the walking area of all components passed through in each path, and obtain a set of each walking area; The pathfinding module is used to determine multiple waypoints for each walking area set to obtain the corresponding route, thereby obtaining the route corresponding to each walking area set.
7. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a computer program, and the processor, when executing the computer program, implements the method of any one of claims 1 to 5.
8. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the method of any one of claims 1 to 5.