Pathfinding Method, Device, Electronic Device and Readable Storage Medium in a Game
By voxelizing the game scene to generate two-dimensional and three-dimensional road-seeking maps, the problem that the path-seeking virtual objects in the existing technology cannot achieve two-dimensional and three-dimensional road-seeking at the same time is solved, efficient memory management and diversified way-seeking switching are realized, and the expressiveness and operability of the game are improved.
Patent Information
- Application Number
- CN202211128479.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-16
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2042-09-16
AI Technical Summary
The prior art is difficult to support the two-dimensional pathfinding and three-dimensional pathfinding of virtual objects in game scenes at the same time, resulting in high labor costs or high memory overhead, and the three-dimensional pathfinding effect is not good.
By voxelizing the game scene, a two-dimensional road search map and a three-dimensional road search map are generated, and the walkable and non-passable areas are processed respectively. The path search path is generated in combination with the specified path search algorithm, which supports switching of multiple path search methods.
It realizes supporting both two-dimensional and three-dimensional pathfinding in game scenarios, reducing memory overhead, improving the expressiveness and operability of the game, and meeting diverse pathfinding needs.
Smart Images

Figure CN115501596B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of Internet technologies, and in particular, to a pathfinding method in a game, a pathfinding device in a game, an electronic device, and a computer-readable storage medium. Background Art
[0002] With the continuous development of Internet technologies, games have become entertainment activities for more and more people. In a game, a player or a system can control a virtual object. Among them, the pathfinding virtual object controlled by the player or the virtual object controlled by the system can automatically move from one location to another in the game scene, realizing automatic pathfinding in the game.
[0003] In an actual game, the automatic pathfinding behavior of a character in the game is an important function affecting the game performance. With the enrichment of game functions, in some game scenes, it is necessary for the pathfinding virtual object to perform two-dimensional pathfinding (2D pathfinding) close to the terrain surface in the game scene and to perform three-dimensional pathfinding (3D pathfinding) in the entire three-dimensional game scene. Therefore, how to support the pathfinding virtual object to achieve two-dimensional pathfinding and three-dimensional pathfinding in the game scene simultaneously is a problem that needs to be solved urgently by those skilled in the art. Summary of the Invention
[0004] Embodiments of the present invention provide a pathfinding method, device, electronic device, and computer-readable storage medium in a game to solve the problem that it is impossible to support the pathfinding virtual object to achieve two-dimensional pathfinding and three-dimensional pathfinding in the game scene simultaneously.
[0005] Embodiments of the present invention disclose a pathfinding method in a game. The game includes a game scene and a pathfinding virtual object. The method includes:
[0006] In response to a pathfinding instruction, determining a starting location and a target location of the pathfinding virtual object in the game scene, and a target pathfinding mode of the pathfinding virtual object in the game scene;
[0007] Loading a target pathfinding map corresponding to the target pathfinding mode in the game scene;
[0008] Generating a pathfinding path according to the starting location, the target location, and the target pathfinding map;
[0009] Controlling the pathfinding virtual object to move in the game scene based on the pathfinding path.
[0010] Optionally, the method further includes:
[0011] Voxelizing the game scene to obtain a plurality of first voxel grids; the first voxel grids have corresponding height information;
[0012] Calculate the height difference between the first voxel grids according to the height information of the first voxel grids;
[0013] Determine the surface of the scene model corresponding to the adjacent first voxel grids whose height difference is within a preset height threshold as the walkable area;
[0014] Divide the walkable area to obtain a number of polygon areas;
[0015] Save the polygon areas as the 2D pathfinding map of the game scene.
[0016] Optionally, the area of the walkable area is greater than or equal to a first preset area and less than a second preset area, and the second preset area is greater than the first preset area.
[0017] Optionally, the walkable area is surrounded by an original boundary, and the original boundary includes original vertices. Before dividing the walkable area to obtain a number of polygon areas, the method further includes:
[0018] Determine the area connection vertices in the walkable area; the area connection vertices are the vertices connecting adjacent walkable areas;
[0019] Connect adjacent area connection vertices to obtain a simplified boundary;
[0020] Determine the original vertex in the original boundary that is farthest from the simplified boundary as the target original vertex;
[0021] When the distance between the target original vertex and the simplified boundary is greater than a preset distance threshold, add the target original vertex to the simplified boundary, and return to execute determining the original vertex in the original boundary that is farthest from the simplified boundary as the target original vertex;
[0022] When the distance between the target original vertex and the simplified boundary is less than or equal to the preset distance threshold, determine the simplified boundary as the target simplified boundary;
[0023] Update the walkable area to the area surrounded by the target simplified boundary.
[0024] Optionally, dividing the walkable area to obtain a number of polygon areas includes:
[0025] Divide the walkable area into a number of triangular areas;
[0026] Combine the triangular regions into a polygonal region; wherein, the shape of the polygonal region is a convex polygon.
[0027] Optionally, the method further includes:
[0028] Voxelize the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer;
[0029] Mark the second voxel grids containing the scene model, wherein the marked second voxel grids are used to represent that the pathfinding virtual object cannot pass through;
[0030] Determine the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids; the parent-child connection relationship is used to represent the connection relationship between the second voxel grids of different layers, and the neighbor connection relationship is used to represent the connection relationship between the second voxel grids of the same layer;
[0031] Save the second voxel grids, the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids as the three-dimensional pathfinding map of the game scene.
[0032] Optionally, the game scene includes a scene model, and the voxelizing the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer includes:
[0033] Voxelize the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer;
[0034] When the second voxel grid includes the scene model, voxelize the second voxel grid including the scene model until the volume of the second voxel grid is less than or equal to the preset voxel grid volume.
[0035] Optionally, the generating a pathfinding path according to the starting point, the target point and the target pathfinding map includes:
[0036] When the target pathfinding map is a two-dimensional pathfinding map, find the connected polygonal region between the starting point and the target point in the two-dimensional pathfinding map;
[0037] Generate a two-dimensional pathfinding path according to the starting point, the two-dimensional waypoints in the connected polygonal region and the target point; wherein, the two-dimensional waypoints are the position coordinate points in the polygonal region calculated according to the starting point and the target point by using a specified path search algorithm, and a straight line is allowed to pass between adjacent two-dimensional waypoints.
[0038] Optionally, generating a pathfinding path according to the starting location, the target location, and the target pathfinding map includes:
[0039] When the target pathfinding map is a three-dimensional pathfinding map, find the connected second voxel grids between the starting location and the target location in the three-dimensional pathfinding map;
[0040] Generate a three-dimensional pathfinding path according to the starting location, the three-dimensional waypoints, and the target location, where the three-dimensional waypoints are the central points of the intersecting surfaces of adjacent connected second voxel grids.
[0041] Optionally, before controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, the method further includes:
[0042] Determine that the pathfinding path is a valid path.
[0043] Optionally, before controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, it further includes:
[0044] When it is determined that the pathfinding path is an invalid path, use the location where the pathfinding virtual object is currently located as the starting location, and re-execute generating a pathfinding path according to the starting location, the target location, and the target pathfinding map.
[0045] Optionally, the method further includes:
[0046] If the pathfinding virtual object is not in the pathfinding walking state, or the time since the last generation of the pathfinding path exceeds a preset time interval, or the number of three-dimensional waypoints in the pathfinding path is zero when the target pathfinding method is the three-dimensional pathfinding method, or the number of three-dimensional waypoints in the pathfinding path is not zero when the target pathfinding method is the three-dimensional pathfinding method, and the number of three-dimensional waypoints that the virtual pathfinding object has not reached is less than a preset waypoint threshold and the three-dimensional waypoints that have not been reached do not include the target location, then determine that the pathfinding path is an invalid path.
[0047] Optionally, the method further includes:
[0048] When the target pathfinding method is the two-dimensional pathfinding method, if the starting location or the target location in the pathfinding path is not in the polygon area of the two-dimensional pathfinding map, or when the target pathfinding method is the two-dimensional pathfinding method, the number of polygon areas in the pathfinding path is less than a preset quantity threshold, and the target location is not in the last polygon area of the pathfinding path, then determine that the pathfinding path is an invalid path.
[0049] Optionally, controlling the pathfinding virtual object to move in the game scene based on the pathfinding path includes:
[0050] Determine the current location of the pathfinding virtual object in the game scene;
[0051] Determine the next waypoint after the current location in the pathfinding path;
[0052] Calculate the movement speed and movement direction of the pathfinding virtual object based on the current location and the next waypoint;
[0053] Control the pathfinding virtual object to move from the current location to the next waypoint in the game scene according to the movement speed and the movement direction.
[0054] Optionally, the controlling the pathfinding virtual object to move in the game scene based on the pathfinding path further includes:
[0055] When the pathfinding virtual object moves to the next waypoint, if the distance between the next waypoint and the target location is less than a preset path threshold, the pathfinding virtual object ends the pathfinding walking state.
[0056] An embodiment of the present invention further discloses a pathfinding device in a game. The game includes a game scene and a pathfinding virtual object. The device includes:
[0057] A pathfinding response module, configured to respond to a pathfinding instruction, determine the starting location and the target location of the pathfinding virtual object in the game scene, and the target pathfinding method of the pathfinding virtual object in the game scene;
[0058] A pathfinding map loading module, configured to load a target pathfinding map corresponding to the target pathfinding method in the game scene;
[0059] A pathfinding path generation module, configured to generate a pathfinding path according to the starting location, the target location, and the target pathfinding map;
[0060] A virtual object movement module, configured to control the pathfinding virtual object to move in the game scene based on the pathfinding path.
[0061] Optionally, the device further includes: a two-dimensional pathfinding map generation module, configured to:
[0062] Voxelize the game scene to obtain a number of first voxel grids; the first voxel grids have corresponding height information;
[0063] Calculate the height difference between the first voxel grids according to the height information of the first voxel grids;
[0064] Determine the surface of the scene model corresponding to the adjacent first voxel grids with the height difference within the preset height threshold in the game scene as the walkable area;
[0065] Divide the walkable area to obtain several polygon areas;
[0066] Save the polygon area as the 2D pathfinding map of the game scene.
[0067] Optionally, the area of the walkable area is greater than or equal to the first preset area and less than the second preset area, and the second preset area is greater than the first preset area.
[0068] In an exemplary embodiment, the 2D pathfinding map generation module is configured to:
[0069] Determine the area connection vertices in the walkable area; the area connection vertices are the vertices connecting adjacent walkable areas;
[0070] Connect adjacent area connection vertices to obtain a simplified boundary;
[0071] Determine the original vertex farthest from the simplified boundary in the original boundary as the target original vertex;
[0072] When the distance between the target original vertex and the simplified boundary is greater than the preset distance threshold, add the target original vertex to the simplified boundary, and return to execute determining the original vertex farthest from the simplified boundary in the original boundary as the target original vertex;
[0073] When the distance between the target original vertex and the simplified boundary is less than or equal to the preset distance threshold, determine the simplified boundary as the target simplified boundary;
[0074] Update the walkable area to the area surrounded by the target simplified boundary.
[0075] Optionally, the 2D pathfinding map generation module is configured to:
[0076] Divide the walkable area into several triangular areas;
[0077] Combine the triangular areas into polygon areas; wherein, the shape of the polygon area is a convex polygon.
[0078] Optionally, the device further includes: a 3D pathfinding map generation module, configured to:
[0079] Voxelize the game scene according to different layers to obtain several second voxel grids corresponding to each layer;
[0080] Mark the second voxel grid containing the scene model, where the marked second voxel grid is used to represent that the pathfinding virtual object cannot pass through;
[0081] Determine the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids; the parent-child connection relationship is used to represent the connection relationship between the second voxel grids at different layers, and the neighbor connection relationship is used to represent the connection relationship between the second voxel grids at the same layer;
[0082] Save the second voxel grid, the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids as the three-dimensional pathfinding map of the game scene.
[0083] Optionally, the game scene includes a scene model, and the three-dimensional pathfinding map generation module is used for:
[0084] Voxelize the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer;
[0085] When the second voxel grid includes the scene model, voxelize the second voxel grid including the scene model until the volume of the second voxel grid is less than or equal to the preset voxel grid volume.
[0086] Optionally, the pathfinding path generation module is used for:
[0087] When the target pathfinding map is a two-dimensional pathfinding map, find the connected polygon area between the starting point and the target point in the two-dimensional pathfinding map;
[0088] Generate a two-dimensional pathfinding path according to the starting point, the two-dimensional waypoints in the connected polygon area and the target point; wherein, the two-dimensional waypoints are position coordinate points in the polygon area calculated according to the starting point and the target point by using a specified path search algorithm, and a straight line is allowed to pass between adjacent two-dimensional waypoints.
[0089] Optionally, the pathfinding path generation module is used for:
[0090] When the target pathfinding map is a three-dimensional pathfinding map, find the connected second voxel grids between the starting point and the target point in the three-dimensional pathfinding map;
[0091] Generate a three-dimensional pathfinding path according to the starting point, the three-dimensional waypoints and the target point, where the three-dimensional waypoints are the central points of the intersection surfaces of adjacent connected second voxel grids.
[0092] Optionally, the device further includes: a pathfinding validity determination module, configured to:
[0093] Determine that the pathfinding path is a valid path.
[0094] Optionally, the device further includes: a re - execution module, configured to:
[0095] When it is determined that the pathfinding path is an invalid path, use the location where the pathfinding virtual object is currently located as the starting location, and re - execute generating the pathfinding path according to the starting location, the target location, and the target pathfinding map.
[0096] Optionally, the pathfinding validity determination module is configured to:
[0097] If the pathfinding virtual object is not in the pathfinding walking state, or the time since the last generation of the pathfinding path exceeds a preset time interval, or when the target pathfinding method is the three - dimensional pathfinding method and the number of three - dimensional waypoints in the pathfinding path is zero, or when the target pathfinding method is the three - dimensional pathfinding method, the number of three - dimensional waypoints in the pathfinding path is not zero, and the number of three - dimensional waypoints that the virtual pathfinding object has not reached is less than a preset waypoint threshold and the non - reached three - dimensional waypoints do not include the target location, then determine that the pathfinding path is an invalid path.
[0098] Optionally, the pathfinding validity determination module is configured to:
[0099] When the target pathfinding method is the two - dimensional pathfinding method, if the starting location or the target location in the pathfinding path is not in the polygon area of the two - dimensional pathfinding map, or when the target pathfinding method is the two - dimensional pathfinding method, the number of polygon areas in the pathfinding path is less than a preset quantity threshold, and the target location is not in the last polygon area of the pathfinding path, then determine that the pathfinding path is an invalid path.
[0100] Optionally, the virtual object movement module is configured to:
[0101] Determine the current location of the pathfinding virtual object in the game scene;
[0102] Determine the next waypoint after the current location in the pathfinding path;
[0103] Calculate the movement speed and movement direction of the pathfinding virtual object according to the current location and the next waypoint;
[0104] Control the pathfinding virtual object to move from the current location to the next waypoint in the game scene according to the movement speed and the movement direction.
[0105] Optionally, the virtual object movement module is configured to:
[0106] After the pathfinding virtual object moves to the next waypoint, if the distance between the next waypoint and the target location is less than a preset path threshold, the pathfinding virtual object ends the pathfinding walking state.
[0107] An embodiment of the present invention also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete communication with each other through the communication bus;
[0108] The memory is used to store a computer program;
[0109] When the processor is used to execute the program stored in the memory, the method described in the embodiment of the present invention is implemented.
[0110] An embodiment of the present invention also discloses a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the embodiment of the present invention.
[0111] An embodiment of the present invention also discloses a computer-readable storage medium, on which instructions are stored. When executed by one or more processors, the processors are caused to execute the method described in the embodiment of the present invention.
[0112] The embodiments of the present invention include the following advantages:
[0113] In the embodiment of the present invention, in response to a pathfinding instruction, the starting location and the target location of the pathfinding virtual object in the game scene are determined, as well as the target pathfinding method of the pathfinding virtual object in the game scene. The target pathfinding map corresponding to the target pathfinding method is loaded in the game scene, so that a pathfinding path can be generated according to the starting location, the target location, and the target pathfinding map, and the pathfinding virtual object is controlled to move in the game scene based on the pathfinding path, realizing automatic pathfinding in the game. The embodiments of the present invention can simultaneously support the pathfinding virtual object to implement multiple pathfinding methods in the game scene, such as two-dimensional pathfinding methods and three-dimensional pathfinding methods, and can support diversified pathfinding requirements in the game, bringing more gaming experiences to players. In addition, since players can control the pathfinding virtual object in the game to select the corresponding target pathfinding method according to their own needs in the game scene and switch between multiple pathfinding methods at any time, the performance and operability of the game are improved. Description of the Drawings
[0114] Figure 1 It is a flowchart of the steps of a pathfinding method in a game provided in the embodiment of the present invention;
[0115] Figure 2It is a schematic diagram of a walkable area provided in an embodiment of the present invention;
[0116] Figure 3 It is a schematic diagram of the area outline of an updated walkable area provided in an embodiment of the present invention;
[0117] Figure 4 It is a schematic diagram of a pathfinding grid of a two-dimensional pathfinding map provided in an embodiment of the present invention;
[0118] Figure 5 It is a schematic diagram of the process for generating a two-dimensional pathfinding map provided in an embodiment of the present invention;
[0119] Figure 6 It is a schematic diagram of the hierarchical SVO voxelization of a game scene provided in an embodiment of the present invention;
[0120] Figure 7 It is a schematic diagram of the parent-child connection relationship between second voxel grids provided in an embodiment of the present invention;
[0121] Figure 8 It is a schematic diagram of the neighbor connection relationship between second voxel grids provided in an embodiment of the present invention;
[0122] Figure 9 It is a schematic diagram of the process for generating a three-dimensional pathfinding map provided in an embodiment of the present invention;
[0123] Figure 10 It is a schematic diagram of the initialization process for pathfinding during a game process provided in an embodiment of the present invention;
[0124] Figure 11 It is a schematic diagram of a two-dimensional pathfinding path provided in an embodiment of the present invention;
[0125] Figure 12 It is a schematic diagram of a three-dimensional pathfinding path provided in an embodiment of the present invention;
[0126] Figure 13 It is a schematic diagram of the working process of a pathfinding frame provided in an embodiment of the present invention;
[0127] Figure 14 It is a schematic diagram of the process for planning a path provided in an embodiment of the present invention;
[0128] Figure 15 It is a schematic diagram of the process for determining the pathfinding effectiveness of the pathfinding path;
[0129] Figure 16 It is a schematic diagram of the process for calculating the moving speed and moving mode of a virtual pathfinding object provided in an embodiment of the present invention;
[0130] Figure 17 It is a structural block diagram of a pathfinding device in a game provided in an embodiment of the present invention;
[0131] Figure 18 It is a schematic hardware structure diagram of an electronic device for implementing various embodiments of the present invention. Detailed implementation manners
[0132] To make the above objects, features, and advantages of the present invention more obvious and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific implementation manners.
[0133] Currently, the pathfinding methods in games include the following several types:
[0134] Waypoint graph pathfinding: Relying on manual or automated methods, a number of waypoints are arranged in the game scene, and then, pathfinding is carried out depending on the connections between the waypoints.
[0135] Regularized grid pathfinding: The game scene is divided into grids of the same size, the grids with obstacles and the grids without obstacles are respectively marked, and then, the connected grids are searched for in the grids without obstacles to carry out pathfinding.
[0136] Detour pathfinding: Detour pathfinding is based on a planar pathfinding grid. A pathfinding polygon grid is generated on the surface of the game scene and the connectivity between the grids is marked. A pathfinding path is generated by searching for connected polygon grids, and then, pathfinding is carried out according to the pathfinding path.
[0137] However, although the current pathfinding methods in games can achieve pathfinding in games, they all have some disadvantages. Specifically:
[0138] Waypoint graph pathfinding: It can support both 2D pathfinding and 3D pathfinding. However, if the range of the game scene is large, if a better pathfinding accuracy is desired, a large number of waypoints need to be arranged in the game scene, and the labor cost is high.
[0139] Regularized grid: It can support both 2D pathfinding and 3D pathfinding. However, if a relatively high pathfinding accuracy is desired, the granularity of the grid needs to be divided fine enough. However, if the number of grids in the game scene is too large, the memory overhead for finding connected grids is relatively large. In addition, the memory required to store the grid data is also large.
[0140] Detour pathfinding: Generally applied to 2D pathfinding, but if the scene is stratified according to height, a pathfinding grid can be generated for each layer to perform 3D pathfinding. However, the pathfinding accuracy of 3D pathfinding based on stratified grids also depends on the stratification accuracy, and the pathfinding virtual object can only perform pathfinding near the pathfinding grid, and the pathfinding effect is not good.
[0141] As can be seen from the above, the current pathfinding methods in games can achieve 2D pathfinding and 3D pathfinding. However, if the waypoint graph pathfinding or regularized grid pathfinding is used, it requires a relatively high labor cost or a large memory overhead. If Detour pathfinding is used, although 2D pathfinding can be achieved, but if 3D pathfinding also needs to be achieved, the pathfinding effect is not good. It can be seen that the technical problem to be solved by the embodiments of the present invention is to provide a fused pathfinding method, so that the pathfinding virtual object can perform 2D pathfinding on the surface of the scene model in the game scene, and can also perform 3D pathfinding in the 3D space of the entire game scene.
[0142] In view of the above technical problems, a pathfinding method in a game provided by an embodiment of the present invention can support diverse pathfinding requirements in the game, that is, it can achieve both 2D pathfinding and 3D pathfinding. Moreover, the pathfinding virtual object in the game can perform 2D pathfinding or 3D pathfinding in the game scene according to its own needs, and can switch between these two pathfinding methods at any time, improving the performance and operability of the game. And, in view of the problem that the memory overhead for implementing 3D pathfinding is relatively large, the embodiment of the present invention proposes to perform fine-grained partitioning only on the area of the game scene that only includes the scene model, and perform coarse-grained partitioning on the area without the scene model. In this way, the pathfinding grid in the generated pathfinding map has a smaller memory overhead compared to the pathfinding method that requires pathfinding grid partitioning for the entire game scene. Specifically, the reduced memory overhead can include the memory overhead when calculating the pathfinding path and the memory overhead when storing the pathfinding grid.
[0143] The pathfinding method in a game in one embodiment of the present invention can run on a local terminal device or a server. When the pathfinding method in the game runs on the server, the pathfinding method in the game can be implemented and executed based on a cloud interaction system, where the cloud interaction system includes a server and a client device.
[0144] In an optional implementation, various cloud applications can be run under the cloud interaction system, such as cloud games. Taking cloud games as an example, cloud games refer to a game mode based on cloud computing. In the operation mode of cloud games, the operating body of the game program and the main body of the game screen presentation are separated. The storage and operation of the path-finding method in the game are completed on the cloud game server. The role of the client device is used for receiving and sending data and presenting the game screen. For example, the client device can be a display device with data transmission function close to the user side, such as a first terminal device, a TV, a computer, a handheld computer, etc.; but the path-finding method in the game is performed by the cloud game server in the cloud. When playing the game, the player operates the client device to send an operation instruction to the cloud game server. The cloud game server runs the game according to the operation instruction, encodes and compresses the game screen and other data, and returns it to the client device through the network. Finally, the client device decodes and outputs the game screen.
[0145] In an optional embodiment, taking a game as an example, a local terminal device stores a game program and is used to present a game screen. The local terminal device is used to interact with the player through a graphical user interface, that is, the game program is downloaded and installed by an electronic device and run conventionally. The local terminal device may provide the graphical user interface to the player in a variety of ways, for example, it may be rendered and displayed on a display screen of the terminal, or provided to the player through a holographic projection. For example, the local terminal device may include a display screen and a processor, the display screen is used to present a graphical user interface, the graphical user interface includes a game screen, and the processor is used to run the game, generate a graphical user interface, and control the display of the graphical user interface on the display screen.
[0146] Reference Figure 1 , shows a flowchart of a path-finding method in a game provided in an embodiment of the present invention, wherein the game includes a game scene and a path-finding virtual object, and specifically may include the following steps:
[0147] Step 101, in response to a path-finding instruction, determining a starting location and a target location of the path-finding virtual object in the game scene, and a target path-finding method of the path-finding virtual object in the game scene.
[0148] In a specific implementation, the pathfinding method in the game provided by the embodiments of the present invention can be applied to both the game client (terminal device side) and the game server (server side). Among them, when applied to the game client, a graphical user interface can be provided for players. Specifically, when the game application is running on the terminal device, the graphical user interface can be rendered on the touch display of the terminal device. The content displayed on the graphical user interface at least partially includes a partial or entire game scene. The specific form of the game scene can be square or other shapes, such as circular, etc.
[0149] Specifically, the game scene includes at least one virtual object. The virtual object can be a game character that the player controls through the terminal device, or a non-player character (NPC) pre-set by the game developer in a specific game scene. It can be presented through the graphical user interface. The presented content can include the entire virtual object or a part of the virtual object. For example, in a third-person perspective game, the content presented on the graphical user interface can include the entire virtual object, or in a first-person perspective game, the content presented on the graphical user interface can include a part or partial of the virtual object or not be presented.
[0150] In the embodiments of the present invention, the pathfinding virtual object refers to the virtual object in the game that is given the automatic pathfinding function. The game scene can be a three-dimensional map containing various scene models. For example, a three-dimensional map containing scene models such as castles, railings, stairs, walls, trees, flying vehicles, and oceans. Among the scene models in the game scene, some will restrict the movement of the pathfinding virtual object. For example, the pathfinding virtual object cannot cross scene models such as castles and railings and can only bypass them, or needs to use skills or items to cross.
[0151] Among them, multiple pathfinding methods are set for the pathfinding virtual object in the game scene. The pathfinding methods can at least include a two-dimensional pathfinding method and a three-dimensional pathfinding method. Specifically, the two-dimensional pathfinding method refers to two-dimensional pathfinding on the terrain surface of the game scene, and the three-dimensional pathfinding method refers to three-dimensional pathfinding in the three-dimensional space of the entire game scene.
[0152] In an embodiment of the present invention, the current position of the pathfinding virtual object in the game scene can be used as the starting point. Then, the player can set the target point of the pathfinding virtual object through operations such as clicking in the graphical user interface provided by the terminal device. Further, the player can also select a pathfinding method from multiple pathfinding methods, such as a two-dimensional pathfinding method, as the target pathfinding method of the pathfinding virtual object in the game scene. In response to the above pathfinding instruction, the terminal device can determine the starting point and the target point of the pathfinding virtual object in the game scene, as well as the target pathfinding method of the pathfinding virtual object in the game scene.
[0153] Step 102: Load the target pathfinding map corresponding to the target pathfinding method in the game scene.
[0154] Step 103: Generate a pathfinding path according to the starting point, the target point, and the target pathfinding map.
[0155] In an embodiment of the present invention, a corresponding pathfinding map is set for each pathfinding method. For example, a two-dimensional pathfinding map corresponding to the two-dimensional pathfinding method, and a three-dimensional pathfinding map corresponding to the three-dimensional pathfinding method. After determining the target pathfinding method of the pathfinding virtual object in the game scene, the target pathfinding map corresponding to the target pathfinding method can be loaded in the game scene, so that the pathfinding virtual object can perform pathfinding in the game scene according to the target pathfinding map.
[0156] Specifically, the pathfinding map includes multiple pathfinding grids. The entire game scene can be represented by these pathfinding grids. Therefore, a pathfinding path of the pathfinding virtual object in the game scene can be generated according to the pathfinding grids connected between the starting point and the target point. Among them, if the pathfinding map is a two-dimensional pathfinding map, the pathfinding grid can be a two-dimensional plane grid, which can cover the terrain surface in the game scene. If the pathfinding map is a three-dimensional pathfinding map, the pathfinding grid can be a three-dimensional solid grid (cube grid), which can cover the entire three-dimensional space of the game scene.
[0157] Step 104: Control the pathfinding virtual object to move in the game scene based on the pathfinding path.
[0158] In an embodiment of the present invention, after generating the pathfinding path of the pathfinding virtual object in the game scene, the pathfinding virtual object can be controlled to move in the game scene based on the pathfinding path, realizing automatic pathfinding in the game scene.
[0159] In the pathfinding method in the above game, in response to a pathfinding instruction, determine the starting location and target location of the pathfinding virtual object in the game scene, as well as the target pathfinding method of the pathfinding virtual object in the game scene. Load the target pathfinding map corresponding to the target pathfinding method in the game scene, so that a pathfinding path can be generated based on the starting location, target location, and target pathfinding map, and control the pathfinding virtual object to move in the game scene based on the pathfinding path, realizing automatic pathfinding in the game. The embodiments of the present invention can support multiple pathfinding methods for the pathfinding virtual object in the game scene at the same time, such as two-dimensional pathfinding methods and three-dimensional pathfinding methods, and can support diverse pathfinding requirements in the game, bringing more gaming experiences to players. In addition, since players can control the pathfinding virtual object in the game to select the corresponding target pathfinding method according to their own needs in the game scene and switch between multiple pathfinding methods at any time, the performance and operability of the game are improved.
[0160] Based on the above embodiments, variant embodiments of the above embodiments are proposed. Here, it should be noted that for the sake of brevity of description, only the differences from the above embodiments are described in the variant embodiments.
[0161] Before the pathfinding virtual object performs pathfinding based on the pathfinding map, the pathfinding map needs to be prepared first. Among them, the pathfinding map may include a two-dimensional pathfinding map for two-dimensional pathfinding. Specifically, the process of generating the two-dimensional pathfinding map is as follows:
[0162] In an exemplary embodiment, before the step 101, in response to a pathfinding instruction, determine the starting location and target location of the pathfinding virtual object in the game scene, and the target pathfinding method of the pathfinding virtual object in the game scene, the method may further include the following steps:
[0163] Voxelize the game scene to obtain a number of first voxel grids; the first voxel grids have corresponding height information;
[0164] According to the height information of the first voxel grids, calculate the height difference between the first voxel grids;
[0165] Determine the surface of the scene model corresponding to the adjacent first voxel grids with the height difference within a preset height threshold in the game scene as the walkable area;
[0166] Divide the walkable area to obtain a number of polygon areas;
[0167] Save the polygon areas as the two-dimensional pathfinding map of the game scene.
[0168] Specifically, a voxel (voxel grid) is short for a volume element. Essentially, a voxel is the 3D version of a pixel. Each voxel has a position and associated attributes in three-dimensional space. Voxelization is the process of cutting an object (such as a scene model in a game scene) into a number of voxel grids.
[0169] In an embodiment of the present invention, for a two-dimensional pathfinding map, scene model data of a game scene can be obtained. Based on this scene model data, the game scene is voxelized, and the game scene is divided into multiple first voxel grids. Among them, each first voxel grid has its corresponding height information. In the game, usually, a pathfinding virtual object is set to be unable to pass through a scene model with a height greater than a preset height threshold. Therefore, the height difference between the first voxel grids can be calculated according to the height information of the first voxel grids. Then, for adjacent first voxel grids with a height difference within the preset height threshold, the surface of the corresponding scene model in the game scene can be determined as a walkable area, where the pathfinding virtual object can move within the walkable area. For example, assume that the scene model in the first voxel grid is a flight of stairs in a staircase, and the height difference between the flights of stairs is within the preset height threshold. Then, based on these voxel grids, the surface of the staircase corresponding to the game scene can be determined as a walkable area. Among them, the size of the voxel grid is customized according to the pathfinding accuracy.
[0170] After determining multiple walkable areas in the game scene, each walkable area can be further divided to obtain several polygon areas. Subsequently, these polygon areas can be saved as the two-dimensional pathfinding map of the game scene. Among them, the polygon area can be a convex polygon area. Exemplarily, referring to Figure 2 , which is a schematic diagram of a walkable area provided in an embodiment of the present invention. An area with the same gray level in this figure represents a walkable area.
[0171] In an exemplary embodiment, the walkable area is surrounded by an original boundary, and the original boundary includes original vertices. Before dividing the walkable area to obtain several polygon areas, the method may further include the following steps:
[0172] Determine the area connection vertices in the walkable area; the area connection vertices are the vertices that connect adjacent walkable areas;
[0173] Connect adjacent area connection vertices to obtain a simplified boundary;
[0174] Determine the target original vertex, which is the original vertex with the farthest distance between the original boundary and the simplified boundary;
[0175] When the distance between the target original vertex and the simplified boundary is greater than a preset distance threshold, add the target original vertex to the simplified boundary, and return to execute the original vertex with the farthest distance from the simplified boundary among the original boundaries, and determine it as the target original vertex;
[0176] When the distance between the target original vertex and the simplified boundary is less than or equal to the preset distance threshold, determine the simplified boundary as the target simplified boundary;
[0177] Update the walkable area to the area enclosed by the target simplified boundary.
[0178] In a specific implementation, the walkable area is enclosed by the original boundary, and the original boundary is formed based on the boundary of the voxel grid. Therefore, the original boundary of the walkable area is an irregular zigzag line. If polygon areas are divided based on this walkable area, it will consume a large amount of memory overhead. Therefore, before dividing the walkable area into polygon areas, the original boundary of the walkable area can be simplified first to regularize the simplified original boundary.
[0179] Among them, the region connection vertex refers to the vertex connecting the walkable area and other walkable areas. Specifically, for the walkable area, first find the region connection vertices of this walkable area, and connect the adjacent region connection vertices to obtain a simplified boundary. Specifically, the adjacent region connection vertices are the region connection vertices of this walkable area and the region connection vertices of the other walkable area closest to it. Then, calculate the original vertex on the original boundary that is farthest from the simplified boundary. If the distance between this original vertex and the simplified boundary is greater than the set preset distance threshold, add this original vertex to the simplified boundary and regenerate a simplified boundary. Repeat these steps until there is no original vertex on the original boundary whose distance from the simplified boundary is greater than the set preset distance threshold. At this time, the walkable area can be updated to the area composed of the simplified boundary. Exemplarily, for the region contour of the updated walkable area, reference can be made to Figure 3 as shown.
[0180] In an exemplary embodiment, the step of dividing the walkable area to obtain a plurality of polygon areas may include the following steps:
[0181] Divide the walkable area into a plurality of triangular areas;
[0182] Combine the triangular areas into polygon areas; among them, the shape of the polygon area is a convex polygon.
[0183] In an embodiment of the present invention, the updated walkable area can be divided into a number of triangular regions according to a preset triangle partitioning algorithm. Then, these triangular regions can be combined into a polygon region in the shape of a convex polygon, and these polygon regions are used as pathfinding grids in the two-dimensional pathfinding map. Exemplarily, the pathfinding grids of the two-dimensional pathfinding map can refer to Figure 4 as shown. Optionally, the preset triangle partitioning algorithm can be an algorithm defined by a developer, such as other algorithms like the internal angle algorithm and the intersecting edge algorithm, and the embodiments of the present invention do not need to limit this.
[0184] In a specific implementation, the walkable area is formed by combining the first voxel grids with a height difference within a preset height threshold. It can be understood that if the walkable area is larger, the memory overhead required to divide the walkable area into a number of triangular regions will be greater. Therefore, when generating the walkable area, the area size of the walkable area can be controlled. Specifically, the area size of the walkable area can be set to be greater than or equal to a first preset area and less than a second preset area, where the second preset area is greater than the first preset area. In this way, it is possible to avoid excessive memory overhead due to the overly large area of the walkable area, and it is also possible to avoid excessive memory overhead caused by an overly small area of the walkable area, resulting in an overly large number of walkable areas that need to be divided into triangular regions.
[0185] Optionally, after generating the polygon region, it is also possible to re-partition the polygon region based on the height information corresponding to the polygon region, so that the accuracy of the pathfinding grids in the two-dimensional pathfinding map is higher, and thus the pathfinding virtual object can perform high-precision pathfinding based on the two-dimensional pathfinding map.
[0186] To enable those skilled in the art to better understand the process of generating a two-dimensional pathfinding map, the following uses an example for illustration. Specifically, referring to Figure 5 , which is a schematic flowchart of the generation of a two-dimensional pathfinding map provided by an embodiment of the present invention. Each step on the right side of the figure has a corresponding number, and the specific step process includes:
[0187] S501. Import the scene model of the game scene.
[0188] S502. Voxelize the game scene and divide it into discrete cube small grids (first voxel grids), where the size of the first voxel grids can be customized according to the pathfinding accuracy.
[0189] S503. Filter out the walkable surfaces of the pathfinding virtual object in the game scene according to the voxel grids.
[0190] S504. Divide the walkable area according to the walkable surfaces, and this walkable area is used to generate subsequent convex polygon regions.
[0191] S505. Simplify the original boundary of the walkable area to generate a simplified boundary (area contour). Among them, the walkable area can be updated based on the simplified boundary.
[0192] S506. Continue to divide the updated walkable area into several convex polygon areas. Among them, during the pathfinding process, the pathfinding virtual object generates a pathfinding path by querying the connected convex polygon areas between the starting point and the target point.
[0193] S507. The convex polygon area can also be further divided by adding height information to improve the convex polygon area.
[0194] S508. Write the convex polygon area as a pathfinding grid into a file according to the format to obtain the export of the 2D pathfinding map.
[0195] Through the above method, a 2D pathfinding map for 2D pathfinding in the game scene can be generated. Among them, the pathfinding map can include a 3D pathfinding map for 3D pathfinding. Specifically, the process of generating the 3D pathfinding map is as follows:
[0196] In an exemplary embodiment, the method may further include the following steps:
[0197] Voxelize the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer;
[0198] Mark the second voxel grids containing the scene model, where the marked second voxel grids are used to represent that the pathfinding virtual object cannot pass through;
[0199] Determine the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids; the parent-child connection relationship is used to represent the connection relationship between the second voxel grids in different layers, and the neighbor connection relationship is used to represent the connection relationship between the second voxel grids in the same layer;
[0200] Save the second voxel grids, the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids as the 3D pathfinding map of the game scene.
[0201] In an embodiment of the present invention, for a three-dimensional pathfinding map, scene model data of a game scene can be obtained, and the game scene can be voxelized according to different layers based on the scene model data, and the game scene can be divided into second voxel grids corresponding to each layer. Then, the second voxel grids containing the scene model can be marked to indicate that the pathfinding virtual object cannot pass through the second voxel grids. That is to say, these marked second voxel grids need to be avoided when generating a pathfinding path. Among them, the number of layers of the game scene and the size of the second voxel grids can be customized according to the pathfinding accuracy.
[0202] Then, a parent-child connection relationship of the second voxel grids can be generated, where the parent-child connection relationship is used to represent the connection between the second voxel grids in the upper and lower layers, and the neighbor connection relationship is used to represent the connection between the second voxel grids in the same layer. Finally, the second voxel grids (including the marked second voxel grids), the parent-child connection relationship and / or the neighbor connection relationship between the second voxel grids can be saved as a three-dimensional pathfinding map of the game scene.
[0203] In an exemplary embodiment, the game scene includes a scene model. The voxelizing the game scene according to different layers to obtain a plurality of second voxel grids corresponding to each layer may include the following steps:
[0204] Voxelize the game scene according to different layers to obtain a plurality of second voxel grids corresponding to each layer;
[0205] When the second voxel grid includes the scene model, voxelize the second voxel grid including the scene model until the volume of the second voxel grid is less than or equal to a preset voxel grid volume.
[0206] Among them, when voxelizing the scene model in the game scene, SVO (Sparse Voxel Octree) is used to voxelize the scene model. Specifically, when using SVO to voxelize the scene model, if the voxelized second voxel grid contains the scene model, the second voxel grid is further voxelized using SVO to obtain a new second voxel grid until the volume of the second voxel grid is less than or equal to the preset voxel grid volume, that is, the size of the preset second voxel grid has been reached and no further voxelization is required.
[0207] In the embodiments of the present invention, to address the problem of relatively large memory overhead for implementing three-dimensional pathfinding, the embodiments of the present invention propose to perform fine-grained partitioning only on the areas in the game scene that include scene models, and perform coarse-grained partitioning on the areas without scene models. In this way, the pathfinding grids (second voxel grids) in the generated three-dimensional pathfinding map have a smaller memory overhead compared to the pathfinding method that requires partitioning the pathfinding grids for the entire game scene. The reduced memory overhead can include the memory overhead when calculating the pathfinding path and the memory overhead when storing the pathfinding grids.
[0208] Exemplarily, referring to Figure 6 , the game scene is divided into three layers, namely Layer0, Layer1, and Layer2. Figure 6 One grid in represents a second voxel grid, and the black second voxel grids represent the marked voxel grids. Among them, the voxelization granularity of the second voxel grids in different layers can be different. Referring to Figure 7 , it is a schematic diagram of the parent-child connection relationship between the second voxel grids. For example, some second voxel grids in Layer2 can be connected to the second voxel grids in Layer1. Referring to Figure 8 , it is a schematic diagram of the neighbor connection relationship between the second voxel grids. For example, the adjacent second voxel grids in Layer1 and Layer2 are connected, and one second voxel grid in Layer2 can be connected to two second voxel grids in Layer1.
[0209] To enable those skilled in the art to better understand the process of generating a two-dimensional pathfinding map, the following uses examples for illustration. Specifically, referring to Figure 9 , it is a schematic flowchart of generating a three-dimensional pathfinding map provided by the embodiments of the present invention. Each step on the right side of the figure has a corresponding number. The specific step process includes:
[0210] S901. Import the scene model data of the game scene.
[0211] S902. Voxelize the scene model, divide the second voxel grids of the game scene according to SVO. If there is a scene model in the second voxel grid, further voxelize the voxel according to SVO.
[0212] S903. Mark the voxel grids with scene models in the second voxel grids. These second voxel grids should be avoided during pathfinding.
[0213] S904. Generate the parent-child connection relationship of the second voxel grids, that is, mark the connection between the second voxel grids in the upper and lower layers.
[0214] S905. Generate the neighbor connection relationships of the second voxel grid, that is, mark the connections between adjacent second voxel grids in the same layer.
[0215] S906. Write the second voxel grid into a file as a pathfinding grid according to the format to obtain the export of the three-dimensional pathfinding map.
[0216] In the above manner, a three-dimensional pathfinding map for three-dimensional pathfinding in the game scene can be generated.
[0217] In the embodiment of the present invention, after obtaining the two-dimensional pathfinding map and the three-dimensional pathfinding map, when the pathfinding virtual object is pathfinding in the game scene, the two-dimensional pathfinding map can be loaded into the game scene for two-dimensional pathfinding, and / or the three-dimensional pathfinding map can be loaded into the game scene for three-dimensional pathfinding. Before the virtual pathfinding object starts pathfinding in the game scene, pathfinding initialization can be performed. Specifically, referring to Figure 10 , which is a schematic diagram of the initialization process of pathfinding in a game process provided by the embodiment of the present invention. Each step on the right side of the figure has a corresponding number. The specific step process includes:
[0218] S1001. The game process of the game client / server starts.
[0219] S1002. Load the two-dimensional pathfinding map in the game scene.
[0220] S1003. Construct a two-dimensional pathfinding grid in the game process according to the two-dimensional pathfinding map.
[0221] S1004. Determine whether three-dimensional pathfinding is required.
[0222] S1005. If three-dimensional pathfinding is required, load the three-dimensional pathfinding map in the game scene.
[0223] S1006. Construct a three-dimensional pathfinding grid in the game scene according to the three-dimensional pathfinding map.
[0224] S1007. The pathfinding initialization is completed.
[0225] It should be noted that in the embodiment of the present invention, when loading the two-dimensional pathfinding map or the three-dimensional pathfinding map in the game scene, it can be loaded according to the requirements of the game design. For example, if it is designed that the pathfinding virtual object can fly in the air in some game scenes, the three-dimensional pathfinding map can be loaded. Or if the pathfinding virtual object can only walk on the ground in some game scenes, the two-dimensional pathfinding map can be loaded. Or if the pathfinding virtual object can both fly in the air and walk on the ground in some game scenes, the two-dimensional pathfinding map and the three-dimensional pathfinding map can be loaded simultaneously. Or the corresponding pathfinding method can also be selected according to the player's own needs, and then the corresponding pathfinding map can be loaded. The embodiment of the present invention does not need to limit this.
[0226] In an exemplary embodiment, step 103, generating a pathfinding route according to the starting location, the target location, and the target pathfinding map, may include the following steps:
[0227] When the target pathfinding map is a two-dimensional pathfinding map, search for a connected polygon area between the starting location and the target location in the two-dimensional pathfinding map;
[0228] Generate a two-dimensional pathfinding route according to the starting location, the two-dimensional waypoints in the connected polygon area, and the target location; wherein, the two-dimensional waypoints are position coordinate points in the polygon area calculated according to the starting location and the target location by using a specified path search algorithm, and a straight line is allowed to pass between adjacent two-dimensional waypoints.
[0229] Among them, the connected polygon area refers to a polygon area that allows a virtual pathfinding object to pass through. For example, assume there are three polygon areas A, B, and C, where A is adjacent to B and C respectively. A and B are connected polygon areas, then the virtual pathfinding object can move from A to B, but cannot move from A to C.
[0230] In an embodiment of the present invention, when a pathfinding virtual object performs two-dimensional pathfinding, the target pathfinding map is a two-dimensional pathfinding map, and the two-dimensional pathfinding map includes polygon areas where the pathfinding virtual object can move. At this time, a two-dimensional pathfinding route can be generated according to the connected polygon area between the starting location and the target location. Subsequently, the pathfinding virtual object can move in the game scene according to the two-dimensional pathfinding route.
[0231] In an embodiment of the present invention, the A* algorithm can be used to calculate the two-dimensional pathfinding route. Of course, other path search algorithms such as depth-first search algorithm, breadth-first search algorithm, Dijkstra algorithm, and funnel algorithm can also be used, and the embodiments of the present invention are not limited thereto.
[0232] Among them, the two-dimensional waypoints refer to the position coordinate points in the game scene that need to be passed through when calculating the two-dimensional pathfinding route by using a specified path search algorithm, and a straight line can pass between adjacent two-dimensional waypoints. Specifically, referring to Figure 11 , is a schematic diagram of a two-dimensional pathfinding route in an embodiment of the present invention. The figure includes a starting point (starting location) and an ending point (target location), and points D and G therein are two-dimensional waypoints. Connecting the starting point, the waypoints (points D and G), and the ending point can obtain the two-dimensional pathfinding route, that is, Figure 11 the arrowed line segment in
[0233] In an exemplary embodiment, step 103, generating a pathfinding route according to the starting location, the target location, and the target pathfinding map, may include the following steps:
[0234] When the target pathfinding map is a three-dimensional pathfinding map, search for the connected second voxel grids between the starting location and the target location in the three-dimensional pathfinding map;
[0235] Generate a three-dimensional pathfinding route according to the starting location, the three-dimensional waypoints, and the target location, where the three-dimensional waypoints are the central points of the intersection surfaces of adjacent connected second voxel grids.
[0236] In an embodiment of the present invention, when a pathfinding virtual object performs three-dimensional pathfinding, the target pathfinding map is a three-dimensional pathfinding map, the three-dimensional pathfinding map includes second voxel grids, and the second voxel grids containing scene models are marked in the three-dimensional pathfinding map, and the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids are also recorded. Based on this recorded information, the connected second voxel grids between the starting location and the target location can be found in the three-dimensional pathfinding map, so as to generate a three-dimensional pathfinding route based on the connected second voxel grids. Subsequently, the pathfinding virtual object can move in the game scene according to the three-dimensional pathfinding route.
[0237] In an embodiment of the present invention, the A* algorithm can be used when calculating the three-dimensional pathfinding route. Of course, path search algorithms such as depth-first search algorithm, breadth-first search algorithm, Dijkstra algorithm, and funnel algorithm can also be used, and the embodiments of the present invention are not limited thereto.
[0238] Among them, the three-dimensional waypoints refer to the central points of the intersection surfaces of adjacent connected second voxel grids. Specifically, referring to Figure 12 , is a schematic diagram of a three-dimensional pathfinding route in an embodiment of the present invention. The figure includes Start (starting location) and End (target location). The connected second voxel grids that can connect the starting location and the target location are found in the three-dimensional pathfinding map. These connected second voxel grids can be a cube passage. The central points of the intersection surfaces of two adjacent second voxel grids in the cube passage are used as three-dimensional waypoints, and connecting the starting location, the three-dimensional waypoints, and the target location can obtain the three-dimensional pathfinding route, that is, Figure 12 the line segments in the cube passage in
[0239] In an exemplary embodiment, before controlling the pathfinding virtual object to move in the game scene based on the pathfinding route, the method may further include the following steps:
[0240] Determine that the pathfinding route is a valid route.
[0241] In an embodiment of the present invention, before controlling the pathfinding virtual object to move in the game scene based on the generated pathfinding path (including the two-dimensional pathfinding path and the three-dimensional pathfinding path), it is possible to first determine whether the pathfinding path is a valid path. When it is determined that the pathfinding path is a valid path, start controlling the pathfinding virtual object based on the generated pathfinding path, so as to avoid the virtual pathfinding object from performing wrong pathfinding in the game scene due to an invalid pathfinding path.
[0242] In an exemplary embodiment, before controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, the method may further include the following steps:
[0243] When it is determined that the pathfinding path is an invalid path, use the location where the pathfinding virtual object is currently located as the starting location, and re-execute the generation of the pathfinding path according to the starting location, the target location, and the target pathfinding map.
[0244] In a specific implementation, the entire pathfinding of the pathfinding virtual object in the game scene is a continuously polling process, that is, the pathfinding process may include multiple pathfinding processing cycles (the pathfinding processing cycle may also be referred to as a pathfinding frame). A pathfinding processing cycle represents a loop. At the end of a pathfinding processing cycle, it will immediately enter the next pathfinding processing cycle, repeating the same logic until the pathfinding virtual object ends pathfinding in the game scene. Among them, at the beginning of each pathfinding processing cycle, it is necessary to re-plan the path, that is, it is necessary to re-generate the pathfinding path.
[0245] In an embodiment of the present invention, it is possible to determine whether to enter the next pathfinding processing cycle by determining the pathfinding validity of the pathfinding path. Specifically, if it is determined that the pathfinding validity of the pathfinding virtual object is invalid, it is necessary to enter the next pathfinding processing cycle, that is, it is necessary to use the location where the pathfinding virtual object is currently located in the game scene as the starting location, and then re-generate the pathfinding path according to the starting location, the target location, and the target pathfinding map. If it is determined that the pathfinding validity of the pathfinding virtual object is valid, there is no need to enter the next pathfinding processing cycle, and continue to move in the game scene using the already calculated pathfinding path.
[0246] Specifically, referring to Figure 13 , is a schematic diagram of the working process of a pathfinding frame provided by an embodiment of the present invention. Each step on the right side of the figure has a corresponding number. The specific step process includes:
[0247] S1301. A new pathfinding frame starts.
[0248] S1302. Judgment of the validity of the pathfinding path.
[0249] S1303. If it is determined that the validity of the pathfinding path is invalid, the pathfinding path of the pathfinding virtual object that needs to re-plan the path shall be re-planned. Specifically, the content of path planning can refer to Figure 13 The steps shown. Among them, for two-dimensional pathfinding, the A* algorithm is used to find the connected convex polygon area (two-dimensional polygon path) in the convex polygon area of the two-dimensional pathfinding map. For three-dimensional pathfinding, the A* algorithm is used to find the connected second voxel grid (cube path) in the three-dimensional pathfinding map.
[0250] S1304. According to the path found in the previous step, use the funnel algorithm to calculate and generate waypoints. Among them, the waypoints of two-dimensional pathfinding can be calculated and generated by the funnel algorithm, and the waypoints of three-dimensional pathfinding are the central points of the intersection surfaces in the connected and adjacent second voxel grids.
[0251] S1305. Calculate the moving speed and moving direction of the pathfinding virtual object according to the current position coordinates of the pathfinding virtual object and the position coordinates of the next waypoint.
[0252] S1306. The pathfinding virtual object moves according to the calculated moving speed and moving direction.
[0253] S1307. After the pathfinding virtual object moves, some post-movement processing needs to be performed. Among them, if it is in the two-dimensional pathfinding state, after the pathfinding virtual object moves, the polygon area where the movement is completed shall be removed from the two-dimensional polygon path. After the movement is completed, calculate the distance between the current position coordinates and the target location. If the distance is less than the threshold, it is considered that the pathfinding is completed and the pathfinding state is stopped.
[0254] S1308. The current pathfinding frame ends, and preparations are made to start the next pathfinding frame.
[0255] Refer to Figure 14 , which is a schematic flowchart of a path planning provided by an embodiment of the present invention. There is a corresponding number on the right side of each step in the figure. The specific step process includes:
[0256] S1401. Path planning starts.
[0257] S1402. Whether the pathfinding virtual object needs to re-plan the path. If so, execute step S1403. If not, execute step S1406.
[0258] S1403. Whether the pathfinding virtual object is performing three-dimensional pathfinding. If so, execute step S1404. If not, execute step S1405.
[0259] S1404. Query the three-dimensional pathfinding path in the three-dimensional pathfinding map.
[0260] S1405. Query the two-dimensional pathfinding path in the two-dimensional pathfinding map.
[0261] S1406. The path planning is completed.
[0262] In an exemplary embodiment, determining the pathfinding effectiveness of the pathfinding path may include the following steps:
[0263] If the pathfinding virtual object is not in the pathfinding walking state, or the time since the last generation of the pathfinding path exceeds a preset time interval, the number of 3D waypoints in the pathfinding path is zero when the target pathfinding method is the 3D pathfinding method, or the number of 3D waypoints in the pathfinding path is not zero when the target pathfinding method is the 3D pathfinding method, and the number of 3D waypoints that the virtual pathfinding object has not reached is less than a preset waypoint threshold and the 3D waypoints that have not been reached do not include the target location, then determine that the pathfinding path is an invalid path.
[0264] When the target pathfinding method is the 2D pathfinding method, if the starting location or the target location in the pathfinding path is not in the polygon area of the 2D pathfinding map, or when the target pathfinding method is the 2D pathfinding method, the number of polygon areas in the pathfinding path is less than a preset quantity threshold, and the target location is not in the last polygon area of the pathfinding path, then determine that the pathfinding path is an invalid path.
[0265] In the embodiments of the present invention, the methods for determining whether the pathfinding path is an invalid path include but are not limited to the following: whether the starting location and the target location are not on the pathfinding grid; whether the currently walked pathfinding path still cannot reach the target location and the pathfinding path is too short; whether the time difference (targetReplanTime) between the time of the previous path planning and the current time is greater than a preset threshold, etc. If any one of the conditions is met, the path planning of the virtual pathfinding object needs to be redone. If none of the conditions is met, the virtual pathfinding object can continue to move along the current pathfinding path.
[0266] Refer to Figure 15 , which is a schematic flowchart of a process for determining the pathfinding effectiveness of the pathfinding path provided by the embodiments of the present invention. Each step on the right side of the figure has a corresponding number. The specific step process includes:
[0267] S1501. Start judging the pathfinding path effectiveness (that is, whether the pathfinding path is a valid path or an invalid path).
[0268] S1502. Whether the pathfinding virtual object is in the pathfinding walking state. If so, execute step S1503; if not, execute step S1511.
[0269] S1503. Whether the targetReplanTime is greater than the threshold, that is, whether the time since the last generation of the pathfinding path exceeds the preset time interval. If so, execute step S1504; if not, execute step S1511.
[0270] S1504. Whether it is performing 3D pathfinding. If so, execute step S1510; if not, execute step S1516.
[0271] S1505. Whether the number of waypoints in the pathfinding path is 0. If so, execute step S1505; if not, execute step S1511.
[0272] S1506. Whether the number of unvisited waypoints in the pathfinding path is less than 5 and the last waypoint is not the target location. If so, execute step S1510; if not, execute step S1511.
[0273] S1507. Whether the starting location in the pathfinding path is within the polygon area of the 2D pathfinding map. If so, execute step S1508; if not, execute step S1510.
[0274] S1508. Whether the target location is within the polygon area of the 2D pathfinding map. If so, execute step S1509; if not, execute step S1510.
[0275] S1509. Whether the number of polygon areas in the pathfinding path is less than 10 and the target location is not within the polygon area of the pathfinding path. If so, execute step S1510; if not, execute step S1511.
[0276] S1510. Re-plan the pathfinding path.
[0277] S1511. End the judgment of the validity of the pathfinding path.
[0278] In an exemplary embodiment, step 104, controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, may include the following steps:
[0279] Determine the current location of the pathfinding virtual object in the game scene;
[0280] Determine the next waypoint after the current location in the pathfinding path;
[0281] Calculate the moving speed and moving direction of the pathfinding virtual object based on the current location and the next waypoint;
[0282] Control the pathfinding virtual object to move from the current location to the next waypoint in the game scene according to the moving speed and the moving direction.
[0283] In a specific implementation, based on the position coordinates of the current location of the pathfinding virtual object and the position coordinates of the next waypoint, the movement speed and movement direction of the pathfinding virtual object are calculated, and then the pathfinding virtual object can be controlled to move from the current location to the next waypoint in the game scene according to the movement speed and movement direction.
[0284] In an exemplary embodiment, step 104, controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, may further include the following steps:
[0285] When the pathfinding virtual object moves to the next waypoint, if the distance between the next waypoint and the target location is less than a preset path threshold, the pathfinding virtual object ends the pathfinding walking state.
[0286] In the embodiment of the present invention, after the pathfinding virtual object moves to the next waypoint in the pathfinding path according to the calculated movement speed and movement direction, if the distance between the next waypoint and the target location is less than a preset path threshold, for example, the preset path threshold can be 0.01, it means that the pathfinding virtual object has reached the target location, then the pathfinding virtual object can end the pathfinding walking state and end the pathfinding.
[0287] Exemplarily, referring to Figure 16 , is a schematic flowchart of a method for calculating the movement speed and movement mode of a virtual pathfinding object provided by an embodiment of the present invention. Each step on the right side of the figure has a corresponding number. The specific step process includes:
[0288] S1601. Start calculating the movement speed and movement direction.
[0289] S1602. Is the pathfinding virtual object in the pathfinding walking state? If so, execute step S1603.
[0290] S1603. Is the pathfinding virtual object performing three-dimensional pathfinding? If so, execute step S1604. If not, execute step S1608.
[0291] S1604. Is the distance between the current location of the pathfinding virtual object and the next waypoint less than 0.01? If so, execute step S1605. If not, execute step S1607.
[0292] S1605. Is the next waypoint the last waypoint in the pathfinding path? If so, set the movement speed to 0 and execute step S1610. If not, execute step S1606.
[0293] S1606. Set the next waypoint to the next waypoint after the last waypoint in the pathfinding path.
[0294] S1607. Calculate the moving speed and direction based on the current location of the pathfinding virtual object and the position of the next waypoint.
[0295] S1608. Is there still an inflection point? If so, execute step S1609; if not, set the moving speed to 0 and execute step S1610.
[0296] S1609. Calculate the moving speed and direction based on the current position of the pathfinding virtual object and the next waypoint.
[0297] S1610. End the calculation of the moving speed and direction.
[0298] In summary, by applying the embodiments of the present invention, it is possible to support diverse pathfinding requirements in the game. The pathfinding virtual object in the game can use two-dimensional pathfinding or three-dimensional pathfinding in the scene according to its own needs for pathfinding and can switch between these two pathfinding methods at any time, improving the performance and operability of the game. And when dividing the game scene by using the SVO method, it is possible to perform fine-grained division only on the areas with scene models in the game scene, while performing coarse-grained division on the areas without scene models. In this way, the generated pathfinding map consumes less memory, can avoid game lag caused by excessive memory overhead, and ensures the game experience of players.
[0299] It should be noted that for the method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the embodiments of the present invention are not limited by the described action sequence, because according to the embodiments of the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily essential for the embodiments of the present invention.
[0300] Refer to Figure 17 , which shows a structural block diagram of a pathfinding device in a game provided in an embodiment of the present invention. The game includes a game scene and a pathfinding virtual object, and specifically may include the following modules:
[0301] A pathfinding response module 1701, configured to respond to a pathfinding instruction, determine the starting location and the target location of the pathfinding virtual object in the game scene, and the target pathfinding method of the pathfinding virtual object in the game scene;
[0302] A pathfinding map loading module 1702, configured to load the target pathfinding map corresponding to the target pathfinding method in the game scene;
[0303] A pathfinding path generation module 1703, configured to generate a pathfinding path according to the starting location, the target location, and the target pathfinding map;
[0304] A virtual object movement module 1704, configured to control the pathfinding virtual object to move in the game scene based on the pathfinding path.
[0305] In an exemplary embodiment, the apparatus further includes: a two-dimensional pathfinding map generation module, configured to:
[0306] Voxelize the game scene to obtain a plurality of first voxel grids; the first voxel grids have corresponding height information;
[0307] Calculate the height difference between the first voxel grids according to the height information of the first voxel grids;
[0308] Determine the surface of the scene model corresponding to the first voxel grids in the game scene where the height difference is within a preset height threshold as the walkable area;
[0309] Divide the walkable area to obtain a plurality of polygon areas;
[0310] Save the polygon areas as the two-dimensional pathfinding map of the game scene.
[0311] In an exemplary embodiment, the area of the walkable area is greater than or equal to a first preset area and less than a second preset area, and the second preset area is greater than the first preset area.
[0312] In an exemplary embodiment, the two-dimensional pathfinding map generation module is configured to:
[0313] Determine the area connection vertices in the walkable area; the area connection vertices are the vertices connecting adjacent walkable areas;
[0314] Connect adjacent area connection vertices to obtain a simplified boundary;
[0315] Determine the original vertex farthest from the simplified boundary in the original boundary as the target original vertex;
[0316] When the distance between the target original vertex and the simplified boundary is greater than a preset distance threshold, add the target original vertex to the simplified boundary, and return to execute the step of determining the original vertex farthest from the simplified boundary in the original boundary as the target original vertex;
[0317] When the distance between the target original vertex and the simplified boundary is less than or equal to the preset distance threshold, determine the simplified boundary as the target simplified boundary;
[0318] Update the walkable area to the area surrounded by the target simplified boundary.
[0319] In an exemplary embodiment, the two-dimensional pathfinding map generation module is configured to:
[0320] Divide the walkable area into a plurality of triangular regions;
[0321] Combine the triangular regions into a polygonal region; wherein, the shape of the polygonal region is a convex polygon.
[0322] In an exemplary embodiment, the device further includes: a three-dimensional pathfinding map generation module, configured to:
[0323] Voxelize the game scene according to different layers to obtain a plurality of second voxel grids corresponding to each layer;
[0324] Mark the second voxel grids including the scene model, wherein the marked second voxel grids are used to represent that the pathfinding virtual object cannot pass through;
[0325] Determine the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids; the parent-child connection relationship is used to represent the connection relationship between the second voxel grids of different layers, and the neighbor connection relationship is used to represent the connection relationship between the second voxel grids of the same layer;
[0326] Save the second voxel grids, the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids as the three-dimensional pathfinding map of the game scene.
[0327] In an exemplary embodiment, the game scene includes a scene model, and the three-dimensional pathfinding map generation module is configured to:
[0328] Voxelize the game scene according to different layers to obtain a plurality of second voxel grids corresponding to each layer;
[0329] When the second voxel grid includes the scene model, voxelize the second voxel grid including the scene model until the volume of the second voxel grid is less than or equal to the preset voxel grid volume.
[0330] In an exemplary embodiment, the pathfinding path generation module is configured to:
[0331] When the target pathfinding map is a two-dimensional pathfinding map, find the connected polygonal region between the starting point and the target point in the two-dimensional pathfinding map;
[0332] Generate a 2D pathfinding path based on the starting location, the 2D waypoints in the connected polygon area, and the target location; wherein, the 2D waypoints are position coordinate points in the polygon area calculated according to the starting location and the target location by using a specified path search algorithm, and a straight line is allowed to pass between adjacent 2D waypoints.
[0333] In an exemplary embodiment, the pathfinding path generation module is configured to:
[0334] When the target pathfinding map is a 3D pathfinding map, find the connected second voxel grids between the starting location and the target location in the 3D pathfinding map;
[0335] Generate a 3D pathfinding path based on the starting location, the 3D waypoints, and the target location, wherein the 3D waypoints are the center points of the intersecting surfaces of adjacent connected second voxel grids.
[0336] In an exemplary embodiment, the apparatus further includes: a pathfinding validity determination module, configured to:
[0337] Determine that the pathfinding path is a valid path.
[0338] In an exemplary embodiment, the apparatus further includes: a re-execution module, configured to:
[0339] When it is determined that the pathfinding path is an invalid path, use the location where the pathfinding virtual object is currently located as the starting location, and re-execute generating the pathfinding path according to the starting location, the target location, and the target pathfinding map.
[0340] In an exemplary embodiment, the pathfinding validity determination module is configured to:
[0341] If the pathfinding virtual object is not in the pathfinding walking state, or the time since the last generation of the pathfinding path exceeds a preset time interval, or when the target pathfinding mode is the 3D pathfinding mode, the number of 3D waypoints in the pathfinding path is zero, or when the target pathfinding mode is the 3D pathfinding mode, the number of 3D waypoints in the pathfinding path is not zero, and the number of 3D waypoints that the virtual pathfinding object has not reached is less than a preset waypoint threshold and the 3D waypoints that have not been reached do not include the target location, then determine that the pathfinding path is an invalid path.
[0342] In an exemplary embodiment, the pathfinding validity determination module is configured to:
[0343] When the target pathfinding method is a two-dimensional pathfinding method, if the starting location or the target location in the pathfinding path is not within the polygon area in the two-dimensional pathfinding map, or when the target pathfinding method is a two-dimensional pathfinding method, the number of polygon areas in the pathfinding path is less than a preset number threshold, and the target location is not within the last polygon area in the pathfinding path, then it is determined that the pathfinding path is an invalid path.
[0344] In an exemplary embodiment, the virtual object movement module is configured to:
[0345] Determine the current location of the pathfinding virtual object in the game scene;
[0346] Determine the next waypoint after the current location in the pathfinding path;
[0347] Calculate the movement speed and movement direction of the pathfinding virtual object based on the current location and the next waypoint;
[0348] Control the pathfinding virtual object to move from the current location to the next waypoint in the game scene according to the movement speed and the movement direction.
[0349] In an exemplary embodiment, the virtual object movement module is configured to:
[0350] After the pathfinding virtual object moves to the next waypoint, if the distance between the next waypoint and the target location is less than a preset path threshold, then the pathfinding virtual object ends the pathfinding walking state.
[0351] By the above method, the embodiments of the present invention can support a pathfinding virtual object to implement multiple pathfinding methods in a game scene, such as two-dimensional pathfinding method and three-dimensional pathfinding method, which can support diverse pathfinding requirements in the game and bring more game experiences to players. In addition, since players can control the pathfinding virtual object in the game to select the corresponding target pathfinding method according to their own needs in the game scene and switch between multiple pathfinding methods at any time, the performance and operability of the game are improved.
[0352] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for the related parts, please refer to the partial description of the method embodiment.
[0353] In addition, the embodiments of the present invention further provide an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, it implements each process of the pathfinding method embodiment in the above game and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0354] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements each process of the pathfinding method embodiment in the above game and can achieve the same technical effects. To avoid repetition, it will not be elaborated here. Among them, the computer-readable storage medium includes, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.
[0355] An embodiment of the present invention also provides a computer program product. The program product is stored in a storage medium and is executed by at least one processor to implement each process of the pathfinding method embodiment in the above game and can achieve the same technical effects. To avoid repetition, it will not be elaborated here.
[0356] Figure 18 Schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0357] The electronic device 1800 includes, but is not limited to: a radio frequency unit 1801, a network module 1802, an audio output unit 1803, an input unit 1804, a sensor 1805, a display unit 1806, a user input unit 1807, an interface unit 1808, a memory 1809, a processor 1810, and a power supply 1811, etc. Those skilled in the art can understand that Figure 18 the structure of the electronic device shown in does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements. In an embodiment of the present invention, the electronic device includes, but is not limited to, a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted terminal, a wearable device, and a pedometer, etc.
[0358] It should be understood that in an embodiment of the present invention, the radio frequency unit 1801 can be used for receiving and sending signals during information reception or call processes. Specifically, after receiving the downlink data from the base station, it is given to the processor 1810 for processing; in addition, the uplink data is sent to the base station. Usually, the radio frequency unit 1801 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier, a duplexer, etc. In addition, the radio frequency unit 1801 can also communicate with the network and other devices through a wireless communication system.
[0359] The electronic device provides wireless broadband Internet access for users through the network module 1802, such as helping users to send and receive emails, browse web pages, and access streaming media, etc.
[0360] The audio output unit 1803 can convert the audio data received by the radio frequency unit 1801 or the network module 1802 or stored in the memory 1809 into an audio signal and output it as sound. Moreover, the audio output unit 1803 can also provide an audio output related to a specific function executed by the electronic device 1800 (e.g., a call signal reception sound, a message reception sound, etc.). The audio output unit 1803 includes a speaker, a buzzer, a receiver, etc.
[0361] The input unit 1804 is used to receive audio or video signals. The input unit 1804 may include a Graphics Processing Unit (GPU) 18041 and a microphone 18042. The graphics processor 18041 processes the image data of a still picture or a video obtained by an image capturing device (such as a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 1806. The image frame processed by the graphics processor 18041 can be stored in the memory 1809 (or other storage media) or transmitted via the radio frequency unit 1801 or the network module 1802. The microphone 18042 can receive sound and can process such sound into audio data. The processed audio data can be output in a format that can be transmitted to a mobile communication base station via the radio frequency unit 1801 in the case of a phone call mode.
[0362] The electronic device 1800 further includes at least one sensor 1805, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor. Among them, the ambient light sensor can adjust the brightness of the display panel 18061 according to the brightness of the ambient light, and the proximity sensor can turn off the display panel 18061 and / or the backlight when the electronic device 1800 is moved to the ear. As a kind of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary, and can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as a pedometer, tapping), etc.; the sensor 1805 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be elaborated here.
[0363] The display unit 1806 is used to display information input by the user or information provided to the user. The display unit 1806 may include a display panel 18061, and the display panel 18061 may be configured in the form of, for example, a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.
[0364] The user input unit 1807 can be used to receive input numerical or character information, and generate key signal inputs related to user settings and function controls of the electronic device. Specifically, the user input unit 1807 includes a touch panel 18071 and other input devices 18072. The touch panel 18071, also known as a touch screen, can collect touch operations of the user thereon or nearby (such as operations of the user using any suitable object or accessory such as a finger or a stylus on or near the touch panel 18071). The touch panel 18071 can include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the touch position of the user, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the processor 1810, and receives and executes the command sent by the processor 1810. In addition, the touch panel 18071 can be implemented in multiple types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 18071, the user input unit 1807 may further include other input devices 18072. Specifically, the other input devices 18072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, power on / off keys, etc.), a trackball, a mouse, a joystick, which will not be elaborated here.
[0365] Further, the touch panel 18071 may cover the display panel 18061. After the touch panel 18071 detects a touch operation thereon or nearby, it transmits the operation to the processor 1810 to determine the type of touch event. Subsequently, the processor 1810 provides a corresponding visual output on the display panel 18061 according to the type of touch event. Although in Figure 18 the touch panel 18071 and the display panel 18061 are implemented as two independent components to realize the input and output functions of the electronic device, in some embodiments, the touch panel 18071 and the display panel 18061 can be integrated to realize the input and output functions of the electronic device, and the specific implementation here is not limited.
[0366] The interface unit 1808 is an interface for an external device to connect to the electronic device 1800. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, and so on. The interface unit 1808 can be used to receive inputs from an external device (such as data information, power, etc.) and transfer the received inputs to one or more components within the electronic device 1800 or can be used to transfer data between the electronic device 1800 and the external device.
[0367] The memory 1809 can be used to store software programs and various data. The memory 1809 mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.). In addition, the memory 1809 can include a high-speed random access memory and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices.
[0368] The processor 1810 is the control center of the electronic device, connecting various parts of the entire electronic device through various interfaces and lines. By running or executing software programs and / or modules stored in the memory 1809, and by calling data stored in the memory 1809, it executes various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 1810 can include one or more processing units; preferably, the processor 1810 can integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 1810.
[0369] The electronic device 1800 can also include a power supply 1811 (such as a battery) for powering each component. Preferably, the power supply 1811 can be logically connected to the processor 1810 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system.
[0370] In addition, the electronic device 1800 includes some functional modules not shown here, which will not be elaborated further.
[0371] It should be noted that, in this article, the term "including", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including such element.
[0372] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described method of the embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0373] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit and scope protected by the claims of the present invention, and all of them belong to the protection scope of the present invention.
[0374] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in connection with the embodiments disclosed in the embodiments of the present invention can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of the present invention.
[0375] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be repeated here.
[0376] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0377] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0378] In addition, in each embodiment of the present invention, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0379] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the essence of the technical solution of the present invention, or the part that contributes to the prior art, or the part of this 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 for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0380] As described above, only the specific implementation manners of the present invention are provided, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims
1. A pathfinding method in a game, characterized in that, The game includes a game scene and a pathfinding virtual object, and the method includes: In response to a pathfinding instruction, determining a starting location and a target location of the pathfinding virtual object in the game scene, and a target pathfinding method of the pathfinding virtual object in the game scene; Loading a target pathfinding map corresponding to the target pathfinding method in the game scene; Generating a pathfinding path according to the starting location, the target location, and the target pathfinding map; Controlling the pathfinding virtual object to move in the game scene based on the pathfinding path; Voxelizing the game scene according to different layers to obtain a plurality of second voxel grids corresponding to each layer; Marking the second voxel grids containing the scene model, where the marked second voxel grids are used to represent that the pathfinding virtual object cannot pass through; Determining a parent-child connection relationship and / or a neighbor connection relationship between the second voxel grids; the parent-child connection relationship is used to represent the connection relationship between the second voxel grids in different layers, and the neighbor connection relationship is used to represent the connection relationship between the second voxel grids in the same layer; Saving the second voxel grids, the parent-child connection relationship and / or the neighbor connection relationship between the second voxel grids as a three-dimensional pathfinding map of the game scene.
2. The method according to claim 1, wherein The method further includes: Voxelizing the game scene to obtain a plurality of first voxel grids; the first voxel grids have corresponding height information; Calculating a height difference between the first voxel grids according to the height information of the first voxel grids; Determining the surface of the scene model corresponding to the adjacent first voxel grids whose height difference is within a preset height threshold in the game scene as a walkable area; Dividing the walkable area to obtain a plurality of polygon areas; Saving the polygon areas as a two-dimensional pathfinding map of the game scene.
3. The method according to claim 2, wherein The area of the walkable area is greater than or equal to a first preset area and less than a second preset area, and the second preset area is greater than the first preset area.
4. The method according to claim 2, wherein The walkable area is surrounded by an original boundary, and the original boundary includes original vertices. Before dividing the walkable area to obtain a plurality of polygon areas, the method further includes: Determining area connection vertices in the walkable area; the area connection vertices are vertices connecting adjacent walkable areas; Connecting adjacent area connection vertices to obtain a simplified boundary; Determining the original vertex farthest from the simplified boundary in the original boundary as a target original vertex; When the distance between the target original vertex and the simplified boundary is greater than a preset distance threshold, adding the target original vertex to the simplified boundary and returning to execute determining the original vertex farthest from the simplified boundary in the original boundary as the target original vertex; When the distance between the target original vertex and the simplified boundary is less than or equal to the preset distance threshold, determining the simplified boundary as a target simplified boundary; Update the walkable area to the area enclosed by the target simplified boundary.
5. The method according to claim 2 or 4, characterized in that, Partition the walkable area to obtain a number of polygon areas, including: Partition the walkable area into a number of triangular areas; Combine the triangular areas into polygon areas; wherein, the shape of the polygon area is a convex polygon.
6. The method according to claim 1, wherein The game scene includes a scene model. Voxelize the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer, including: Voxelize the game scene according to different layers to obtain a number of second voxel grids corresponding to each layer; When the second voxel grid includes the scene model, voxelize the second voxel grid including the scene model until the volume of the second voxel grid is less than or equal to the preset voxel grid volume.
7. The method according to claim 2, characterized in that, Generate a pathfinding path according to the starting point, the target point, and the target pathfinding map, including: When the target pathfinding map is a two-dimensional pathfinding map, search for the connected polygon area between the starting point and the target point in the two-dimensional pathfinding map; Generate a two-dimensional pathfinding path according to the starting point, the two-dimensional path points in the connected polygon area, and the target point; wherein, the two-dimensional path points are the position coordinate points in the polygon area calculated according to the starting point and the target point by using a specified path search algorithm, and a straight line is allowed to pass between adjacent two-dimensional path points.
8. The method according to claim 1, wherein Generate a pathfinding path according to the starting point, the target point, and the target pathfinding map, including: When the target pathfinding map is a three-dimensional pathfinding map, search for the connected second voxel grids between the starting point and the target point in the three-dimensional pathfinding map; Generate a three-dimensional pathfinding path according to the starting point, the three-dimensional path points, and the target point, wherein the three-dimensional path points are the central points of the intersecting surfaces of adjacent connected second voxel grids.
9. The method according to claim 1, wherein Before controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, the method further includes: Determine that the pathfinding path is a valid path.
10. The method according to claim 1, wherein Before controlling the pathfinding virtual object to move in the game scene based on the pathfinding path, the method further includes: When it is determined that the pathfinding path is an invalid path, use the location where the pathfinding virtual object is currently located as the starting point, and re-execute generating a pathfinding path according to the starting point, the target point, and the target pathfinding map.
11. The method according to claim 9 or 10, characterized in that, The method further includes: If the pathfinding virtual object is not in the pathfinding walking state, or the time since the last generation of the pathfinding path exceeds the preset time interval, or when the target pathfinding method is the three-dimensional pathfinding method, the number of three-dimensional path points in the pathfinding path is zero, or when the target pathfinding method is the three-dimensional pathfinding method, the number of three-dimensional path points in the pathfinding path is not zero, and the number of unarrived three-dimensional path points of the pathfinding virtual object is less than the preset path point threshold and the unarrived three-dimensional path points do not include the target point, then determine that the pathfinding path is an invalid path.
12. The method according to claim 2, wherein The method further includes: When the target pathfinding method is a two-dimensional pathfinding method, if the starting location or the target location in the pathfinding path is not within the polygon area in the two-dimensional pathfinding map, or when the target pathfinding method is a two-dimensional pathfinding method, the number of polygon areas in the pathfinding path is less than a preset number threshold, and the target location is not within the last polygon area in the pathfinding path, then it is determined that the pathfinding path is an invalid path.
13. The method according to claim 1, wherein Controlling the pathfinding virtual object to move in the game scene based on the pathfinding path includes: Determining the current location of the pathfinding virtual object in the game scene; Determining the next waypoint after the current location in the pathfinding path; Calculating the movement speed and movement direction of the pathfinding virtual object according to the current location and the next waypoint; Controlling the pathfinding virtual object to move from the current location to the next waypoint in the game scene according to the movement speed and the movement direction.
14. The method according to claim 13, characterized in that, Controlling the pathfinding virtual object to move in the game scene based on the pathfinding path further includes: When the pathfinding virtual object moves to the next waypoint, if the distance between the next waypoint and the target location is less than a preset path threshold, then the pathfinding virtual object ends the pathfinding walking state.
15. A pathfinding device in a game, characterized in that, The game includes a game scene and a pathfinding virtual object, and the device includes: A pathfinding response module, configured to respond to a pathfinding instruction, determine the starting location and the target location of the pathfinding virtual object in the game scene, and the target pathfinding method of the pathfinding virtual object in the game scene; A pathfinding map loading module, configured to load a target pathfinding map corresponding to the target pathfinding method in the game scene; A pathfinding path generation module, configured to generate a pathfinding path according to the starting location, the target location, and the target pathfinding map; A virtual object movement module, configured to control the pathfinding virtual object to move in the game scene based on the pathfinding path; A three-dimensional pathfinding map generation module, configured to: Voxelize the game scene according to different layers to obtain a plurality of second voxel grids corresponding to each layer; Mark the second voxel grids including the scene model, where the marked second voxel grids are used to represent that the pathfinding virtual object cannot pass through; Determine the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids; the parent-child connection relationship is used to represent the connection relationship between the second voxel grids in different layers, and the neighbor connection relationship is used to represent the connection relationship between the second voxel grids in the same layer; Save the second voxel grids, the parent-child connection relationship and / or neighbor connection relationship between the second voxel grids as the three-dimensional pathfinding map of the game scene.
16. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete communication with each other through the communication bus; The memory is used to store a computer program; When the processor executes the program stored in the memory, it implements the method according to any one of claims 1-14.
17. A computer-readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to execute the method according to any one of claims 1-14.
Citation Information
Patent Citations
A super-large map movement optimization method
CN109685903A
Game way-finding method and device, storage medium and computer equipment
CN111714892A