Data processing method and device in way finding and electronic equipment
By dividing the voxel mesh in the game scene into connectable convex polygons and determining the virtual character path based on the attribute data, the problems of high pathfinding and high maintenance costs in the existing technology are solved, and efficient and accurate Virtual roles move and reduce storage and maintenance costs.
Patent Information
- Application Number
- CN202410985341.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-11-12
AI Technical Summary
When finding a way in the game, the existing technology consumes high, maintains high maintenance costs, and frequent resource updates lead to large performance overhead, affecting game performance and player experience.
By marking the attribute data on the voxel grid in the game scene, dividing it into connectable convex polygons, and determining the path through which the target virtual character can pass based on the attribute data, reducing storage space and loading time and reducing maintenance costs.
It effectively reduces performance consumption in the pathfinding process, improves the efficient and accurate movement ability of target virtual characters in complex scenarios, and reduces storage space and maintenance costs.
Smart Images

Figure CN118925235A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and computer-readable storage medium for data processing in pathfinding. Background Art
[0002] With the continuous development of virtual games, the autonomous navigation ability of the target virtual characters in the game has gradually become one of the key factors to improve the gaming experience. In particular, the efficiency and flexibility of the pathfinding system are directly related to the realism of the game and the smoothness of the player's interaction. Game pathfinding technology mainly involves path planning between two points.
[0003] At present, for path planning between two points, the industry generally uses tools such as RecastNavigation (navigation mesh generator) to pre-bake pathfinding meshes, which can create efficient path planning for specific types of pathfinding needs. For example, for the different interaction rules of player characters and non-player characters (NPCs) with the environment, if player characters can cross the water surface but non-player characters cannot, pathfinding graph A (water surface is set as an obstacle) and pathfinding graph B (water surface is unobstructed) can be generated respectively, so that the player character uses pathfinding graph B and the NPC uses pathfinding graph A to make movement decisions respectively.
[0004] Although the above method meets the pathfinding needs in the game to a certain extent, creating multiple sets of pathfinding maps for different pathfinding needs has at least the following defects: on the one hand, it consumes additional storage space, prolongs the loading time of the pathfinding map, and affects the game performance; on the other hand, if the pathfinding map needs to be modified during the game or the scene resources change and all the pathfinding maps need to be re-baked, all related pathfinding maps need to be updated synchronously, which increases the maintenance cost and improves the performance consumption. Summary of the invention
[0005] The present application provides a data processing method, device, electronic device and computer-readable storage medium in pathfinding, which can reduce the performance consumption in the pathfinding process. The specific scheme is as follows:
[0006] In a first aspect, an embodiment of the present application provides a method for processing data in pathfinding, the method comprising:
[0007] Marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid;
[0008] Determine each target voxel grid corresponding to an area in each voxel grid where a virtual character belonging to at least one character type can walk, wherein the character type includes a player character type and a non-player character type;
[0009] According to the attribute data corresponding to the target voxel grids, each of the target voxel grids is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grid contained in each of the convex polygons is the same;
[0010] In response to a pathfinding instruction for a target virtual character, a first path for the target virtual character to move is determined from each first convex polygon having first attribute data among the convex polygons, wherein the area type indicated by the first attribute data is the area type through which the target virtual character can pass.
[0011] In a second aspect, an embodiment of the present application provides a data processing device in pathfinding, the device comprising:
[0012] A marking unit, used for marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid;
[0013] A first determining unit is used to determine each target voxel grid corresponding to a walkable area of a virtual character belonging to at least one character type in each voxel grid, wherein the character type includes a player character type and a non-player character type;
[0014] A division unit, configured to divide each target voxel grid into connected convex polygons according to the attribute data corresponding to the target voxel grid, wherein the attribute data corresponding to the target voxel grid contained in each convex polygon is the same;
[0015] The second determination unit is used to determine a first path for the target virtual character to move from each first convex polygon having first attribute data in each convex polygon in response to a path-finding instruction for the target virtual character, wherein the area type indicated by the first attribute data is an area type through which the target virtual character can pass.
[0016] In a third aspect, the present application further provides an electronic device, including:
[0017] Processor; and
[0018] The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the method described in the first aspect is executed.
[0019] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium storing a data processing program, which is executed by a processor to perform the method described in the first aspect.
[0020] Compared with the prior art, this application has the following advantages:
[0021] The data processing method for pathfinding provided in an embodiment of the present application firstly marks attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate the area type of the scene model corresponding to the voxel grid, so that the voxel grids corresponding to all scene models in the game scene are marked with attribute data, so that it is possible to determine to which area type each voxel grid belongs; then, each target voxel grid corresponding to an area in which a virtual character belonging to at least one character type can walk in each of the voxel grids is determined, wherein the character type includes a player character type and a non-player character type, so that it is possible to determine from each of the voxel grids an area in which a player character and / or a non-player character can walk, except for an area inaccessible to the target virtual character; then, each of the target voxel grids is marked according to the attribute data corresponding to the target voxel grid. The voxel grid is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grid contained in each of the convex polygons is the same, so that connected convex polygons can be obtained, and each convex polygon has and only has one attribute data; finally, in response to the pathfinding instruction for the target virtual character, the first path to be moved by the target virtual character is determined from each first convex polygon with first attribute data in each of the convex polygons, wherein the area type indicated by the first attribute data is the area type that the target virtual character can pass through, since each of the obtained convex polygons has and only has one attribute data, and since the area type indicated by the first attribute data is the area type that the target virtual character can pass through, therefore, the first path determined in each first convex polygon with the first attribute data is the path that the target virtual character can walk. In this way, when there is a pathfinding demand for a certain target virtual character, the corresponding path can be queried from the convex polygons whose area type indicated by the attribute data is the area type that the target virtual character can pass through.
[0022] It can be seen that the data processing method for pathfinding provided in the embodiment of the present application can determine the pathfinding path for the target virtual character with different pathfinding needs by generating a connected convex polygon carrying attribute data. Compared with the current creation of multiple sets of pathfinding graphs for different pathfinding needs, on the one hand, the pathfinding data used to support pathfinding in this solution (that is, the convex polygons carrying attribute data) effectively reduces the storage space and reduces the loading time of the pathfinding data. On the other hand, if the scene model needs to be modified during the game operation, it is sufficient to redetermine the convex polygons carrying attribute data without re-baking and updating all pathfinding graphs, thereby reducing development and maintenance costs. It can be seen that the data processing method for pathfinding provided in the embodiment of the present application can effectively reduce the performance consumption in the pathfinding process, and the data processing method for pathfinding provided in the embodiment of the present application can control the target virtual character to efficiently and accurately complete automatic pathfinding in complex game scenes. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a flow chart of a data processing method in pathfinding provided by an embodiment of the present application;
[0024] Figure 2 is a schematic diagram of an example of a target path point on a first path in the data processing method for pathfinding provided in an embodiment of the present application;
[0025] Figure 3 It is a schematic diagram of an example of searching for a first point in the data processing method for pathfinding provided in an embodiment of the present application;
[0026] Figure 4 It is a flow chart for determining a target position for a player character in a data processing method for pathfinding provided in an embodiment of the present application;
[0027] Figure 5 is a schematic diagram of an example of a grid area in a data processing method for pathfinding provided in an embodiment of the present application;
[0028] Figure 6 It is a schematic diagram of rotating a grid area in the data processing method for pathfinding provided in an embodiment of the present application;
[0029] Figure 7 is a structural block diagram of an example of a data processing device for pathfinding provided in an embodiment of the present application;
[0030] Figure 8 It is a structural block diagram of an example of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0032] It should be noted that the terms "first", "second", "third", etc. in the claims, description and drawings of the present application are used to distinguish similar objects and are not used to describe a specific order or sequence. The data used in this way are interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including", "having" and their variants are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] It should be understood that in the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" is merely a way to describe the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. "Including A, B and / or C" means including any one, any two, or any three of A, B, and C.
[0034] It should be understood that in the embodiments of the present application, "B corresponding to A", "B corresponding to A", "A corresponds to B", or "B corresponds to A" means that B is associated with A, and B can be determined according to A. Determining B according to A does not mean determining B only according to A, and B can also be determined according to A and / or other information.
[0035] It should be noted that the instructions or operations that appear in the subsequent detailed introduction of the data processing method in the pathfinding provided by the embodiment of the present application can all be regarded as instructions or operations triggered by the player through fingers or controlling the mouse, keyboard, game controller or stylus or voice. The specific triggering operation can be determined according to the type of electronic device. For example, when the electronic device is a touch screen device such as a mobile phone, tablet computer, game console, etc., the player can trigger instructions or operations on the touch screen through any suitable object or accessory such as a finger or stylus, or through voice. When the terminal device is a non-touch screen terminal device such as a desktop computer or a laptop computer, the player can trigger instructions or operations through external devices such as a mouse, keyboard, and game controller.
[0036] Before describing the implementation methods of the present application in detail, relevant concepts are first introduced, and the prior art is further described.
[0037] In game development, pathfinding algorithms are a key technology to ensure that game characters can move intelligently in the virtual world. In a complex three-dimensional environment, pathfinding problems mainly involve two levels: one is long-distance pathfinding, that is, finding a path from the starting point to the end point on a large-scale map; the other is real-time displacement processing, that is, avoiding obstacles in a local area to achieve precise movement. The game world is often complex and changeable, and the target virtual character needs to move freely in various terrains. The long-distance pathfinding problem focuses on how to automatically calculate an optimal or feasible movement path from the starting point to the end point, which usually involves complex algorithms to reduce movement time or follow specific path preferences. Once the movement path is determined, the actual displacement operation needs to ensure that the target virtual character can move accurately along the calculated path, while handling real-time obstacles in the dynamic environment, such as sudden appearance of entities or changes in traversable / non-traversable areas.
[0038] In related technologies, tools such as RecastNavigation (navigation mesh generator) are usually used to pre-bake the navigation mesh, which can effectively handle path planning in static environments. In this way, game developers can customize pathfinding strategies for different types of target virtual characters (such as player characters or non-player characters). Especially when dealing with special interaction requirements, such as the different passability of player characters and non-player characters on the same terrain (such as water surface), it is usually necessary to create multiple sets of pathfinding maps, each set of pathfinding maps for specific pathfinding rules. For example, if the player character can pass through the water surface, but the non-player character cannot pass through the water surface, then a pathfinding map that allows passage through the water surface is designed for the player, and another pathfinding map that uses the water surface as an obstacle is designed for the non-player character. Although this method achieves functional differentiation, it increases the complexity of resource management and maintenance, and limits the dynamic adaptability to environmental changes.
[0039] In addition, the real-time displacement determination of the target virtual character usually relies on the collision detection mechanism of the physics engine. The physics engine can monitor the contact between the target virtual character and the environment or other objects in real time to determine whether the next action is feasible. If there is an obstacle, the movement of the target virtual character will be naturally blocked or redirected. The physics engine not only detects collisions, but is also responsible for simulating physical phenomena such as gravity to ensure the realism of the game world.
[0040] However, the data processing method in pathfinding provided by the related art has at least the following problems:
[0041] First, high memory consumption: loading multiple pathfinding maps significantly increases the memory usage when the game is running, especially for large or open world games.
[0042] Second, high maintenance costs: If the pathfinding map needs to be adjusted during the game, for example, the target virtual character destroys a virtual box blocking the road in the game scene, changing the passable area, or a bridge is dynamically generated in the game scene at a certain moment, connecting two originally separated areas, the pathfinding map needs to be modified. Each modification must be synchronized to all related pathfinding maps, which increases the burden on developers.
[0043] Third, the cost of resource updates is high: Whenever scene resources change, such as adding, deleting, or adjusting obstacles, not only does it need to update the visual performance in the game, but it also needs to re-bake all associated pathfinding maps, which increases the workload of developers. On the other hand, as the number of pathfinding maps increases, the size of the game client data will continue to grow, which not only increases the player's download time, but also increases the disk space requirements of the game client. In addition, frequent resource updates and game clients with large data volumes may make the installation and update process for players cumbersome, reducing the accessibility of virtual games and player satisfaction.
[0044] Fourth, high performance overhead: Even with optimization methods such as quadtrees, the collision detection and gravity simulation of the physics engine still incur high computational costs, especially in high-density scenes and multi-entity interaction environments, where this disadvantage is more obvious.
[0045] To sum up, although the relevant technologies can meet the basic pathfinding needs, they have limitations in resource efficiency, maintenance convenience and performance. Therefore, there is an urgent need for a data processing method in pathfinding that has lower performance consumption and can control the target virtual character to complete automatic pathfinding efficiently and accurately in complex game scenes.
[0046] Based on the above reasons, in order to reduce the performance consumption in the pathfinding process and control the target virtual character to efficiently and accurately complete automatic pathfinding in complex game scenes, the first embodiment of the present application provides a data processing method in pathfinding, which is applied to electronic devices. The electronic device can be a desktop computer, a laptop computer, a mobile phone, a tablet computer, an electronic watch, etc., or other electronic devices capable of pathfinding, which is not specifically limited in the embodiments of the present application.
[0047] It should be noted that in the embodiments of the present application, the execution subject of the data processing method in pathfinding can be a terminal device or a server, wherein the terminal device can be a local terminal device or a client device in the aforementioned cloud game. The embodiments of the present application do not limit the type of the execution subject.
[0048] The technical solution of the present application is described in detail below through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0049] The following, combined Figure 1 to Figure 6 The data processing method for pathfinding provided in an embodiment of the present application is introduced.
[0050] like Figure 1 As shown, the data processing method for path finding provided by the present application includes the following steps S101 to S104.
[0051] Step S101: marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid.
[0052] The game scene refers to a virtual environment provided for the target virtual character to perform game behaviors. The target virtual character may be a player character or a non-player character, including but not limited to at least one of a virtual person and a virtual animal. The game behaviors may include but are not limited to at least one of adjusting body posture, crawling, walking, running, jumping, driving, picking up, shooting, attacking, throwing, moving, sprinting, and defending.
[0053] It should be noted that the scene model refers to the three-dimensional model that constitutes the game scene. Specifically, the scene model may include but is not limited to at least one of the following scene landforms: mountains, hills, deserts, waters, houses, castles, bridges, towers, trees, flowers, and rocks.
[0054] In an embodiment of the present application, the scene model can be voxelized to obtain voxel grids corresponding to the scene model. Voxelization is the process of converting objects or data in three-dimensional space into voxel representation. Voxel is the abbreviation of volume element, which is equivalent to the corresponding concept of pixels in two-dimensional images in three-dimensional space, and is the smallest unit in three-dimensional space segmentation. These voxels are usually small cubes or cuboids in three-dimensional space, which are used to approximately fill or cover the shape and volume of the three-dimensional model.
[0055] In the voxelization process, the continuous space where the 3D model is located is discretized and divided into a series of regularly arranged voxel grids. For each voxel grid, it can be further determined whether the grid is occupied by the model. If so, it is marked as a solid voxel grid; if it is located on the surface of the model, it is a surface voxel grid; if it is not occupied by the model, it is an empty voxel grid.
[0056] In one embodiment, the attribute data for marking each voxel grid corresponding to the scene model in the game scene can be achieved by the following steps: for each scene model in the game scene, the type identification information used to characterize the area type of the targeted scene model is determined as the attribute data of each voxel grid corresponding to the targeted scene model.
[0057] The region type and the type identification information correspond one to one, and the type identification information can be a string or a vector.
[0058] In another optional implementation, marking attribute data of each voxel grid corresponding to the scene model in the game scene can be implemented by the following steps:
[0059] Marking the voxel grid corresponding to the scene model of the area type that is passable by the player character and the area type that is not passable by the NPC in the game scene as the first data; and
[0060] Marking the voxel grid corresponding to the scene model of the game scene that belongs to the area type that the NPC can pass through and belongs to the area type that the player character cannot pass through as the second data; and
[0061] Marking the voxel grid corresponding to the scene model of the area type that the player character can pass through and the area type that the NPC can pass through in the game scene as the third data;
[0062] The first data, the second data and the third data are binary data.
[0063] As shown in Table 1, it is an example table of marking the attribute data of each voxel grid corresponding to the scene model as binary data in the data processing method in pathfinding provided by an embodiment of the present application:
[0064] Table 1.
[0065] Voxel grid type Attribute data Passable by player characters but not by NPCs 01 Player characters cannot pass through, but NPCs can pass through 10 Player characters can pass through and NPCs can pass through 11
[0066] In the above Table 1, the first data is 00, the second data is 01, and the third data is 02, that is, the voxelized grid corresponding to the scene model that is passable by the player character but not by the non-player character (NPC) is marked as 01, the voxelized grid corresponding to the scene model that is not passable by the player character but passable by the NPC is marked as 10, and the voxelized grid corresponding to the scene model that is passable by the player character and the NPC is marked as 11.
[0067] For example, the grass belongs to the scene model that both the player character and the NPC can pass through, the river belongs to the scene model that the player character can pass through but the NPC cannot pass through, and the tower bridge belongs to the scene model that the NPC can pass through but the player character cannot pass through. Based on the above Table 1, the grass can be marked as 11, the river can be marked as 01, and the tower bridge can be marked as 10.
[0068] In the embodiments of the present application, the attribute data of each voxel grid corresponding to the scene model is marked in binary form, which has the following advantages: on the one hand, the binary mark directly uses bits to encode information, and each area only requires a fixed number of bits. Compared with the decimal system, this reduces the storage bytes required for each attribute data, thereby reducing memory pressure; on the other hand, bit operations can be used to directly operate data at the bit level. These operations are usually faster than operations on decimal values, and there is no need for complex numerical comparisons or conversions, which can significantly reduce calculation time and thus improve calculation speed.
[0069] Step S202: determining each target voxel grid corresponding to a walkable area of a virtual character belonging to at least one character type in each voxel grid, wherein the character type includes a player character type and a non-player character type.
[0070] It should be noted that each target voxel grid determined in step S202 refers to: a surface voxel grid of a scene model that a target virtual character of at least one character type can pass through. In other words, each target voxel grid is a grid obtained by removing grids that are inaccessible to both the player character and the NPC from each voxel grid, and the target voxel grid is a grid located on the ground surface.
[0071] In virtual games, a set of movement rules or configuration parameters are usually pre-set to determine the standard of walkability. In step S102, the movement configuration parameters can be first obtained, and the target voxel grids corresponding to the walkable areas of the virtual characters belonging to at least one character type in each of the voxel grids are determined according to the movement configuration parameters. The movement configuration parameters refer to the pre-set movement rules or configuration parameters. It should be noted that the movement configuration parameters are used to impose general restrictions on the movement of player characters and NPCs in the game scene. That is to say, the areas that do not meet the movement configuration parameters are inaccessible to the player characters and NPCs in the game scene.
[0072] The movement configuration parameters may generally include but are not limited to at least one of the following: a movement height limit parameter, a movement angle limit parameter, and a jump limit parameter. The movement height limit parameter is used to define the maximum height difference of a target virtual character moving one step in the game scene. For example, if the movement height limit parameter is 5 meters, it means that steps or obstacles higher than 5 meters are inaccessible to the target virtual character.
[0073] It should be noted that the areas that meet the movement configuration parameters are not necessarily areas that are accessible to both player characters and NPCs. For example, the areas that meet the movement configuration parameters include rivers and tower bridges. Rivers are areas that player characters can pass through but NPCs cannot pass through, and tower bridges are areas that NPCs can pass through but player characters cannot pass through.
[0074] Step S103: According to the attribute data corresponding to the target voxel grids, each of the target voxel grids is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grids contained in each of the convex polygons is the same.
[0075] The convex polygon may be a triangle, a polygon, etc., and this application does not limit this. Here, the walkable area is divided into convex polygons. When the path is found later, two points in a convex polygon can be reached in a straight line, avoiding the tortuous path caused by searching between two points in a concave polygon, so as to reduce the data calculation in the path finding and reduce the performance consumption in the path finding.
[0076] It should be noted that, among the connected convex polygons, each of the convex polygons has corresponding attribute data, and the attribute data corresponding to each of the convex polygons is the attribute data corresponding to the target voxel grid contained in the convex polygon. In other words, the attribute data of each of the convex polygons is unique, for example, a target voxel grid belonging to a grassland and a target voxel grid belonging to a mountain will not be divided into one convex polygon.
[0077] In this way, each convex polygon carrying attribute data is obtained, and when there is a specific type of path-finding requirement, the corresponding path can be found from each convex polygon according to the attribute data. Specifically, when there is a path-finding requirement for a player character, the path that the player character can reach and that corresponds to the path-finding requirement can be determined from the convex polygon whose area type indicated by the attribute data is an area type that the player character can pass through; when there is a path-finding requirement for an NPC, the path that the NPC can reach and that corresponds to the path-finding requirement can be determined from the convex polygon whose area type indicated by the attribute data is an area type that the NPC can pass through.
[0078] In combination with the above Table 1, for the path-finding needs of the player character, the corresponding path can be determined from the convex polygons with attribute data of 01 and 11, and for the path-finding needs of the NPC, the corresponding path can be determined from the convex polygons with attribute data of 10 and 11.
[0079] In an optional embodiment, after dividing each target voxel grid into connected convex polygons, a pathfinding logic can also be generated, which includes each of the convex polygons and each of the convex polygons carries corresponding attribute data, wherein the pathfinding logic is used to query the farthest reachable path of the target virtual character from the starting point to the end point in the connected area composed of the convex polygons according to the attribute data.
[0080] In a specific implementation, the end point can be a location point that the target virtual character at the starting point can reach, or a location point that the target virtual character at the starting point cannot reach. For example, the end point is in an area that the target virtual character cannot reach, or the end point is located below the ground surface, or the end point is located in the air. For the starting point and the end point, the path-finding logic can query the target location point that is as close as possible to the end point and reachable by the target virtual character, and output a path with the starting point as the path starting point and the target location point as the path end point.
[0081] As shown in Table 2, this is an example table of querying the path between two locations through the path-finding logic in the data processing method in the path-finding provided in the embodiment of the present application.
[0082] Table 2.
[0083]
[0084] In the above Table 2, the coordinates of the starting point passed into the path-finding logic are (0, 0, 0), and the coordinates of the end point passed into the path-finding logic are (0, 0, 9). That is to say, the path of the target virtual character from (0, 0, 0) to (0, 0, 9) needs to be queried through the path-finding logic. When the end point (0, 0, 9) is a position reachable by the target virtual character, the path-finding logic can output the path between (0, 0, 0) → (0, 0, 9). When the end point (0, 0, 9) is an unreachable position for the target virtual character, the path-finding logic can query the position point (0, 0, 8) closest to the end point (0, 0, 9) and reachable by the target virtual character, thereby outputting the path between (0, 0, 0) → (0, 0, 8).
[0085] The pathfinding logic may also be referred to as a pathfinding graph, which may be pre-baked during the game development phase. Specifically, after the game scene is built, the pathfinding graph may be pre-generated based on the scene model in the game scene. In addition, the pathfinding graph may be re-baked if the scene model changes during the game operation. Therefore, steps S101 to S103 may be performed during the game development phase, and steps S101 to S103 may be performed again if the scene model changes during the game operation.
[0086] Specifically, in response to a change instruction of the scene model, the scene model is changed in a change manner indicated by the change instruction to obtain an updated scene model, and based on the target scene model, an updated pathfinding logic is generated based on the changed scene model.
[0087] Based on the above steps S101 to S103, generating updated pathfinding logic based on the changed scene model may include the following steps:
[0088] voxelize the updated scene model to obtain updated voxel grids; mark updated attribute data on each of the updated voxel grids, wherein the updated attribute data is used to indicate the region type of the updated scene model corresponding to the corresponding updated voxel grid;
[0089] Determine, according to the movement configuration parameters, updated target voxel grids corresponding to walkable areas of the virtual characters belonging to at least one character type in the updated voxel grids;
[0090] According to the updated attribute data corresponding to the updated target voxel grids, each of the updated target voxel grids is divided into connected updated convex polygons, wherein the updated attribute data corresponding to the updated target voxel grids contained in each of the updated convex polygons are the same;
[0091] Generate an updated path-finding logic that includes the updated convex polygons, and each updated convex polygon carries corresponding attribute data, wherein the updated path-finding logic is used to query the farthest reachable path of the target virtual character from the starting point to the end point in the connected area composed of the updated convex polygons according to the attribute data.
[0092] It should be noted that due to the change in the scene model, the pathfinding logic before and after the update may output different paths for the same target virtual character and the same pair of start and end points.
[0093] Step S104: In response to a path-finding instruction for a target virtual character, determine a first path for the target virtual character to move from each first convex polygon having first attribute data in each convex polygon, wherein the target virtual character is one of a player character and an NPC, and the area type indicated by the first attribute data is an area type through which the target virtual character can pass.
[0094] In an embodiment of the present application, the pathfinding instructions can be pathfinding instructions corresponding to the player character, or pathfinding instructions corresponding to the NPC. The pathfinding instructions corresponding to the player character can be generated through input player operations, and the pathfinding instructions corresponding to the NPC can be automatically generated when it is detected that the NPC pathfinding conditions are met.
[0095] The pathfinding instructions corresponding to the player character may be pathfinding instructions generated by the player controlling the target virtual character to perform real-time movement operations, or the player may select a destination to be reached and issue pathfinding instructions to the target virtual character from the current location to the destination. The pathfinding instructions may be generated by touch operations on mobile controls, or by voice commands, or by touch operations on a mouse, keyboard, or touch-sensitive screen. The present application does not specifically limit the method for generating the pathfinding instructions of the player character.
[0096] The pathfinding instructions corresponding to the NPC can be generated, for example, when the NPC is born, or when the NPC reaches an awakened state. The present application does not specifically limit the method for generating the pathfinding instructions of the NPC.
[0097] Step S104 is a step in the game running stage. In response to the pathfinding instruction for the target virtual character, the type of area through which the target virtual character can pass can be determined, and the corresponding first attribute data is determined based on the type of area through which the target virtual character can pass, and the first convex polygons that are connected and carry the first attribute data are screened from the convex polygons generated in step S103. After that, the first path to be moved by the target virtual character after responding to the above pathfinding instruction is determined from the first convex polygons. It should be noted that the first convex polygons can form a connected area, so that a first path located within the first convex polygons can be obtained. Since the area type indicated by the first attribute data of the first convex polygons is the type of area through which the target virtual character can pass, that is, the first convex polygons are convex polygons through which the target virtual character can pass, therefore, the first path determined from the first convex polygons with the first attribute data is the path that the target virtual character can walk.
[0098] “Determine the area type that the target virtual character can pass through, and determine the corresponding first attribute data based on the area type that the target virtual character can pass through” may specifically include: if the target virtual character is a player character, then the first area type that the player character can pass through (such as grassland, river and mountain) can be determined, and then the first attribute data corresponding to the first area type is determined; if the target virtual character is an NPC, then the second area type that the NPC can pass through (such as tower bridge, volcano and grassland) can be determined, and then the first attribute data corresponding to the second area type is determined.
[0099] The data processing method for pathfinding provided in an embodiment of the present application firstly marks attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate the area type of the scene model corresponding to the voxel grid, so that the voxel grids corresponding to all scene models in the game scene are marked with attribute data, so that it is possible to determine to which area type each voxel grid belongs; then, each target voxel grid corresponding to an area in which a virtual character belonging to at least one character type can walk in each of the voxel grids is determined, wherein the character type includes a player character type and a non-player character type, so that it is possible to determine from each of the voxel grids an area in which a player character and / or a non-player character can walk, except for an area inaccessible to the target virtual character; then, each of the target voxel grids is marked according to the attribute data corresponding to the target voxel grid. The voxel grid is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grid contained in each of the convex polygons is the same, so that connected convex polygons can be obtained, and each convex polygon has and only has one attribute data; finally, in response to the pathfinding instruction for the target virtual character, the first path to be moved by the target virtual character is determined from each first convex polygon with first attribute data in each of the convex polygons, wherein the area type indicated by the first attribute data is the area type that the target virtual character can pass through, since each of the obtained convex polygons has and only has one attribute data, and since the area type indicated by the first attribute data is the area type that the target virtual character can pass through, therefore, the first path determined in each first convex polygon with the first attribute data is the path that the target virtual character can walk. In this way, when there is a pathfinding demand for a certain target virtual character, the corresponding path can be queried from the convex polygons whose area type indicated by the attribute data is the area type that the target virtual character can pass through.
[0100] It can be seen that the data processing method for pathfinding provided in the embodiment of the present application can determine the pathfinding path for the target virtual character with different pathfinding needs by generating a connected convex polygon carrying attribute data. Compared with the current creation of multiple sets of pathfinding graphs for different pathfinding needs, on the one hand, the pathfinding data used to support pathfinding in this solution (that is, the convex polygons carrying attribute data) effectively reduces the storage space and reduces the loading time of the pathfinding data. On the other hand, if the scene model needs to be modified during the game operation, it is sufficient to redetermine the convex polygons carrying attribute data without re-baking and updating all pathfinding graphs, thereby reducing development and maintenance costs. It can be seen that the data processing method for pathfinding provided in the embodiment of the present application can effectively reduce the performance consumption in the pathfinding process, and the data processing method for pathfinding provided in the embodiment of the present application can control the target virtual character to efficiently and accurately complete automatic pathfinding in complex game scenes.
[0101] In an optional implementation manner, the data processing method in pathfinding provided in the embodiment of the present application may further include the following steps:
[0102] If the area types corresponding to two adjacent first convex polygons passed by the first path are different, the correspondence between the target path point and the target area type corresponding to the first target polygon is recorded, so that when the target virtual character enters the first target polygon from the target path point, the movement logic matching the target area type is called to give the target virtual character a movement performance;
[0103] Among them, the target path point is the common point of the first path on the two adjacent first convex polygons, and the first target polygon is the polygon located after the target path point in the two first convex polygons connected by the target path point.
[0104] It should be noted that the first path is a path from the starting position to the ending position and continuously passes through the first convex polygon, and the area types corresponding to the two adjacent first convex polygons passed by the first path may be the same or different. In the case where the area types of the two adjacent first convex polygons passed by the first path are different, the correspondence between the target path point and the target area type corresponding to the first target polygon can be recorded, wherein the target path point is the common point of the first path on the two adjacent first convex polygons, and the first target polygon is the polygon of the two adjacent first convex polygons that the first path passes through.
[0105] In this way, when the target virtual character moves to the target path point in the first path and enters the first target polygon from the target path point, the target area type corresponding to the first target polygon can be queried according to the corresponding relationship, and the movement logic matching the target area type can be called to give the target virtual character's movement in the first target polygon a corresponding movement performance, that is, to present a movement animation matching the first target polygon.
[0106] It should be noted that when the area types of two adjacent first convex polygons through which the target virtual character moves are the same, the movement logic used is the same set of movement logic, so that the movement performance in the two adjacent first convex polygons is the same.
[0107] like Figure 2 As shown, it is a schematic diagram of an example of a target path point on the first path in the data processing method in pathfinding provided by an embodiment of the present application. The first path is A→P12→B, wherein the two adjacent first convex polygons connected by the path point C on the first path are a river and a grassland, respectively, the two adjacent first convex polygons connected by the path point P12 on the first path are a grassland and a river, respectively, the two adjacent first convex polygons connected by the path point D on the first path are a river and a grassland, respectively, the two adjacent first convex polygons connected by the path point E on the first path are a grassland and a river, respectively, and the two adjacent first convex polygons connected by the path point F on the first path are a river and a grassland, respectively, so that the target path points included on the first path are C, P12, D, E and F, respectively.
[0108] Based on the attached Figure 2 The target path points shown in can obtain the corresponding relationship shown in Table 3 below:
[0109] Table 3.
[0110]
[0111]
[0112] Thus, in the above Table 3, when the target virtual character reaches point C and continues to move, the movement logic 1 for moving on the grass will be called to support the movement performance of the target virtual character, and the target virtual character continues to move between point C and point P12 according to the movement method corresponding to the movement logic 1; when the target virtual character reaches point P12 and continues to move, the movement logic 2 for moving on the river will be called to support the movement performance of the target virtual character, and the target virtual character continues to move between point P12 and point D according to the movement method corresponding to the movement logic 2; when the target virtual character reaches point D and continues to move, the movement logic 1 for moving on the grass will be called to support the movement performance of the target virtual character, and the target virtual character continues to move between point P12 and point D according to the movement method corresponding to the movement logic 2. The target virtual character's movement performance is supported, and the target virtual character continues to move between point D and point E according to the movement method corresponding to movement logic 1; when the target virtual character reaches point E and continues to move, movement logic 2 for moving on the river will be called to support the movement performance of the target virtual character, and the target virtual character continues to move between point E and point F according to the movement method corresponding to movement logic 2; when the target virtual character reaches point F and continues to move, movement logic 1 for moving on the grass will be called to support the movement performance of the target virtual character, and the target virtual character continues to move between point F and the end position B according to the movement method corresponding to movement logic 1.
[0113] In an embodiment of the present application, when a first path is generated for a target virtual character, the correspondence between the target path points and the target area types is recorded so that when the target virtual character moves along the first path, the corresponding movement logic can be called accurately and efficiently, thereby avoiding the target virtual character from moving using the same set of movement logic. While enriching the movement performance of the target virtual character, it is only necessary to execute the corresponding movement logic according to the correspondence, thereby reducing the performance consumption of the target virtual character when moving along the first path.
[0114] In an optional implementation, "determining the first path for the target virtual character to move from each first convex polygon having first attribute data among the convex polygons" in step S104 can be implemented by following steps S20 and S21.
[0115] Step S20: obtaining the current starting position of the target virtual character, and determining the target position to be moved to corresponding to the path-finding instruction;
[0116] Step S21: When the corresponding target position is determined for the pathfinding instruction, the starting position and the target position are used as the starting point and the ending point respectively, and the pathfinding logic is input, so that the pathfinding logic determines each first convex polygon with first attribute data from each convex polygon based on the type of the target virtual character, and outputs the corresponding first path located within each first convex polygon.
[0117] In the embodiment of the present application, in response to a pathfinding instruction for a target virtual character, it is first necessary to obtain the current starting position of the target virtual character and determine the target position to be moved to corresponding to the pathfinding instruction.
[0118] In step S20, "determining the target position to be moved to corresponding to the path-finding instruction" may specifically include the following steps S201 to S203:
[0119] Step S201: When the pathfinding instruction is an instruction issued by the player to the player character to automatically go to the destination to be reached, the destination is determined as the target position. For example, during the game, the player selects the destination b in the game scene, and issues a pathfinding instruction to the player character at the current position a to automatically go to the destination b. In this way, the destination b can be determined as the target position to be moved to.
[0120] Step S202: When the pathfinding instruction is an instruction generated by a pathfinding operation in which a player controls a player character to move, the target position to be moved to corresponding to the pathfinding instruction can be determined according to the operation attributes of the player's pathfinding operation.
[0121] Step S203: When the pathfinding instruction is an instruction for the NPC to move randomly in the game scene, reasonable positions to which the NPC can move can be determined from the game scene, and one position can be selected from the reasonable positions as the target position to be moved to corresponding to the pathfinding instruction.
[0122] It should be noted that the target position is the position to which the target virtual character can move. Specifically, in response to a pathfinding instruction for a player character, the target position determined is the position to which the player character at the starting position can move; in response to a pathfinding instruction for an NPC, the target position determined is the position to which the NPC at the starting position can move. For example, the area to which the player character can move includes grasslands, rivers, and mountains, and the area to which the NPC can move includes tower bridges, volcanoes, and grasslands. Then, the target position determined for the player character is a position in the area where the grassland, river, or mountain is located, and the target position determined for the NPC is a position in the area where the tower bridge, volcano, and grassland are located.
[0123] It should be noted that, when the corresponding target position is determined for the pathfinding instruction, the path between the starting position and the target position can be queried through the pathfinding logic. Exemplarily, in response to the pathfinding instruction for the target virtual character, the current starting position of the target virtual character is obtained as (0, 0, 0), and the target position to be moved to corresponding to the pathfinding instruction is determined to be (8, 8, 8). Then the path from (0, 0, 0) to (8, 8, 8) can be queried through the pathfinding logic, and the specific query method is the above step S21.
[0124] Specifically, the starting position can be used as the starting point, and the target position can be used as the ending point to input the path-finding logic, so that the path-finding logic determines each first convex polygon with first attribute data from each convex polygon based on the type of the target virtual character, and outputs the corresponding first path located within each first convex polygon.
[0125] It should be noted that the pathfinding logic may include multiple configuration variables, specifically role type variables, starting point variables, and ending point variables. The pathfinding logic may be encapsulated as a pathfinding interface. After the role type parameters, starting point parameters, and ending point parameters are passed to the pathfinding logic, the pathfinding logic may specifically determine the passable convex polygons corresponding to the role type parameters from each of the convex polygons according to the role type parameters, and query the farthest reachable path from the starting point corresponding to the starting point parameter and the ending point corresponding to the ending point parameter from the passable convex polygons corresponding to the role type parameters.
[0126] In an optional implementation, the above step S21 of "taking the starting position and the target position as the starting point and the ending point respectively, inputting the path finding logic, so that the path finding logic determines each first convex polygon having the first attribute data from each convex polygon based on the type of the target virtual character, and outputting the corresponding first path located within each first convex polygon" can be implemented in the following manner:
[0127] The starting position and the target position are used as the starting point and the ending point respectively, and input into the path finding logic;
[0128] The path-finding logic queries the type of area through which the target virtual character can pass according to the character configuration information, and determines the first attribute data corresponding to the type of area through which the target virtual character can pass;
[0129] Determine each of the first convex polygons having first attribute data from each of the convex polygons, and determine a first point for connecting the starting position and the target position from each of the first convex polygons;
[0130] The starting position, the first point and the target position are sequentially connected to generate a first path.
[0131] In a virtual game, role configuration information may be pre-set for various target virtual roles, and the role configuration information is at least used to indicate the type of area through which the corresponding target virtual role can pass.
[0132] In an optional embodiment, the above step of "determining each of the first convex polygons having the first attribute data from each of the convex polygons" can be: determining a target convex polygon whose attribute is the first attribute data and is connected from each of the convex polygons, and determining the target convex polygon as the first convex polygon.
[0133] As shown in Table 4, it is a schematic table of determining the first convex polygon based on the type of area through which the target virtual character can pass in the data processing method for pathfinding provided in an embodiment of the present application.
[0134] Table 4.
[0135]
[0136] In Table 4, according to the character configuration information of the player character, the types of areas that the player character can pass through are queried as grassland, river and mountain, and then the first attribute data corresponding to the types of areas that the player character can pass through are determined to be attribute data a, b, c, and finally, convex polygons 1 to 5 whose attribute data is one of a, b, and c are determined from each of the convex polygons; according to the character configuration information of the NPC, the types of areas that the NPC can pass through are queried as grassland, tower bridge and volcano, and then the first attribute data corresponding to the types of areas that the NPC can pass through are determined to be attribute data a, d, and e, and finally, convex polygons 5 to 10 whose attribute data is one of a, d, and e are determined from each of the convex polygons.
[0137] In another optional implementation, the above step of “determining each of the first convex polygons having the first attribute data from each of the convex polygons” may include the following steps:
[0138] Determine a starting polygon where the starting position is located from each of the convex polygons, and determine a terminating polygon where the target position is located from each of the convex polygons;
[0139] An intermediate polygon connecting the start polygon and the end polygon and having first attribute data is determined from each of the convex polygons, and the start polygon, the end polygon and the intermediate polygon are determined as a first convex polygon.
[0140] In the above method, each of the first convex polygons forms a connected area, wherein the first convex polygon corresponding to one end of the connected area is a convex polygon that accommodates the starting position, and the first convex polygon corresponding to the other end is a convex polygon that accommodates the target position.
[0141] After determining each of the first convex polygons, a first point for connecting the starting position and the target position can be determined from each of the first convex polygons, and finally, a straight line is used to connect the starting position, the first point, and the target position in sequence, thereby generating a first path. It should be noted that the first point is a point that allows the generated first path to be located in the connected area formed by each of the first convex polygons.
[0142] In an optional embodiment, the above step of "determining a first point for connecting the starting position and the target position from each of the first convex polygons" can specifically be: determining a first point for connecting the starting position and the target position from each of the first convex polygons based on the adjacent relationship between each of the first convex polygons.
[0143] In a specific implementation, the step of "determining a first point for connecting the starting position and the target position from each of the first convex polygons" can be implemented in the following manner:
[0144] Taking the starting position as an initial detection base point, taking the triangles in the first convex polygons adjacent to the starting triangle as initial triangles to be detected, and executing the first step, wherein the starting triangles are triangles in each of the first convex polygons that contain the starting position;
[0145] The first step includes:
[0146] Detect whether a line segment formed by the detection base point and any position point on the target edge of the triangle to be detected is located inside the connected area formed by each of the first convex polygons and passes through the triangle to be detected, wherein the target edge is a common edge between the triangle to be detected and the next adjacent triangle;
[0147] If not, the target vertex of the triangle to be detected is determined as the first point position, and when the next adjacent triangle is not a terminating triangle, the target vertex is used as the detection base point, and the next adjacent triangle is used as the triangle to be detected, and the first step is returned to be executed, wherein the target vertex is a vertex among the vertices of the triangle except the two end points of the target edge, and the terminating triangle is a triangle in each of the first convex polygons that contains the target position;
[0148] If yes, in the case that the next adjacent triangle is not the terminating triangle, continue to use the starting position as the initial detection base point, use the next adjacent triangle as the triangle to be detected, and return to execute the first step;
[0149] Until the triangles adjacent to the termination triangle in each of the first convex polygons are detected.
[0150] The following combination Figure 3 The first step above is described in detail:
[0151] like Figure 3 FIG. 1 is a schematic diagram of an example of searching for a first point in a data processing method for pathfinding provided in an embodiment of the present application, and includes the following steps:
[0152] The first step is to use the starting position A as the initial detection base point, triangle P 12 P 13 P2 is used as the initial triangle to be detected, and the target edge P is detected. 12 Is there a line segment on P2 that is formed with the starting position A and is located inside the connected area formed by the first polygons and passes through the triangle P? 12 P 13 The location point of P2;
[0153] Step 2: Find the line segment AP 12 Located inside the connected area formed by the first polygons and passing through the triangle P 12 P 13 P2;
[0154] Step 3: Continue to use the starting position A as the detection base point and place the triangle P3P 12 P2 is the triangle to be detected, and the target edge P is detected. 12 Is there a line segment on P3 formed with the starting position A that is located inside the connected area formed by the first polygons and passes through the triangle P3P 12 The location point of P2;
[0155] Step 4: Find the line segment AP3 that is inside the connected area formed by the first polygons and passes through the triangle P3P 12 P2;
[0156] Step 5: Continue to use the starting position A as the detection base point and make the triangle P4P 12 P3 is the triangle to be detected, and the target edge P is detected. 12 Is there a line segment on P4 formed with the starting position A located inside the connected area formed by the first polygons and passing through the triangle P4P 12The location point of P3;
[0157] Step 6: Find that line segment AP4 is located inside the connected area formed by the first polygons and passes through triangle P4P 12 P3;
[0158] Step 7: Continue to use the starting position A as the detection base point and make the triangle P4P 11 P 12 As the triangle to be detected, the detection target edge P 11 Is there a line segment on P4 formed with the starting position A located inside the connected area formed by the first polygons and passing through the triangle P4P 11 P 12 The location point;
[0159] Step 8. Target edge P 11 There is no line segment on P4 that is formed with the starting position A and is located inside the connected area formed by the first polygons and passes through the triangle P4P 11 P 12 The location point;
[0160] Step 9. P4P the triangle 11 P 12 Except for the target edge P 11 The target vertex P is outside the two vertices in P4 12 Determine as the detection base point, and place the triangle P5P 11 P4 is used as the triangle to be detected, and the target edge P5P is detected. 11 Whether there is a detection base point P on 12 The line segment is located at a point inside the connected area formed by each of the first polygons and passes through the triangle P5P 11 Position point of P4;
[0161] Step 10: Find line segment P 12 P5 is located inside the connected area formed by the first polygons and passes through the triangle P5P 11 P4;
[0162] Step 11: Continue to 12 As the detection base point, the triangle P 10 P 11 P5 is the triangle to be detected, and the target edge P is detected. 10 Whether there is a detection base point P on P5 12 The line segment is located inside the connected area formed by each of the first polygons and passes through the triangle P 10 P 11 Position point of P5;
[0163] Step 12: Find line segment P 12 P 10 Located inside the connected area formed by the first polygons and passing through the triangle P 10 P 11 P5;
[0164] Step 13: Continue to add P 12 As the detection base point, the triangle P6P 10 P5 is used as the triangle to be detected, and the target edge P6P is detected. 10 Whether there is a detection base point P on 12 The line segment formed by the first polygons is located inside the connected area formed by the first polygons and passes through the triangle P6P 10 Position point of P5;
[0165] Step 14: Find line segment P 12 P6 is located inside the connected area formed by the first polygons and passes through the triangle P6P 10 P5;
[0166] Step 15: Continue to add P 12 As the detection base point, the triangle P6P9P 10 As the triangle to be detected, whether there is a triangle on the detection target edge P6P9 that is consistent with the detection base point P 12 The line segment formed by the first polygons is located inside the connected area formed by the first polygons and passes through the triangle P6P9P 10 The location point;
[0167] Step 16: Find P 12 The line segment formed by the point on the target edge P6P9 is located inside the connected area formed by each of the first polygons and passes through the triangle P6P9P 10 ;
[0168] Step 17: Continue to add P 12 As the detection base point, take triangle P6P7P9 as the triangle to be detected, and detect whether there is a triangle on the target edge P7P9 that is consistent with the detection base point P 12 The formed line segment is located inside the connected area formed by the first polygons and passes through the position point of the triangle P6P7P9;
[0169] Step 18: Find P 12 The line segment formed by the point on the target edge P7P9 is located inside the connected area formed by the first polygons and passes through the triangle P6P7P9. Since the triangle P6P7P9 is adjacent to the terminating triangle P8P7P9, the detection is terminated.
[0170] Step 19: Move the target vertex P 12 Determine the first point.
[0171] Regarding the above Figure 3 , connect the starting position A and the first point P 12 , connect the first point P 12 and the target position B, thus obtaining the first path A→P 12 →B.
[0172] It should be noted that in the prior art, when searching for pathfinding paths through a physics engine, in order to maintain collision detection, it leads to consumption caused by operations such as maintaining a quadtree structure and dynamically adding and deleting objects. In addition, the physical simulation and constraints in the physics engine also require a large performance consumption. In contrast, in the embodiment of the present application, by generating each of the convex polygons with attribute data, the pathfinding path can be searched based on the attribute data, thereby avoiding the high consumption of the physics engine.
[0173] The above step S202 and step S203 are respectively described in detail below.
[0174] The following combination Figure 4 Step S202 is introduced as follows. Figure 4 , which is a flowchart of determining a target position for a player character in a path-finding data processing method provided in an embodiment of the present application, including steps S401 to S405.
[0175] The target virtual character is a player character, the starting position currently located by the player character is a first starting position, the pathfinding instruction is an instruction generated by the player controlling the player character to perform a pathfinding operation, and the above step of "determining the target position to be moved to corresponding to the pathfinding instruction" can be generated by the following steps:
[0176] Step S401: Determine a first distance corresponding to the path-finding operation and a first direction to be moved;
[0177] Step S402: determining a first position whose distance from the first starting position is the first distance and whose direction with the first starting position is the first direction;
[0178] Step S403: determining whether the first position is a position that the player character at the first starting position can reach;
[0179] Step S404: If yes, determine the first position as the target position.
[0180] It should be noted that the determined first position is a position on the same horizontal plane as the first starting position. The first distance and the first direction can be determined by the operation attributes corresponding to the pathfinding operation. Specifically, when the pathfinding operation is an operation performed through the keyboard, the first distance can be positively correlated with the pressing time of the shortcut key on the keyboard used to control the movement of the target virtual character. The longer the pressing time, the larger the first distance, and vice versa. The first direction can be determined according to the shortcut key pressed, such as pressing the "up, down, left, and right" key or pressing the "WSAD" key to represent moving up, down, left, and right respectively; when the pathfinding operation is a sliding operation performed by a finger on a touch-sensitive screen, the first distance can be proportional to the sliding distance of the sliding operation. The larger the sliding distance, the larger the first distance, and vice versa. The first direction can be the same as the sliding direction of the sliding operation.
[0181] It should be noted that the determination of the first distance and the first direction is not limited to the above-mentioned manner.
[0182] Afterwards, a position point located in the first direction of the first starting position and at a first distance from the first starting position may be determined as the first position. For example, if the determined first direction is 45 degrees to the right and the first distance is 5 meters, then a position located 45 degrees to the right and 5 meters from the first starting position may be determined as the first position.
[0183] Afterwards, it can be determined whether the first position is a position that the player character can reach. It should be noted that the first position is not a position that the player character can reach, including at least the following situations: the first position is located inside an obstacle, making the first position unreachable, the first position is located in the air, making the first position unreachable, and the first position is located in an area that the player character cannot reach.
[0184] When the first position is a position that the player character can reach, the first position may be determined as the target position.
[0185] In an optional implementation, the above step of "determining whether the first position is a position that the player character at the first starting position can reach" can be implemented in the following manner:
[0186] The first starting position and the first position are used as a starting point and an ending point respectively, and input into the path finding logic, so that the path finding logic outputs a corresponding second path;
[0187] If the end point of the second path is the first position, the result of determining whether the first position is a position that the player character at the first starting position can reach is yes;
[0188] If the end point of the second path is not the first position, the result of determining whether the first position is a position that the player character at the first starting position can reach is no.
[0189] In a specific implementation, the “using the first starting position and the first position as a starting point and an ending point respectively, and inputting the path finding logic so that the path finding logic outputs a corresponding second path” includes the following steps:
[0190] The first starting position and the first position are used as a starting point and an ending point, respectively, and input into the path finding logic;
[0191] The path-finding logic determines the farthest reachable path from the first starting position to the first position from each of the convex polygons according to the type of area through which the player character can pass, and determines the farthest reachable path from the first starting position to the first position as the second path.
[0192] As can be seen from the above introduction, for the starting point and the ending point of the path finding logic input, the path finding logic can query the target location point that is as close to the ending point as possible and reachable by the target virtual character, and output a path with the starting point as the starting point and the target location point as the end point.
[0193] In this way, when the first starting position and the first position are respectively used as the starting point and the ending point and the pathfinding logic is input, the pathfinding logic will look for a target position point that is as close to the first position as possible and reachable by the player character. Specifically, when the first position is a position point that is reachable by the player character, the target position point found by the pathfinding logic is the first position; when the first position is a position point that is unreachable by the player character, the target position point found by the pathfinding logic is the position point that is closest to the first position and reachable by the player character.
[0194] Afterwards, the path finding logic will output the longest reachable path from the first starting position to the first position, i.e., the second path. When the end point of the second path is the first position, it means that the first position is a position that the player character can reach; when the end point of the second path is not the first position, it means that the first position is not a position that the player character can reach.
[0195] Through the generated pathfinding logic, it is possible to quickly and easily query whether the first position is a position that the player character can reach, thereby improving the efficiency of the pathfinding process and reducing the performance consumption in the pathfinding process.
[0196] In an optional implementation manner, the data processing method in pathfinding provided in the embodiment of the present application may further include the following steps:
[0197] Step S405: If not, the first position is corrected to obtain a corrected position, so that the corrected position belongs to a position that the player character at the first starting position can reach, and the corrected position is determined as the target position.
[0198] In the embodiment of the present application, correcting the first position may include height correction and distance correction.
[0199] In the embodiment of the present application, if the first position is not a position that the player character can reach, the first position can be corrected first, and the principle of the correction is to keep the direction component of the direction between the corrected position and the first position on the horizontal plane as the first direction. In this way, when the player character moves, it always moves towards the corrected position, and the direction between the starting point and the end point on the horizontal line is consistent with the first direction corresponding to the path-finding operation, which meets the player's expectations and improves the player's gaming experience.
[0200] In an optional implementation, each of the convex polygons fits the ground surface, and the height correction specifically includes the following steps:
[0201] Performing altitude correction on the first position to obtain an altitude-corrected position, so that the altitude-corrected position is located on the ground surface;
[0202] Determining whether the position after the height correction is a position that the player character at the first starting position can reach;
[0203] If so, the position after the height correction is determined as the corrected position.
[0204] It should be noted that when the first position is not a position that the player character can reach, the first position can be corrected in height to obtain a position with a corrected height, that is, the first position is corrected to a position point on the surface of the ground, so as to ensure that the position point to be reached is a reasonable position on the surface of the ground.
[0205] For example, the height of the first position is (8, 0, 8), the height is 0, (8, 0, 8) is below the ground surface, then the height of the position (8, 0, 8) can be corrected, assuming that the position after the corrected height is (8, 3, 8), that is, the position (8, 3, 8) is on the ground surface.
[0206] In a specific implementation, the position after the height correction may be a position that the player character can reach, or a position that the player character cannot reach. For example, the first position determined is located inside a mountain, and the position after the height correction is located on the surface of the mountain, which is a position that the player character can reach. For another example, the first position determined is located in the air above a tower bridge, and the position after the height correction is located on the surface of the tower bridge, which is a position that the player character cannot reach.
[0207] It should be noted that the method of determining whether the position after the height correction is a position that the player character can reach is the same as the method of determining whether the first position is a position that the player character can reach, and will not be elaborated here.
[0208] When the position after the height correction is a position that the player character can reach, the position after the height correction can be determined as the target position, so that the path finding logic can output a reachable path from the first starting position to the position after the height correction.
[0209] In a specific implementation, the above step of “correcting the height of the first position to obtain a position after the height correction” may include the following steps:
[0210] Acquire horizontal coordinate data of two axes of the first position on a horizontal plane;
[0211] Determine the height coordinate data corresponding to the horizontal coordinate data on the ground surface according to the vertex data of the convex polygon corresponding to the horizontal coordinate data;
[0212] The position indicated by the coordinates composed of the horizontal coordinate data and the height coordinate data is determined as the position after the height is corrected.
[0213] It should be noted that the convex polygon corresponding to the horizontal coordinate data refers to a convex polygon that contains a ground surface position whose horizontal coordinates are the horizontal coordinate data.
[0214] In the embodiment of the present application, the horizontal coordinate data other than the height coordinate data in the three-dimensional coordinates of the first position can be first obtained, and then the convex polygon corresponding to the horizontal coordinate data is determined from each of the convex polygons, and the height coordinate data corresponding to the horizontal coordinate data on the ground surface is determined based on the vertex data of the convex polygon. Finally, the position indicated by the coordinates composed of the horizontal coordinate data and the height coordinate data is determined as the position after the height correction.
[0215] Exemplarily, the three-dimensional coordinates of the first position are (-99, 50, 98). A convex polygon corresponding to the horizontal coordinate data (-99, 98) is determined from each of the convex polygons. Assuming it is a triangle, the three vertices of the triangle are (-99, -99, -99), (99, 99, 99), and (-99, 99, 99). In this way, the height coordinate data corresponding to the horizontal coordinate data (-99, 98) on the triangle is 96, and the first position (-99, 50, 98) can be corrected to (-99, 96, 98).
[0216] By performing an altitude correction on the first position so as to correct the first position to a position on the ground surface, when the position after the altitude correction is a position reachable by the player character, the pathfinding operation in which the player controls the player character to move can enable the player character to move along the ground surface in the expected first direction, meeting the player's movement expectations.
[0217] In an optional implementation manner, the distance correction specifically includes the following steps:
[0218] If the result of determining whether the position after the height correction is within the reachable position of the player character at the first starting position is no, the first distance is expanded based on the distance expansion parameter to obtain a second distance;
[0219] Determine a position whose distance from the first starting position is the first distance and whose direction with the first starting position is the corrected distance of the first direction;
[0220] Determining whether the position after the distance correction is a position that the player character at the first starting position can reach;
[0221] If so, the position after the distance correction is determined as the corrected position.
[0222] In the embodiment of the present application, when the position after the height correction is a position that is unreachable by the player character, it means that the position after the height correction is located in an area that is unreachable by the player character. At this time, the distance correction can be performed on the first position.
[0223] In a specific implementation, the first distance may be expanded based on the distance extension parameter to obtain a corresponding second distance. The distance extension parameter may include but is not limited to at least one of an additional distance and a distance multiple, the distance multiple may be, for example, 20 times, 30 times, or 40 times, and the additional distance may be, for example, 20 meters, 30 meters, or 40 meters.
[0224] For example, the first distance is 5 meters. When the distance extension parameter is a distance multiple and the distance multiple is 30 times, the second distance is 150 meters. When the distance or parameter is an additional distance and the additional distance is 30 meters, the second distance is 35 meters.
[0225] In a specific implementation, a position whose distance from the first starting position is the first distance and whose direction with the first starting position is the first direction may be determined as the position after the distance correction.
[0226] In another specific implementation, a position whose distance from the first starting position is the first distance, whose direction component on the horizontal plane formed with the first starting position is the first direction, and which is located on the ground surface can be determined as the position after the distance correction.
[0227] Afterwards, similar to the aforementioned determination of whether the first position is a position reachable by the player character, the path-finding logic can be used to determine whether the position after the corrected distance belongs to a position reachable by the player character at the first starting position. This determination method can refer to the determination of whether the first position is a position reachable by the player character, which will not be elaborated here.
[0228] In the case where the position after the corrected distance is a position that the player character can reach, the position after the corrected distance may be determined as the corrected position.
[0229] By expanding the first distance, the player character can bypass the impassable area in the first direction as much as possible and reach a position in the first direction or a position whose horizontal component is the corrected distance in the first direction. In this way, the direction between the starting point and the end point on the horizontal line is consistent with the first direction corresponding to the pathfinding operation, which meets the player's expectations and enhances the player's gaming experience.
[0230] In an optional implementation manner, the data processing method in pathfinding provided in the embodiment of the present application may further include the following steps:
[0231] If the result of determining whether the position after the distance correction is a position that the player character at the first starting position can reach is no, it is determined that the corresponding target position has not been determined for the pathfinding instruction, and the first starting position is determined as the player position corresponding to the first frame, and the second step is performed for the i-th frame, wherein i traverses 1 to n, and the total distance moved by the player character from the first frame to the n-th frame is the first distance;
[0232] The second step comprises:
[0233] Determine the turning point as the intersection point between the ray formed by the player position of the player character at the beginning of the i-th frame along the first direction and the surface of the obstacle when the ray reaches the surface of the obstacle, wherein the turning point is located on the ground surface;
[0234] Determining the normal direction of the obstacle at the turning point;
[0235] Removing a first direction component opposite to the normal direction from the first direction to obtain a second direction component perpendicular to the normal direction, and determining the second direction component as the direction in which the player character is to move at the turning point;
[0236] The player character is controlled to move from the player position along the first direction to the turning point in the i-th frame, and to move from the turning point along the direction to be moved.
[0237] In the embodiment of the present application, when the pathfinding instruction for the player character fails to determine the corresponding target position, it indicates that the unreachable area in the first direction cannot be bypassed after the distance is extended. For example, the unreachable area in the first direction is an abyss, and the other side of the abyss is unreachable. At this time, the player character can be controlled to move along the edge of the unreachable area.
[0238] For the i-th frame in the path-finding process, first, the position on the surface of the obstacle reached from the player's position along the first direction can be determined as the turning point, and then the normal direction of the obstacle at the turning point is determined; then, the first direction is decomposed into a first direction component opposite to the normal direction and a second direction component perpendicular to the normal direction, the second direction component is retained, and the second direction component is determined as the direction in which the player character is to move at the turning point.
[0239] In this way, when the player character actually moves, the player character can be controlled to move from the player position along the first direction to the turning point in the i-th frame, and then move from the turning point along the direction to be moved.
[0240] When the position after the corrected distance is still an unreachable position for the player character, the player character is controlled to move in a manner close to the edge of the obstacle, thereby avoiding the problem of poor player experience caused by the player character's movement being directly hindered after the player character moves to the turning point.
[0241] The above is the introduction of step S202.
[0242] The following is an introduction to step S203:
[0243] In an optional implementation, the target virtual character is an NPC, and the starting position currently located by the NPC is the second starting position; the step of "determining the target position to be moved to corresponding to the path-finding instruction" may include the following steps:
[0244] Dividing the game scene into unit grids;
[0245] Determine, from the unit grid, a grid area whose distance from the second starting position is within a preset range;
[0246] A target grid that the NPC can reach is determined from the grid area, and a position in the target grid is determined as the target position.
[0247] For the NPC, determining the target position refers to determining a reasonable position that the NPC can reach, and the distance between the reasonable position and the second starting position where the NPC is currently located is within a preset range.
[0248] In the embodiment of the present application, the ground surface in the game scene can be divided into smaller unit grids, such as 1 meter * 1 meter unit grids, so as to find a grid area whose distance from the first starting position is within the preset range. The grid area whose distance from the first starting position is within the preset range can be: a grid area composed of unit grids whose distance from the center of the grid to the first starting position is within the preset range.
[0249] Afterwards, a target grid that is reachable from the NPC is determined from the grid area, and any position in the target grid (such as the center of the grid) is determined as the target position.
[0250] In this way, by dividing the surface into unit grids and selecting a reasonable position that meets the requirements and is reachable by the NPC, the speed of determining the target position to be moved to for the NPC when the NPC is pathfinding is improved.
[0251] In an optional implementation manner, determining from the unit grid a grid area whose distance from the second starting position is within a preset range may be implemented according to the following steps:
[0252] A grid area whose Manhattan distance from the second starting position is within a preset range consisting of a first distance threshold and a second distance threshold is determined from the unit grid.
[0253] In the embodiment of the present application, the location point whose Manhattan distance from the second starting location is within a grid area within a preset range composed of a first distance threshold and a second distance threshold and which is reachable by the NPC is the target location.
[0254] Manhattan distance is a method of measuring the distance between two points in a grid or grid layout. In two-dimensional space, if there are two points A and B, then the Manhattan distance between them can be calculated according to the following formula (1):
[0255] d=|x a -x b |+|y a -y b | Formula (1)
[0256] Where d is the Manhattan distance between A and B, (x a ,y a ) is the coordinate of A, (x b ,y b ) are the coordinates of B.
[0257] Assuming that the first distance threshold is l1 and the second distance threshold is l2, the position point in the grid area can be determined according to the following formula (2):
[0258] l1≤|x-x1|+|y-y1|≤l2 Formula (2)
[0259] The second starting position where the NPC is currently located is (x1, y1), and the position point in the grid area is (x, y).
[0260] like Figure 5 As shown, it is a schematic diagram of an example of a grid area in the data processing method in pathfinding provided by an embodiment of the present application, wherein point C is the second starting position of the NPC, and the gray square ring area formed by the large diamond and the small diamond at point C is the grid area, wherein point C is the center of the large diamond and the small diamond, half of the diagonal of the small diamond is the first distance threshold L1, and half of the diagonal of the large diamond is the second distance threshold L2. The range of the grid area is determined based on the above formula (2).
[0261] In the embodiment of the present application, the target position is Figure 5 The gray square ring area in the figure shows the locations that the NPC can reach.
[0262] In an optional implementation, dividing the game scene into unit grids may include the following steps:
[0263] Dividing the game scene into unit grids, and marking first identification information on grids in the unit grids that are reachable by the NPC;
[0264] Correspondingly, the determining of the target grid that is reachable by the NPC from the grid area may be implemented according to the following steps: determining the target grid having the first identification information from the grid area.
[0265] The grid in the unit grid that is unreachable by the NPC may not be marked, or may be marked as the second identification information. In order to more clearly introduce the embodiments of the present application, in the subsequent content of the present application, the grid in the unit grid that is unreachable by the NPC is introduced as the second identification information.
[0266] In an embodiment of the present application, unit grids can be marked as obstacles, so that each unit grid has corresponding marking information. The marking information can be used to quickly locate which unit grids belong to the grids reachable by the NPC, thereby accurately and efficiently determining the target grid.
[0267] In a specific implementation manner, marking the first identification information of the grids reachable by the NPC in the unit grid may be implemented by the following steps:
[0268] Selecting a reference grid reachable by the NPC from the unit grid;
[0269] For the jth grid, determine whether the reference grid and the jth grid are reachable, wherein the jth grid is a grid to be marked in the unit grid except the reference grid, j traverses 1 to m, and m is the number of grids to be marked;
[0270] If so, mark the j-th grid with the first identification information.
[0271] Correspondingly, if the result of determining whether the reference grid and the j-th grid are reachable is no, the j-th grid may be marked with second identification information.
[0272] When marking each unit grid, a reference grid can be selected first. The reference grid is a grid that the NPC can reach. Usually, the player's birth point is a grid that each NPC can reach. The player's birth point can be selected as the reference grid. After that, for the jth grid in the unit grid except the reference grid, determine whether the jth grid is reachable relative to the reference grid. If so, the jth grid is marked as the first marking data, such as 1, indicating that the jth grid is an open space. If not, the jth grid is marked as the second marking data, such as -1, indicating that the jth grid is an obstacle.
[0273] It should be noted that the reachability between the base grid and the j-th grid means that the NPC can move from the base grid to the j-th grid, and the unreachability between the base grid and the j-th grid means that the NPC cannot move from the base grid to the j-th grid.
[0274] As described above, the marking of whether each unit grid is an obstacle is completed. In this way, a position can be selected from the target grid marked as the first marking data in the grid area as the target position to which the NPC is to move.
[0275] In a specific implementation, the determining whether the reference grid is reachable from the j-th grid may be implemented according to the following steps:
[0276] The center position of the reference grid and the center position of the j-th grid are respectively used as a starting point and an ending point, and input into the path-finding logic, so that the path-finding logic outputs a corresponding third path;
[0277] If the end point of the third path is the center position of the j-th grid, the result of determining whether the reference grid and the j-th grid are reachable is yes;
[0278] If the end point of the second path is not the center position of the j-th grid, the result of determining whether the reference grid and the j-th grid are reachable is no.
[0279] Specifically, taking the center position of the reference grid and the center position of the j-th grid as the starting point and the ending point respectively, and inputting them into the path finding logic so that the path finding logic outputs the corresponding third path may include the following steps:
[0280] The center position of the reference grid and the center position of the j-th grid are respectively used as the starting point and the ending point, and input into the path finding logic;
[0281] The path-finding logic determines the farthest reachable path from the center position of the reference grid to the center position of the j-th grid from each of the convex polygons according to the type of area through which the NPC can pass, and determines the farthest reachable path from the center position of the reference grid to the center position of the j-th grid as the third path.
[0282] It should be noted that the determination of whether the center position of the reference grid and the center position of the j-th grid are reachable through the path-finding logic is the same as the determination principle of whether the first position is reachable through the path-finding logic mentioned above, and can be referred to the above description, which will not be repeated here.
[0283] In an optional implementation, determining the target grid having the first identification information from the grid area may include the following steps:
[0284] Constructing a corresponding two-dimensional segment tree according to identification information of the unit grid, wherein the identification information is one of the first identification information and the second identification information;
[0285] A target mesh having the first identification information is determined from the mesh area according to the two-dimensional segment tree.
[0286] A two-dimensional segment tree is a data structure that is mainly used to solve query or update problems on intervals (or rectangular areas) on a two-dimensional plane, such as counting the number of points in a rectangular area, solving the maximum or minimum value in a rectangular area, etc. A two-dimensional segment tree is essentially a quadtree, where each node represents a rectangular area and stores a value related to the rectangular area (called a domain). This value is usually information that needs to be queried or maintained, such as the sum of elements in the interval, the maximum value, the minimum value, etc.
[0287] When constructing a two-dimensional segment tree, it starts with a large rectangle (the entire query area) and continuously divides it into smaller rectangles until it reaches the basic unit (usually a 1x1 cell). When querying or updating, the algorithm starts from the root node and decides whether to continue to drill down to the child node or directly return the information of the current node based on the relationship between the query rectangle or update area and the rectangle representing the current node (whether they intersect, are completely contained, etc.). The divide-and-conquer strategy is used to efficiently locate the relevant area, ensuring that the time complexity of query and update operations is at the logarithmic level.
[0288] In the grid area Figure 5 In the case of the gray square ring area shown in FIG. 1 , determining the target grid having the first identification information from the grid area according to the two-dimensional line segment tree can be specifically implemented according to the following steps:
[0289] Rotate the grid area by 45 degrees around the coordinate origin in the direction of the target clockwise direction to obtain a rotated grid area, wherein the target clockwise direction is one of clockwise and counterclockwise;
[0290] Querying the maximum value in the rotated grid area from the two-dimensional line segment tree, and determining the grid corresponding to the maximum value as the rotated target grid;
[0291] The rotated target grid is rotated 45 degrees around the coordinate origin in a direction opposite to the target clockwise direction to obtain the target grid.
[0292] In the embodiment of the present application, the grid area can be rotated 45 degrees counterclockwise around the coordinate origin, or the grid area can be rotated 45 degrees clockwise around the coordinate origin.
[0293] like Figure 6 , which is a schematic diagram of the grid area after being rotated in the data processing method for pathfinding provided in an embodiment of the present application. Figure 6 Is to attach Figure 5 The mesh area in the figure is rotated to obtain the rotated mesh area. The rotated mesh area is as shown in the attached figure. Figure 6 The gray square ring area shown in .
[0294] It should be noted that the attached Figure 5 The grid area shown cannot meet the query conditions of the two-dimensional segment tree. By rotating the grid area, a rotated grid area is obtained in which the horizontal coordinates of the upper left corner and the lower left corner are the same, the vertical coordinates of the upper left corner and the upper right corner are the same, the horizontal coordinates of the upper right corner and the lower right corner are the same, and the vertical coordinates of the lower left corner and the lower right corner are the same. In this way, the two-dimensional segment tree can be successfully queried based on the rotated grid area.
[0295] It should be noted that, since the queried grid (rotated target grid) is a grid rotated 45 degrees around the coordinate origin in the direction of the target clock, when determining the target position, it is necessary to rotate the queried grid (rotated target grid) 45 degrees around the coordinate origin in the opposite direction of the target clock to obtain the target grid, and determine any position in the target grid (such as the center position of the grid) as the target position.
[0296] In the embodiment of the present application, a corresponding two-dimensional segment tree is constructed based on the identification information of the unit grid, so as to determine the target grid with the first identification information from the grid area according to the two-dimensional segment tree. Figure 5 All unit grids in the gray square ring shown can effectively improve the efficiency of querying the target grid through a two-dimensional segment tree.
[0297] In an optional implementation, constructing a corresponding two-dimensional segment tree according to identification information of each unit grid in the grid area may include the following steps:
[0298] Rotate each unit grid in the grid area by 45 degrees around the coordinate origin in the direction of the target clock to obtain a rotated unit grid, wherein the identification information of each unit grid remains unchanged before and after the rotation;
[0299] A corresponding two-dimensional segment tree is constructed based on the identification information of the rotated unit grid.
[0300] The following is an introduction to a method for constructing a corresponding two-dimensional segment tree based on the identification information of the rotated unit grid in the data processing method for pathfinding provided in an embodiment of the present application:
[0301] Step S501: Create a root node corresponding to the rectangular area;
[0302] Take the root node as the initial parent node and perform the following third step:
[0303] The third step includes steps S502 to S505:
[0304] Step S502: Divide the rectangle corresponding to the parent node into four sub-rectangles, each sub-rectangle corresponding to a child node;
[0305] Step S503: setting node attributes of the corresponding sub-nodes according to each sub-rectangle, the node attributes include area range, maximum value and maximum value grid id (number), wherein the area range is the coordinate range (start_x, end_x, start_y, end_y) of the corresponding sub-rectangle, the maximum value is the maximum value in the corresponding sub-rectangle, and the maximum value grid id is the number of the unit grid corresponding to the maximum value;
[0306] Step S504: for a first child node including only one unit grid in the child nodes, use the identification information of the unit grid included in the first child node as the maximum value of the first child node, and use the number of the unit grid included in the first child node as the maximum value grid id of the first child node;
[0307] Step S505: for the second child node including multiple unit grids in the child node, recursively construct a child node. Specifically, take the second child node as the parent node and execute the third step until start_x>end_x, or start_y>end_y (each divided child node includes only one unit grid), and the recursion ends;
[0308] Step S506: backtrack and update node attributes; specifically, update the maximum value and maximum value grid id of non-leaf nodes, and for each non-leaf node, take the largest value among the maximum values corresponding to all its child nodes as the maximum value of the non-leaf node, and take the maximum value grid id of the child node corresponding to the largest value as the maximum value grid id of the non-leaf node, wherein the non-leaf node is a node among all nodes except the first child node; that is, the non-leaf node contains multiple unit grids.
[0309] The above constructs a two-dimensional segment tree corresponding to a rectangular area.
[0310] The final constructed two-dimensional line segment tree will be able to quickly query the maximum value in the corresponding rectangle and determine the corresponding maximum value grid ID, thereby determining the target grid without traversing the entire grid. This tree structure ensures the efficiency of query operations, especially for large grids and frequent query operations.
[0311] Assuming that there are n*m grids in the grid area, the time complexity of traversing all unit grids to query the target grid is O(nm). As the size of the grid area increases, the time required will increase linearly. For frequent queries, this method will lead to performance bottlenecks. By building a two-dimensional segment tree, after the two-dimensional segment tree is built, the maximum value in the grid area can be found through a series of recursive queries without directly accessing each unit grid in the grid area. The time complexity of this query is O(log n*logm). In this way, even if the size of the grid area increases, the query time increases very slowly.
[0312] The steps to query the target grid in the grid area based on the 2D segment tree are as follows:
[0313] Step S601: Initialize the query range; take the root node of the two-dimensional line segment tree as the initial parent node and execute the fourth step:
[0314] The fourth step includes the following steps S602 to S605:
[0315] Step S602: Determine whether the area range of the parent node overlaps with the query range;
[0316] Step S603: If the area range of the parent node completely includes the query range, start from the root node and search downward layer by layer. Each time a node is encountered, determine whether the node overlaps with the query range; if so, check the child nodes of the node;
[0317] Step S604: if the area range of the child node is completely within the query range, the maximum value grid ID of the child node is returned;
[0318] Step S605: If the range of the child node is partially within the query range, then continue to recursively search the child node. Specifically, take the child node as the parent node and return to execute step 4.
[0319] During the recursive search process, if it is found that the range of a child node is completely within the query range, while returning the maximum value grid id of the child node, backtrack to the corresponding parent node and use the maximum value grid id of the child node as the maximum value grid id of the corresponding parent node.
[0320] Step S606: during the entire recursive search process, the maximum value grid IDs corresponding to all sub-nodes whose maximum values are the first identification information are collected, and the corresponding target grid can be determined through the maximum value grid IDs.
[0321] The core process of determining the target location for the NPC's pathfinding instructions is summarized as follows:
[0322] Step 1: Divide the surface 1 of the game scene into unit grids, and mark the unit grids as obstacles to obtain surface 2 with marking information for each unit grid, and rotate surface 2 45 degrees around the origin in the direction of the target clock to obtain surface 3 with marking information for each unit grid;
[0323] Step 2: construct a two-dimensional segment tree based on the label information of each unit grid in the surface 3;
[0324] Step 3: Rotate the NPC's current second starting position by 45 degrees around the origin in the target clockwise direction, and determine the grid area (also called the wandering point area) based on the NPC's current second starting position;
[0325] Step 4: Query the grid 1 that does not belong to an obstacle in the grid area according to the two-dimensional line segment tree;
[0326] Step 5. Rotate grid 1 45 degrees in the opposite direction of the target clock to obtain the rotated grid 1, which is the target position (also known as the NPC's wandering point).
[0327] By rotating the unit grid, the constructed two-dimensional segment tree is generated based on the rotated unit grid, so that the information corresponding to the two-dimensional segment tree is unified with the information of all queried grid areas, thereby ensuring the accuracy of the query.
[0328] It should be noted that the examples provided in the embodiments of the present application are intended to provide a clearer explanation of the present application and are not intended to limit the present application.
[0329] Corresponding to the data processing method in pathfinding provided in the first embodiment of the present application, the second embodiment of the present application further provides a data processing device in pathfinding, such as Figure 7 As shown, the data processing device 700 in the path finding includes:
[0330] A marking unit 701 is used to mark attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid;
[0331] A first determining unit 702 is used to determine each target voxel grid corresponding to a walkable area of a virtual character belonging to at least one character type in each voxel grid, wherein the character type includes a player character type and a non-player character type;
[0332] A division unit 703 is used to divide each target voxel grid into connected convex polygons according to the attribute data corresponding to the target voxel grid, wherein the attribute data corresponding to the target voxel grid contained in each convex polygon is the same;
[0333] The second determination unit 704 is used to determine, in response to a path-finding instruction for a target virtual character, a first path for the target virtual character to move from each first convex polygon having first attribute data in each convex polygon, wherein the area type indicated by the first attribute data is an area type through which the target virtual character can pass.
[0334] Optionally, the data processing device 700 in the pathfinding further includes a recording unit, and the recording unit is used to:
[0335] If the area types corresponding to two adjacent first convex polygons passed by the first path are different, the correspondence between the target path point and the target area type corresponding to the first target polygon is recorded, so that when the target virtual character enters the first target polygon from the target path point, the movement logic matching the target area type is called to give the target virtual character a movement performance;
[0336] Among them, the target path point is the common point of the first path on the two adjacent first convex polygons, and the first target polygon is the polygon located after the target path point in the two first convex polygons connected by the target path point.
[0337] Optionally, the data processing device 700 in the pathfinding further includes a generating unit, and the generating unit is used to:
[0338] Generate a path-finding logic that includes each of the convex polygons, and each of the convex polygons carries corresponding attribute data, wherein the path-finding logic is used to query the farthest reachable path of the target virtual character from the starting point to the end point in the connected area composed of each of the convex polygons according to the attribute data.
[0339] Optionally, the second determining unit 704 is specifically configured to:
[0340] Obtaining the current starting position of the target virtual character, and determining the target position to be moved to corresponding to the path-finding instruction;
[0341] When the corresponding target position is determined for the pathfinding instruction, the starting position and the target position are used as the starting point and the ending point respectively, and the pathfinding logic is input so that the pathfinding logic determines each first convex polygon with first attribute data from each convex polygon based on the type of the target virtual character, and outputs the corresponding first path located within each first convex polygon.
[0342] Optionally, the second determining unit 704 is specifically configured to:
[0343] The starting position and the target position are used as the starting point and the ending point respectively, and input into the path finding logic;
[0344] The path-finding logic queries the type of area through which the target virtual character can pass according to the character configuration information, and determines the first attribute data corresponding to the type of area through which the target virtual character can pass;
[0345] Determine each of the first convex polygons having first attribute data from each of the convex polygons, and determine a first point for connecting the starting position and the target position from each of the first convex polygons;
[0346] The starting position, the first point and the target position are sequentially connected to generate a first path.
[0347] Optionally, the second determining unit 704 is specifically configured to:
[0348] According to the adjacent relationship between the first convex polygons, a first point for connecting the starting position and the target position is determined from the first convex polygons.
[0349] Optionally, the second determining unit 704 is specifically configured to:
[0350] Taking the starting position as an initial detection base point, taking the triangles in the first convex polygons adjacent to the starting triangle as initial triangles to be detected, and executing the first step, wherein the starting triangles are triangles in each of the first convex polygons that contain the starting position;
[0351] The first step includes:
[0352] Detect whether a line segment formed by the detection base point and any position point on the target edge of the triangle to be detected is located inside the connected area formed by each of the first convex polygons and passes through the triangle to be detected, wherein the target edge is a common edge between the triangle to be detected and the next adjacent triangle;
[0353] If not, the target vertex of the triangle to be detected is determined as the first point position, and when the next adjacent triangle is not a terminating triangle, the target vertex is used as the detection base point, and the next adjacent triangle is used as the triangle to be detected, and the first step is returned to be executed, wherein the target vertex is a vertex among the vertices of the triangle except the two end points of the target edge, and the terminating triangle is a triangle in each of the first convex polygons that contains the target position;
[0354] If yes, in the case that the next adjacent triangle is not the terminating triangle, continue to use the starting position as the initial detection base point, use the next adjacent triangle as the triangle to be detected, and return to execute the first step;
[0355] Until the triangles adjacent to the termination triangle in each of the first convex polygons are detected.
[0356] Optionally, the marking unit 701 is specifically used for:
[0357] Marking the voxel grid corresponding to the scene model of the area type that is passable by the player character and the area type that is not passable by the NPC in the game scene as the first data; and
[0358] Marking the voxel grid corresponding to the scene model of the game scene that belongs to the area type that the NPC can pass through and belongs to the area type that the player character cannot pass through as the second data; and
[0359] Marking the voxel grid corresponding to the scene model of the area type that the player character can pass through and the area type that the NPC can pass through in the game scene as the third data;
[0360] The first data, the second data and the third data are binary data.
[0361] Optionally, the target virtual character is a player character, the starting position where the player character is currently located is a first starting position, and the second determining unit 704 is specifically configured to:
[0362] Determining a first distance corresponding to the pathfinding operation and a first direction to be moved;
[0363] Determine a first position whose distance from the first starting position is the first distance and whose direction with the first starting position is the first direction;
[0364] determining whether the first position is a position that the player character at the first starting position can reach;
[0365] If so, the first position is determined as the target position.
[0366] Optionally, the second determining unit 704 is further specifically configured to:
[0367] If not, the first position is corrected to obtain a corrected position, so that the corrected position belongs to a position that the player character at the first starting position can reach, and the corrected position is determined as the target position.
[0368] Optionally, the second determining unit 704 is further specifically configured to:
[0369] The first starting position and the first position are used as a starting point and an ending point respectively, and input into the path finding logic, so that the path finding logic outputs a corresponding second path;
[0370] If the end point of the second path is the first position, the result of determining whether the first position is a position that the player character at the first starting position can reach is yes;
[0371] If the end point of the second path is not the first position, the result of determining whether the first position is a position that the player character at the first starting position can reach is no.
[0372] Optionally, the second determining unit 704 is further specifically configured to:
[0373] The first starting position and the first position are used as a starting point and an ending point, respectively, and input into the path finding logic;
[0374] The path-finding logic determines the farthest reachable path from the first starting position to the first position from each of the convex polygons according to the type of area through which the player character can pass, and determines the farthest reachable path from the first starting position to the first position as the second path.
[0375] Optionally, each of the convex polygons fits the ground surface, and the second determining unit 704 is further specifically configured to:
[0376] Performing altitude correction on the first position to obtain an altitude-corrected position, so that the altitude-corrected position is located on the ground surface;
[0377] Determining whether the position after the height correction is a position that the player character at the first starting position can reach;
[0378] If so, the position after the height correction is determined as the corrected position.
[0379] Optionally, the second determining unit 704 is further specifically configured to:
[0380] Acquire horizontal coordinate data of two axes of the first position on a horizontal plane;
[0381] Determine the height coordinate data corresponding to the horizontal coordinate data on the ground surface according to the vertex data of the convex polygon corresponding to the horizontal coordinate data;
[0382] The position indicated by the coordinates composed of the horizontal coordinate data and the height coordinate data is determined as the position after the height is corrected.
[0383] Optionally, the second determining unit 704 is further specifically configured to:
[0384] If not, the first distance is expanded based on the distance expansion parameter to obtain a second distance;
[0385] Determine a position whose distance from the first starting position is the first distance and whose direction with the first starting position is the corrected distance of the first direction;
[0386] Determining whether the position after the distance correction is a position that the player character at the first starting position can reach;
[0387] If so, the position after the distance correction is determined as the corrected position.
[0388] Optionally, the second determining unit 704 is further specifically configured to:
[0389] If not, it is determined that the corresponding target position has not been determined for the pathfinding instruction, and the first starting position is determined as the player position corresponding to the first frame, and the second step is performed for the i-th frame, wherein i traverses 1 to n, and the total distance moved by the player character from the first frame to the n-th frame is the first distance;
[0390] The second step comprises:
[0391] Determine the turning point as the intersection point between the ray formed by the player position of the player character at the beginning of the i-th frame along the first direction and the surface of the obstacle when the ray reaches the surface of the obstacle, wherein the turning point is located on the ground surface;
[0392] Determining the normal direction of the obstacle at the turning point;
[0393] Removing a first direction component opposite to the normal direction from the first direction to obtain a second direction component perpendicular to the normal direction, and determining the second direction component as the direction in which the player character is to move at the turning point;
[0394] The player character is controlled to move from the player position along the first direction to the turning point in the i-th frame, and to move from the turning point along the direction to be moved.
[0395] Optionally, the target virtual character is an NPC, and the starting position where the NPC is currently located is a second starting position; the second determining unit 704 is specifically configured to:
[0396] Dividing the game scene into unit grids;
[0397] Determine, from the unit grid, a grid area whose distance from the second starting position is within a preset range;
[0398] A target grid that the NPC can reach is determined from the grid area, and a position in the target grid is determined as the target position.
[0399] Optionally, the second determining unit 704 is further specifically configured to:
[0400] Dividing the game scene into unit grids, and marking first identification information on grids in the unit grids that are reachable by the NPC;
[0401] The determining of a target grid that the NPC can reach from the grid area includes:
[0402] A target grid having the first identification information is determined from the grid area.
[0403] Optionally, the second determining unit 704 is further specifically configured to:
[0404] Selecting a reference grid reachable by the NPC from the unit grid;
[0405] For the jth grid, determine whether the reference grid and the jth grid are reachable, wherein the jth grid is a grid to be marked in the unit grid except the reference grid, j traverses 1 to m, and m is the number of grids to be marked;
[0406] If so, mark the j-th grid with the first identification information.
[0407] Optionally, the second determining unit 704 is further specifically configured to:
[0408] If not, the j-th grid is marked with second identification information.
[0409] Optionally, the second determining unit 704 is further specifically configured to:
[0410] The center position of the reference grid and the center position of the j-th grid are respectively used as a starting point and an ending point, and input into the path-finding logic, so that the path-finding logic outputs a corresponding third path;
[0411] If the end point of the third path is the center position of the j-th grid, the result of determining whether the reference grid and the j-th grid are reachable is yes;
[0412] If the end point of the second path is not the center position of the j-th grid, the result of determining whether the reference grid and the j-th grid are reachable is no.
[0413] Optionally, the second determining unit 704 is further specifically configured to:
[0414] The center position of the reference grid and the center position of the j-th grid are respectively used as the starting point and the ending point, and input into the path finding logic;
[0415] The path-finding logic determines the farthest reachable path from the center position of the reference grid to the center position of the j-th grid from each of the convex polygons according to the type of area through which the NPC can pass, and determines the farthest reachable path from the center position of the reference grid to the center position of the j-th grid as the third path.
[0416] Optionally, the second determining unit 704 is further specifically configured to:
[0417] Constructing a corresponding two-dimensional segment tree according to identification information of the unit grid, wherein the identification information is one of the first identification information and the second identification information;
[0418] A target mesh having the first identification information is determined from the mesh area according to the two-dimensional segment tree.
[0419] Optionally, the second determining unit 704 is further specifically configured to:
[0420] A grid area whose Manhattan distance from the second starting position is within a preset range consisting of a first distance threshold and a second distance threshold is determined from the unit grid.
[0421] Optionally, the second determining unit 704 is further specifically configured to:
[0422] Rotate the grid area by 45 degrees around the coordinate origin in the direction of the target clockwise direction to obtain a rotated grid area, wherein the target clockwise direction is one of clockwise and counterclockwise;
[0423] Querying the maximum value in the rotated grid area from the two-dimensional line segment tree, and determining the grid corresponding to the maximum value as the rotated target grid;
[0424] The rotated target grid is rotated 45 degrees around the coordinate origin in a direction opposite to the target clockwise direction to obtain the target grid.
[0425] Optionally, the second determining unit 704 is further specifically configured to:
[0426] The unit grid is rotated 45 degrees around the coordinate origin in the direction of the target clock to obtain a rotated unit grid, wherein the identification information of each unit grid remains unchanged before and after the rotation;
[0427] A corresponding two-dimensional segment tree is constructed based on the identification information of the rotated unit grid.
[0428] Corresponding to the data processing method in pathfinding provided in the first embodiment of the present application, the third embodiment of the present application further provides an electronic device for data processing in pathfinding. Figure 8 As shown, the electronic device 800 includes: a processor 801; and a memory 802, which is used to store a program of the data processing method in pathfinding. After the device is powered on and the program of the data processing method in pathfinding is run by the processor, the following steps are performed:
[0429] Marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid;
[0430] Determine each target voxel grid corresponding to an area in each voxel grid where a virtual character belonging to at least one character type can walk, wherein the character type includes a player character type and a non-player character type;
[0431] According to the attribute data corresponding to the target voxel grids, each of the target voxel grids is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grid contained in each of the convex polygons is the same;
[0432] In response to a path-finding instruction for a target virtual character, a first path for the target virtual character to move is determined from each first convex polygon having first attribute data in each convex polygon, wherein the target virtual character is one of a player character and an NPC, and the area type indicated by the first attribute data is the area type through which the target virtual character can pass.
[0433] Corresponding to the data processing method in pathfinding provided in the first embodiment of the present application, the fourth embodiment of the present application provides a computer-readable storage medium storing a program of the data processing method in pathfinding, the program is executed by a processor to perform the following steps:
[0434] Marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid;
[0435] Determine each target voxel grid corresponding to an area in each voxel grid where a virtual character belonging to at least one character type can walk, wherein the character type includes a player character type and a non-player character type;
[0436] According to the attribute data corresponding to the target voxel grids, each of the target voxel grids is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grid contained in each of the convex polygons is the same;
[0437] In response to a pathfinding instruction for a target virtual character, a first path for the target virtual character to move is determined from each first convex polygon having first attribute data among the convex polygons, wherein the area type indicated by the first attribute data is the area type through which the target virtual character can pass.
[0438] It should be noted that for the detailed description of the devices, electronic devices and computer-readable storage media provided in the second, third and fourth embodiments of the present application, reference can be made to the relevant description of the first embodiment of the present application, and no further details will be given here.
[0439] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
[0440] In a typical configuration, a node device in a blockchain includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0441] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0442] 1. Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), random access memory (RAM) of other attributes, read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage media or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include non-transitory media such as modulated data signals and carrier waves.
[0443] 2. Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0444] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
Claims
1. A data processing method in pathfinding, characterized in that: The method comprises: Marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid; Determine each target voxel grid corresponding to an area in each voxel grid where a virtual character belonging to at least one character type can walk, wherein the character type includes a player character type and a non-player character type; According to the attribute data corresponding to the target voxel grids, each of the target voxel grids is divided into connected convex polygons, wherein the attribute data corresponding to the target voxel grid contained in each of the convex polygons is the same; In response to a pathfinding instruction for a target virtual character, a first path for the target virtual character to move is determined from each first convex polygon having first attribute data among the convex polygons, wherein the area type indicated by the first attribute data is the area type through which the target virtual character can pass.
2. The method according to claim 1, characterized in that The method further comprises: If the area types corresponding to two adjacent first convex polygons passed by the first path are different, the correspondence between the target path point and the target area type corresponding to the first target polygon is recorded, so that when the target virtual character enters the first target polygon from the target path point, the movement logic matching the target area type is called to give the target virtual character a movement performance; Among them, the target path point is the common point of the first path on the two adjacent first convex polygons, and the first target polygon is the polygon located after the target path point in the two first convex polygons connected by the target path point.
3. The method according to claim 1, characterized in that Before determining, in response to a pathfinding instruction for a target virtual character, a first path for the target virtual character to move from each first convex polygon having first attribute data among the convex polygons, the method further includes: Generate a path-finding logic that includes each of the convex polygons, and each of the convex polygons carries corresponding attribute data, wherein the path-finding logic is used to query the farthest reachable path of the target virtual character from the starting point to the end point in the connected area composed of each of the convex polygons according to the attribute data.
4. The method according to claim 3, characterized in that: The step of determining the first path for the target virtual character to move from each first convex polygon having first attribute data among the convex polygons comprises: Obtaining the current starting position of the target virtual character, and determining the target position to be moved to corresponding to the path-finding instruction; When the corresponding target position is determined for the pathfinding instruction, the starting position and the target position are used as the starting point and the ending point respectively, and the pathfinding logic is input so that the pathfinding logic determines each first convex polygon with first attribute data from each convex polygon based on the type of the target virtual character, and outputs the corresponding first path located within each first convex polygon.
5. The method according to claim 4, characterized in that The starting position and the target position are used as a starting point and an ending point respectively, and input into the path finding logic, so that the path finding logic determines each first convex polygon having first attribute data from each convex polygon based on the type of the target virtual character, and outputs a corresponding first path located within each first convex polygon, including: The starting position and the target position are used as the starting point and the ending point respectively, and input into the path finding logic; The path-finding logic queries the type of area through which the target virtual character can pass according to the character configuration information, and determines the first attribute data corresponding to the type of area through which the target virtual character can pass; Determine each of the first convex polygons having first attribute data from each of the convex polygons, and determine a first point for connecting the starting position and the target position from each of the first convex polygons; The starting position, the first point and the target position are sequentially connected to generate a first path.
6. The method according to claim 5, characterized in that The step of determining a first point for connecting the starting position and the target position from each of the first convex polygons includes: According to the adjacent relationship between the first convex polygons, a first point for connecting the starting position and the target position is determined from the first convex polygons.
7. The method according to claim 6, characterized in that Each of the first convex polygons is a triangle, and determining a first point for connecting the starting position and the target position from each of the first convex polygons according to the adjacent relationship of the first convex polygons includes: Taking the starting position as an initial detection base point, taking the triangles in the first convex polygons adjacent to the starting triangle as initial triangles to be detected, and executing the first step, wherein the starting triangles are triangles in each of the first convex polygons that contain the starting position; The first step includes: Detect whether a line segment formed by the detection base point and any position point on the target edge of the triangle to be detected is located inside the connected area formed by each of the first convex polygons and passes through the triangle to be detected, wherein the target edge is a common edge between the triangle to be detected and the next adjacent triangle; If not, the target vertex of the triangle to be detected is determined as the first point position, and when the next adjacent triangle is not a terminating triangle, the target vertex is used as the detection base point, and the next adjacent triangle is used as the triangle to be detected, and the first step is returned to be executed, wherein the target vertex is a vertex among the vertices of the triangle except the two end points of the target edge, and the terminating triangle is a triangle in each of the first convex polygons that contains the target position; If yes, in the case that the next adjacent triangle is not the terminating triangle, continue to use the starting position as the initial detection base point, use the next adjacent triangle as the triangle to be detected, and return to execute the first step; Until the triangles adjacent to the termination triangle in each of the first convex polygons are detected.
8. The method according to claim 1, characterized in that The voxel grid marking attribute data corresponding to the scene model in the game scene includes: Marking the voxel grid corresponding to the scene model of the area type that is passable by the player character and the area type that is not passable by the NPC in the game scene as the first data; and Marking the voxel grid corresponding to the scene model of the game scene that belongs to the area type that the NPC can pass through and belongs to the area type that the player character cannot pass through as the second data; and Marking the voxel grid corresponding to the scene model of the area type that the player character can pass through and the area type that the NPC can pass through in the game scene as the third data; The first data, the second data and the third data are binary data.
9. The method according to claim 3, characterized in that: The target virtual character is a player character, the starting position currently located by the player character is a first starting position, and the path-finding instruction is an instruction generated by a path-finding operation; The determining of the target position to be moved to corresponding to the pathfinding instruction includes: Determining a first distance corresponding to the pathfinding operation and a first direction to be moved; Determine a first position whose distance from the first starting position is the first distance and whose direction with the first starting position is the first direction; determining whether the first position is a position that the player character at the first starting position can reach; If so, the first position is determined as the target position.
10. The method according to claim 9, characterized in that The method further comprises: If not, the first position is corrected to obtain a corrected position, so that the corrected position belongs to a position that the player character at the first starting position can reach, and the corrected position is determined as the target position.
11. The method according to claim 10, characterized in that The determining whether the first position is a position that the player character at the first starting position can reach includes: The first starting position and the first position are used as a starting point and an ending point respectively, and input into the path finding logic, so that the path finding logic outputs a corresponding second path; If the end point of the second path is the first position, the result of determining whether the first position is a position that the player character at the first starting position can reach is yes; If the end point of the second path is not the first position, the result of determining whether the first position is a position that the player character at the first starting position can reach is no.
12. The method according to claim 11, characterized in that The step of taking the first starting position and the first position as a starting point and an ending point respectively, and inputting the first starting position and the first ending point into the path finding logic so that the path finding logic outputs a corresponding second path, comprises: The first starting position and the first position are used as a starting point and an ending point, respectively, and input into the path finding logic; The path-finding logic determines the farthest reachable path from the first starting position to the first position from each of the convex polygons according to the type of area through which the player character can pass, and determines the farthest reachable path from the first starting position to the first position as the second path.
13. The method according to claim 10, characterized in that Each of the convex polygons fits the ground surface, and the first position is corrected to obtain a corrected position, including: Performing altitude correction on the first position to obtain an altitude-corrected position, so that the altitude-corrected position is located on the ground surface; Determining whether the position after the height correction is a position that the player character at the first starting position can reach; If so, the position after the height correction is determined as the corrected position.
14. The method according to claim 13, characterized in that The step of performing height correction on the first position to obtain a position after the height correction comprises: Acquire horizontal coordinate data of two axes of the first position on a horizontal plane; Determine the height coordinate data corresponding to the horizontal coordinate data on the ground surface according to the vertex data of the convex polygon corresponding to the horizontal coordinate data; The position indicated by the coordinates composed of the horizontal coordinate data and the height coordinate data is determined as the position after the height is corrected.
15. The method according to claim 13, characterized in that The method further comprises: If not, the first distance is expanded based on the distance expansion parameter to obtain a second distance; Determine a position whose distance from the first starting position is the first distance and whose direction with the first starting position is the corrected distance of the first direction; Determining whether the position after the distance correction is a position that the player character at the first starting position can reach; If so, the position after the distance correction is determined as the corrected position.
16. The method according to claim 15, characterized in that The method further comprises: If not, it is determined that the corresponding target position has not been determined for the pathfinding instruction, and the first starting position is determined as the player position corresponding to the first frame, and the second step is performed for the i-th frame, wherein i traverses 1 to n, and the total distance moved by the player character from the first frame to the n-th frame is the first distance; The second step comprises: Determine the turning point as the intersection point between the ray formed by the player position of the player character at the beginning of the i-th frame along the first direction and the surface of the obstacle when the ray reaches the surface of the obstacle, wherein the turning point is located on the ground surface; Determining the normal direction of the obstacle at the turning point; Removing a first direction component opposite to the normal direction from the first direction to obtain a second direction component perpendicular to the normal direction, and determining the second direction component as the direction in which the player character is to move at the turning point; The player character is controlled to move from the player position along the first direction to the turning point in the i-th frame, and to move from the turning point along the direction to be moved.
17. The method according to claim 3, characterized in that The target virtual character is an NPC, and the starting position currently located by the NPC is a second starting position; and determining the target position to be moved to corresponding to the pathfinding instruction includes: Dividing the game scene into unit grids; Determine, from the unit grid, a grid area whose distance from the second starting position is within a preset range; A target grid that the NPC can reach is determined from the grid area, and a position in the target grid is determined as the target position.
18. The method according to claim 17, characterized in that The step of dividing the game scene into unit grids comprises: Dividing the game scene into unit grids, and marking first identification information on grids in the unit grids that are reachable by the NPC; The determining of a target grid that the NPC can reach from the grid area includes: A target grid having the first identification information is determined from the grid area.
19. The method according to claim 18, characterized in that The marking of the first identification information of the grid that is reachable by the NPC in the unit grid includes: Selecting a reference grid reachable by the NPC from the unit grid; For the jth grid, determine whether the reference grid and the jth grid are reachable, wherein the jth grid is a grid to be marked in the unit grid except the reference grid, j traverses 1 to m, and m is the number of grids to be marked; If so, mark the j-th grid with the first identification information.
20. The method according to claim 19, characterized in that The method further comprises: If not, the j-th grid is marked with second identification information.
21. The method according to claim 19, characterized in that The determining whether the reference grid is reachable from the j-th grid comprises: The center position of the reference grid and the center position of the j-th grid are respectively used as a starting point and an ending point, and input into the path-finding logic, so that the path-finding logic outputs a corresponding third path; If the end point of the third path is the center position of the j-th grid, the result of determining whether the reference grid and the j-th grid are reachable is yes; If the end point of the second path is not the center position of the j-th grid, the result of determining whether the reference grid and the j-th grid are reachable is no.
22. The method according to claim 21, characterized in that The step of taking the center position of the reference grid and the center position of the j-th grid as a starting point and an end point respectively, and inputting the path finding logic so that the path finding logic outputs a corresponding third path, comprises: The center position of the reference grid and the center position of the j-th grid are respectively used as the starting point and the ending point, and input into the path finding logic; The path-finding logic determines the farthest reachable path from the center position of the reference grid to the center position of the j-th grid from each of the convex polygons according to the type of area through which the NPC can pass, and determines the farthest reachable path from the center position of the reference grid to the center position of the j-th grid as the third path.
23. The method according to claim 20, characterized in that The determining a target grid having the first identification information from the grid area includes: Constructing a corresponding two-dimensional segment tree according to identification information of the unit grid, wherein the identification information is one of the first identification information and the second identification information; A target mesh having the first identification information is determined from the mesh area according to the two-dimensional segment tree.
24. The method according to claim 23, characterized in that The step of determining, from the unit grid, a grid area whose distance from the second starting position is within a preset range comprises: A grid area whose Manhattan distance from the second starting position is within a preset range consisting of a first distance threshold and a second distance threshold is determined from the unit grid.
25. The method according to claim 24, characterized in that The step of determining a target grid having the first identification information from the grid area according to the two-dimensional segment tree includes: Rotate the grid area by 45 degrees around the coordinate origin in the direction of the target clockwise direction to obtain a rotated grid area, wherein the target clockwise direction is one of clockwise and counterclockwise; Querying the maximum value in the rotated grid area from the two-dimensional line segment tree, and determining the grid corresponding to the maximum value as the rotated target grid; The rotated target grid is rotated 45 degrees around the coordinate origin in a direction opposite to the target clockwise direction to obtain the target grid.
26. The method according to claim 25, characterized in that The step of constructing a corresponding two-dimensional segment tree according to the identification information of the unit grid includes: The unit grid is rotated 45 degrees around the coordinate origin in the direction of the target clock to obtain a rotated unit grid, wherein the identification information of each unit grid remains unchanged before and after the rotation; A corresponding two-dimensional segment tree is constructed based on the identification information of the rotated unit grid.
27. A data processing device for path finding, characterized in that: The device comprises: A marking unit, used for marking attribute data for each voxel grid corresponding to a scene model in a game scene, wherein the attribute data is used to indicate a region type of the scene model corresponding to the voxel grid; A first determining unit is used to determine each target voxel grid corresponding to a walkable area of a virtual character belonging to at least one character type in each voxel grid, wherein the character type includes a player character type and a non-player character type; A division unit, configured to divide each target voxel grid into connected convex polygons according to the attribute data corresponding to the target voxel grid, wherein the attribute data corresponding to the target voxel grid contained in each convex polygon is the same; The second determination unit is used to determine a first path for the target virtual character to move from each first convex polygon having first attribute data in each convex polygon in response to a path-finding instruction for the target virtual character, wherein the area type indicated by the first attribute data is an area type through which the target virtual character can pass.
28. An electronic device, characterized in that: include: processor; as well as The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the method as described in any one of claims 1 to 26 is executed.
29. A computer-readable storage medium, characterized in that: A data processing program is stored, and the program is run by a processor to execute the method according to any one of claims 1 to 26.
Citation Information
Cited By
Identification method for drawing block and drawing tag in architectural drawing, storage medium and electronic equipment
CN120148065A
