CN117732072A - Cross-layer path finding method, device, computer equipment and readable storage medium - Google Patents

Cross-layer path finding method, device, computer equipment and readable storage medium Download PDF

Info

Publication number
CN117732072A
CN117732072A CN202311688569.7A CN202311688569A CN117732072A CN 117732072 A CN117732072 A CN 117732072A CN 202311688569 A CN202311688569 A CN 202311688569A CN 117732072 A CN117732072 A CN 117732072A
Authority
CN
China
Prior art keywords
navigation grid
navigation
target
grid
path
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311688569.7A
Other languages
Chinese (zh)
Inventor
杨飞飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Pixel Software Technology Co Ltd
Original Assignee
Beijing Pixel Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Pixel Software Technology Co Ltd filed Critical Beijing Pixel Software Technology Co Ltd
Priority to CN202311688569.7A priority Critical patent/CN117732072A/en
Publication of CN117732072A publication Critical patent/CN117732072A/en
Pending legal-status Critical Current

Links

Landscapes

  • Navigation (AREA)

Abstract

The invention provides a cross-layer path finding method, a device, computer equipment and a readable storage medium, which are used for acquiring the starting point and the end point of NPC; the starting point and the ending point are positioned at two different levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to a navigation grid; performing path search by taking a navigation grid corresponding to a starting point as an initial navigation grid, and determining a plurality of target navigation grids positioned on an optimal path and exchange labels corresponding to each target navigation grid in the path search process; the exchange label represents whether a cross-layer path exists in the target navigation grid; the partial connection points positioned in the target navigation grid form partial path sections of the cross-layer path; and controlling the NPC to move from the level of the starting point to the level of the ending point according to all the target navigation grids and the exchange labels. The invention can enable the NPC to realize more natural and smooth cross-layer movement capability in game worlds with different terrain levels.

Description

Cross-layer path finding method, device, computer equipment and readable storage medium
Technical Field
The present invention relates to the field of games, and in particular, to a cross-layer routing method, apparatus, computer device, and readable storage medium.
Background
In game development, in order to meet the experience needs of players, there are often some cross-layer playing methods, namely, the actions of climbing or descending the NPC between different levels, so as to realize position conversion. For example, a player may go up to the roof to play a game by a simple climbing action. However, as Non-Player characters (NPCs), they need to have more intelligent path finding capability in order to achieve the effect of cross-layer path finding.
The traditional cross-layer road finding method is characterized in that an entity lifting structure is established between map scenes of different levels, and a navigation grid is added on the structure. Such as building a stairway structure between the roof and the ground and adding a navigation grid over the stairway. Thus, a connection channel between navigation grids of different levels is established. When the NPC needs to realize cross-layer, the optimal path can be directly searched in the whole navigation system by utilizing the existing path searching method through the connecting channel.
However, the above-described cross-layer routing method relies on establishing stairs or other engagement areas for climbing between two different levels, which is not in itself compatible with the specific game play needs. Therefore, how to realize the NPC to realize the intelligent cross-layer path finding is a technical problem to be solved.
Disclosure of Invention
The invention provides a cross-layer path finding method, a device, computer equipment and a readable storage medium, which are used for enabling NPC to realize intelligent cross-layer. Embodiments of the invention may be implemented as follows:
in a first aspect, the present invention provides a cross-layer routing method, the method comprising: acquiring a starting point and an ending point of NPC; wherein the start point and the end point are located at two different levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to one navigation grid; performing path search by taking a navigation grid corresponding to the starting point as an initial navigation grid, and determining a plurality of target navigation grids positioned on an optimal path and a switching label corresponding to each target navigation grid in the path search process; the exchange label characterizes whether a cross-layer path exists in the target navigation grid; a part of the connection points located in the target navigation grid form part of the path section of the cross-layer path; and controlling the NPC to move from the level where the starting point is located to the level where the ending point is located according to all the target navigation grids and the exchange labels.
In a second aspect, the present invention provides a cross-layer routing device, including: the acquisition module is used for acquiring the starting point and the end point of the NPC; wherein the start point and the end point are located at two different levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to one navigation grid; the searching module is used for searching a path by taking the navigation grid corresponding to the starting point as an initial navigation grid, and determining a plurality of target navigation grids positioned on the optimal path and a switching label corresponding to each target navigation grid in the path searching process; the exchange label characterizes whether a cross-layer path exists in the target navigation grid; a part of the connection points located in the target navigation grid form part of the path section of the cross-layer path; and the path finding module is used for controlling the NPC to move from the level where the starting point is located to the level where the ending point is located according to all the target navigation grids and the exchange labels.
In a third aspect, the present invention provides a computer device comprising a processor and a memory having stored therein at least one instruction or at least one program loaded and executed by the processor to implement a cross-layer routing method as described in the first aspect.
In a fourth aspect, the present invention provides a readable storage medium having stored therein at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by a processor to implement a cross-layer routing method as described in the first aspect.
The invention provides a cross-layer path finding method, a device, computer equipment and a readable storage medium. In the embodiment of the invention, a plurality of connection points are preset in two levels and the connection area thereof in advance, and each connection point corresponds to one navigation grid to form a cross-layer path for communicating different levels. And taking the navigation grid corresponding to the starting point as the starting point, and carrying out path searching to search the optimal path. In the searching process, a switch label is marked for each target navigation grid on the optimal path, and the switch label indicates whether a cross-layer path communicated with different levels exists in the grid. The optimal path can be known through the exchange label and needs to be temporarily switched to the cross-layer path when being transmitted to some target navigation grids, so that NPC can be moved from a starting point level to an end point level by means of path planning and label exchange, and the cross-layer navigation effect is achieved. The invention can enable the NPC to realize more natural and smooth cross-layer movement capability in the game world with different terrain levels.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a cross-layer routing method provided by an embodiment of the present invention;
FIG. 2 is a schematic view of a scenario provided in an embodiment of the present invention;
FIG. 3 is a schematic flow chart of step S102 provided in an embodiment of the present invention;
fig. 4 is a schematic flowchart of step S103 provided in an embodiment of the present invention;
FIG. 5 is a functional block diagram of a cross-layer routing device according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a computer device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. The components of the embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the invention, as presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
In the description of the present invention, it should be noted that, if the terms "upper", "lower", "inner", "outer", and the like indicate an azimuth or a positional relationship based on the azimuth or the positional relationship shown in the drawings, or the azimuth or the positional relationship in which the inventive product is conventionally put in use, it is merely for convenience of describing the present invention and simplifying the description, and it is not indicated or implied that the apparatus or element referred to must have a specific azimuth, be configured and operated in a specific azimuth, and thus it should not be construed as limiting the present invention.
Furthermore, the terms "first," "second," and the like, if any, are used merely for distinguishing between descriptions and not for indicating or implying a relative importance.
It should be noted that the features of the embodiments of the present invention may be combined with each other without conflict.
Related terms involved in the embodiments of the present invention will be explained first.
Star finding algorithm: is a heuristic search algorithm commonly used for graph search and path planning. It is widely used in the field of computer science, particularly in the fields of computer games, artificial intelligence and robotics, for finding the shortest path or optimal path from a starting point to a target point.
Navigation grid: in a game scene, the navigation grid typically represents a map or scene of the game world, divided into regular grid cells, each of which may be square or hexagonal, etc. These grid cells may represent passable areas and obstacles.
Non-Player Character (NPC) NPC is a virtual Character designed and controlled by a game developer, not manipulated by an actual Player. NPCs play a variety of different roles and functions in the game, enriching the storyline, world view and interactivity of the game.
Manhattan distance: which is the sum of the horizontal and vertical distances from the current node to the target node.
Nodes: each navigation grid is considered as a node in the a-star routing algorithm.
Euclidean distance: which is the linear distance from the current node to the target node.
Practical cost: the actual distance from the starting node to the current node.
Heuristic cost: refers to a heuristic function that estimates the shortest path cost from the current node to the target node. Common heuristic functions: there are manhattan distance and euclidean distance.
Total cost: the sum of the actual cost and the heuristic cost.
Open list: a star finding algorithm maintains a list containing nodes to be considered.
Closing the list: a star-finding algorithm maintains a list of nodes that have been considered.
Switch container: for the existence of correspondence between node coordinates and location points. The coordinates of the position point are Value, wherein the coordinates (X, Y) of the node are Key.
Referring to fig. 1, fig. 1 is a schematic flowchart of a cross-layer routing method provided in an embodiment of the present invention, which may include the following steps:
s101, acquiring a starting point and an ending point of NPC; the starting point and the ending point are located at two different levels, and a plurality of connection points are preset in the two levels and a junction area between the levels; each connection point corresponds to a navigation grid;
S102, performing path search by taking a navigation grid corresponding to a starting point as an initial navigation grid, and determining a plurality of target navigation grids positioned on an optimal path and a switching label corresponding to each target navigation grid in the path search process;
the exchange label characterizes whether a cross-layer path exists in the target navigation grid; the partial connection points positioned in the target navigation grid form partial path sections of the cross-layer path;
and S103, controlling the NPC to move from the level where the starting point is located to the level where the ending point is located according to all the target navigation grids and the exchange labels.
In the technical solutions of the above steps S101 to 103, the start point and the end point of the NPC are first obtained, and these two points are located at two different terrain levels. In the embodiment of the invention, a plurality of connection points are preset in two levels and the connection area thereof in advance, and each connection point corresponds to one navigation grid to form a cross-layer path for communicating different levels. And taking the navigation grid corresponding to the starting point as the starting point, and carrying out path searching to search the optimal path. In the searching process, a switch label is marked for each target navigation grid on the optimal path, and the switch label indicates whether a cross-layer path communicated with different levels exists in the grid. The optimal path can be known through the exchange label and needs to be temporarily switched to the cross-layer path when being transmitted to some target navigation grids, so that NPC can be moved from a starting point level to an end point level by means of path planning and label exchange, and the cross-layer navigation effect is achieved. The invention can enable the NPC to realize more natural and smooth cross-layer movement capability in the game world with different terrain levels.
The above steps are described in detail below. For easy understanding, the embodiment of the invention will take two different levels of topography and roof in a game scene as an example, and describes a path finding method of climbing NPC from the ground to the roof.
In step S101, a start point (denoted as Pos 1) and an end point (denoted as Pos 2) of the NPC are acquired; wherein the start point and the end point are positioned at two different levels, and a cross-layer channel such as stairs is not established between the two levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to a navigation grid;
in the embodiment of the invention, in order to enable the NPC to realize cross-layer road searching between the terrain and the roof, the unconnected terrain navigation grid and the roof navigation grid can be connected together by a plurality of connection points in the game scene editor. These marker points may be manually preset at the location of the area where the terrain navigation grid and the roof navigation grid meet.
For example, as shown in fig. 2, fig. 2 is a schematic view of a scene provided by an embodiment of the present invention, where a point a may be preset on the ground, a point F may be preset on the roof, and five connection points B, C, D, E may be preset on the wall between the ground and the roof. The game editor background automatically establishes logical connection relationships between the interaction points to form a cross-layer path between a-F, where each connection point has a path order. Thus, the original independent terrain navigation grids and the roof navigation grids can be connected into a whole.
When the game scene is exported, the connection points, the coordinates and the ID information of the navigation grid where the connection points are located can be stored in a Switch. Bytes file in a structuring mode, and when the game is started, the Switch. Bytes content is loaded into a specific memory Switch container.
In the embodiment of the invention, the starting point and the ending point of the NPC are positioned at different levels, for example, the starting point is positioned on the ground, the ending point is positioned on the roof, and the NPC needs to finish the cross-layer movement from the ground to the roof; alternatively, for example, the start point is on the roof and the end point is on the ground, the NPC needs to complete the cross-layer movement from roof to roof. In different cross-layer scenarios, the path order of the preset connection points is different. For example, with continued reference to FIG. 2, moving across floors to roofs, the path order between A-F may be denoted A- > B- > … - > F; the cross-layer movement from roof to floor may be expressed as F- > E- > … - > a, which may be set according to actual needs, and is not limited herein.
In step S102, the path searching method adopted in the embodiment of the present invention may be an a-algorithm, so as to obtain the target navigation grid. In the path searching process, the embodiment of the invention sets a switching label for each navigation grid participating in searching, and the switching label characterizes whether a cross-layer path exists in the target navigation grid; the partial connection points positioned in the target navigation grid form partial path sections of the cross-layer path, which provides guarantee for the subsequent control NPC to temporarily switch into the cross-layer path for cross-layer movement.
Referring to fig. 3, fig. 3 is a schematic flowchart of step S102 provided in an embodiment of the present invention, which may include the following steps:
s102-1, taking out a navigation grid with the minimum total distance from a candidate navigation grid data table as a current navigation grid, and adding the current navigation grid into a considered navigation grid table;
in the embodiment of the invention, the candidate navigation grid data table is used for maintaining the distance information, father node information and exchange labels of the navigation grids to be considered; the navigation grid table has been considered for maintaining navigation grids that have participated in the path search; wherein the distance information includes total distance and parent node information of the navigation grid; wherein the total distance (denoted as F) is the sum of the actual distance (denoted as G) from the navigation grid corresponding to the start point to a certain navigation grid and the heuristic distance (denoted as H) from the navigation grid to the navigation grid corresponding to the start point.
For example, taking an a-star road-finding algorithm as an example, each navigation grid is regarded as a node, the candidate navigation grid data table and the considered navigation grid table respectively correspond to an open list and a closed list in the a-star road-finding algorithm, the actual distance from the navigation grid corresponding to the starting point to a certain navigation grid is the actual cost in the a-star road-finding algorithm, the shortest distance from the navigation grid to the navigation grid corresponding to the end point is the actual heuristic cost in the a-star road-finding algorithm, and the total distance corresponds to the total cost in the a-star road-finding algorithm, namely the sum of the actual cost and the heuristic cost. For ease of understanding, embodiments of the present invention will be described hereinafter with reference to the star-a routing algorithm.
In the candidate navigation grid data table, each navigation grid is arranged in order of the total distance F from large to small or from small to large, which is not limited herein. It can be appreciated that when arranged in order from large to small, the last navigation grid can be directly fetched each time as the current navigation grid; if the order is from small to large, the first navigation grid can be directly fetched each time as the current navigation grid. Moreover, if a new navigation grid to be considered is added to the table, the position of the navigation grid in the table is determined according to the F corresponding to the navigation grid.
S102-2, if the current navigation grid is not the navigation grid corresponding to the end point, determining a plurality of adjacent navigation grids and exchange labels of the current navigation grid, and determining a target adjacent navigation grid meeting preset conditions and distance information of the target adjacent navigation grid from the plurality of adjacent navigation grids;
it can be understood that if the current navigation grid is different from the navigation grid corresponding to the destination, the route searching is not successful, and then all neighbor navigation grids of the current navigation grid need to be traversed, and the target adjacent navigation grid and the exchange label of the current navigation grid are determined according to the preset condition.
Therefore, the embodiment of the invention firstly provides an implementation manner for determining the adjacent navigation grids and the exchange labels of the current navigation grid, which comprises the following steps:
step A1: determining a navigation grid adjacent to the current navigation grid in the horizontal direction and the vertical direction as an adjacent navigation grid;
that is, the navigation grids adjacent in the four directions of up, down, left and right of the current navigation grid are regarded as the adjacent navigation grids considered in the embodiment of the present invention. For example, assuming that the coordinates of the current navigation grid are (X, Y), the navigation grids corresponding to the four coordinates of (x+1, Y), (X-1, Y), (X, y+1), (X, Y-1) are all neighboring navigation grids of the current navigation grid.
Step A2: judging whether a connection point exists in the current navigation grid;
it can be appreciated that, because the embodiment of the present invention presets the connection point and the direct correspondence between the connection point and the navigation grid, such correspondence may be stored by the memory Switch container as above. For example, taking fig. 2 as an example, let key= (X, Y), value= (X) A ,Y A X A ,0),(X B ,Y B ,Z B ) Indicating that the (X, Y) corresponding navigation grid corresponds to connection points a and B. Thus, the first and second substrates are bonded together,whether the corresponding connection point exists in the current navigation grid can be directly determined according to the corresponding relation.
If so, executing the step A3: if not, executing the step A4;
step A3: setting a first exchange label for the current navigation grid, and determining the navigation grid corresponding to the path end point of a part of path segments formed by the connection points as an adjacent navigation grid;
as known from the above, when each connection point is preset, the embodiment of the present invention has generated the logic sequence between each connection point, according to which the path end point in the current navigation grid can be directly determined as to which connection point, and initializes a navigation grid according to the connection point, where the navigation grid is the adjacent navigation grid of the current navigation grid.
For example, continuing to assume that there is a correspondence assumption key= (X, Y), value= (X) A ,Y A X A ,0),(X B ,Y B ,Z B ) If the path end point is known to be the connection point B according to the logic sequence, one navigation grid can be initialized according to the coordinates of the connection point B as an adjacent navigation grid.
Step A4: setting a second exchange label for the current navigation grid;
in the embodiment of the invention, a first exchange label characterizes that a cross-layer path exists in a current navigation grid; the second switch label characterizes that no cross-layer path exists within the current navigation grid. The first switch label and the second switch label may be identified by different numbers, characters, etc., for example, the first switch label is 1 and the second switch label is 0, which is not limited herein.
It can be understood that if the current navigation grid has corresponding connection points, then there must be cross-layer path segments corresponding to the connection points in the navigation grid, so that the first exchange label is set for the current navigation grid, otherwise, the second exchange label is set for the current navigation grid.
After all adjacent navigation grids corresponding to the current navigation grid are determined through the embodiment, the target adjacent navigation grids can be determined according to the preset conditions, and the target adjacent navigation grids are to be used as the navigation grids to be considered and added into the candidate navigation grid data table.
In the embodiment of the invention, after all adjacent navigation grids corresponding to the current navigation grid are found, whether each adjacent navigation grid can become a navigation grid to be considered for participating in path search or not can be determined according to preset conditions. Specifically, the preset condition may be:
the neighboring navigation grid is not in the considered navigation grid data table or the candidate navigation grid data table; alternatively, the adjacent navigation grid is in the candidate navigation grid data table and its recalculated actual distance G is less than G already stored in the candidate navigation grid data table.
Therefore, for how to determine the adjacent navigation grids of the target and the distance information thereof, the embodiment of the invention provides an implementation manner, which comprises the following steps:
Step B1, judging whether adjacent navigation grids are positioned in a candidate navigation grid data table or a considered navigation grid data table;
if not, determining the adjacent navigation grid as a target adjacent navigation grid and determining the distance information corresponding to the target navigation grid;
it will be appreciated that if no indicates that the neighboring navigation grid is neither in the candidate navigation grid data table nor in the considered navigation grid data table, then the target neighboring navigation grid may be determined directly and G, H and F corresponding to the neighboring navigation grid may be calculated. Specifically, g=the sum of the distance between the current navigation grid and the target adjacent navigation grid and the G corresponding to the current navigation grid; h = distance of the navigation grid corresponding to the destination point from the target neighboring navigation grid; f=g+h.
Step B3, if the navigation grids are positioned in the candidate navigation grid data table, new distance information of adjacent navigation grids is redetermined;
that is, if a certain neighboring navigation grid is located in the candidate navigation grid data table, it is determined whether it satisfies the condition that the "recalculated actual distance G is smaller than G" already stored in the candidate navigation grid data table, i.e. step B4 is performed.
Step B4, when the actual distance in the new distance information is smaller than the actual distance stored in the candidate navigation grid data table, determining the adjacent navigation grid as a target navigation grid, and replacing the stored distance information with the new distance information;
in the embodiment of the present invention, if the adjacent navigation grid is located in the candidate navigation grid data table, G, H and F corresponding to the adjacent navigation grid are recalculated. Specifically, assuming that a new G is set to Tempg, tmpg=a sum of G corresponding to a distance between the current navigation grid and the adjacent navigation grid and a distance between the current navigation grid, and H is still a distance between the adjacent navigation grid and a navigation grid corresponding to an end point; if Tmpg is less than the already stored G for the neighboring navigation grid, then the neighboring navigation grid is the target neighboring navigation grid and the already stored G, f=g+h, is replaced with Tmpg, where G is after the replacement. If Tmpg is greater than G that the neighbor navigation grid has stored, then the neighbor navigation grid is not the target navigation neighbor grid and may be skipped.
And step B5, presetting the current navigation grid as a father node of the target adjacent navigation grid.
In the embodiment of the invention, for the determined target navigation grid, the father node is the current navigation grid.
Through the implementation mode, the distance information and the father node information corresponding to each target navigation grid can be determined and added into the candidate navigation grid data set, and at the moment, the target adjacent navigation grids are used as the navigation grids to be considered to participate in the path search.
S102-3, adding the target adjacent navigation grids, the distance information of the target adjacent navigation grids and the father node information into a candidate navigation grid data table, returning to the step of taking out the navigation grid with the minimum total distance from the candidate navigation grid data table as the current navigation grid, and adding the current navigation grid into the considered navigation grid table.
S102-4, if the current navigation grid is the navigation grid corresponding to the terminal point, or the candidate navigation grid data table is empty, tracing back the path according to the parent node information of the current navigation grid until the parent node encountered by tracing back is empty;
as can be seen from the above step 102-3, in the process of searching the path, the target adjacent navigation grid records the corresponding parent node information in the process of becoming the navigation grid to be considered, and when the target adjacent navigation grid is used as a current navigation grid, the corresponding exchange label can be determined through the steps A1 to A4. If the current navigation grid is the navigation grid corresponding to the end point in a certain search, the current navigation grid is taken out from the table, the success of the route searching is indicated, the father node of the current navigation grid, namely a certain navigation grid, is obtained at the moment, the father node of the navigation grid is obtained, and the like until the father node of the certain navigation grid is empty, and the end of backtracking is indicated.
S102-5, taking all the traced navigation grids as target navigation grids.
In the technical schemes of S102-1 to S102-5, each time the navigation grid with the minimum F is selected from the candidate navigation grid data table as the current navigation grid, it is moved to the considered navigation grid table, whether the current navigation grid is equal to the navigation grid where Pos2 is located is compared, if so, the navigation is successful, the parent node of the current navigation grid is used for tracing back all the navigation grids upwards until the parent node is empty, the traced back navigation grids are returned to the upper layer caller, and the route finding is finished. If the current navigation grids are not equal, traversing adjacent navigation grids of the current navigation grid, determining a target navigation grid to be considered from the adjacent navigation grids, adding the target navigation grid to the candidate navigation grid data table, and taking the target navigation grid as the current navigation grid of the next path search, and iterating until the path searching is successful or the candidate navigation grid data table is empty.
It should be noted that, before executing S102-1, a starting navigation grid may be initialized with the coordinates of Pos 1. At this point, the G, H, F, parent, and switch labels corresponding to the initial navigation grid may all be initialized to 0 or empty. Both the candidate navigation grid data table and the considered navigation grid table are empty. Therefore, for the initial navigation grid, it is directly added to the candidate navigation grid data table, and when executing S102-1, the initial navigation grid is directly taken out and added to the considered navigation grid table, and it is obvious that the initial navigation grid is different from the navigation grid corresponding to the destination, and then S102-2 to S102-5 may be directly executed.
After each target navigation grid on the optimal path is found through the above embodiment, the NPC may be controlled to perform cross-layer movement according to each target navigation grid and the corresponding exchange label, i.e. step S103 is executed.
In step S103, interpolation moves may be performed sequentially traversing the target navigation grid. During the interpolation movement, different interpolation modes may be determined according to the type of exchange tag of the target navigation grid. For example, if it is a first switch label, then interpolation movements between multiple connection points within the target navigation grid are required; if the label is the second label, the interpolation movement is directly performed between the target navigation grid and the next target navigation grid. Thus, for the step S103, an implementation manner is provided in the embodiment of the present invention, referring to fig. 4, fig. 4 is a schematic flowchart of the step S103 provided in the embodiment of the present invention, which may include the following steps:
s103-1, starting from an initial navigation grid, sequentially taking out each target navigation grid;
it will be appreciated that since the optimal path has been obtained in the path searching process of step S102, there is naturally a path order between the target navigation grids, and thus it is possible to determine what interpolation method should be performed by the target navigation grids according to the path order.
In the embodiment of the invention, an interpolation task can be created for the NPC in advance, and each frame can call the task to execute interpolation movement. For this task, the distance moved per frame may be calculated according to the speed of the NPC, and then different interpolation modes may be performed in combination with the distance moved per frame and the type of the switch label corresponding to each target navigation grid.
S103-2, judging whether the exchange label of the target navigation grid is a first exchange label or a second exchange label;
s103-3, if the target navigation grid is the first exchange label, performing position interpolation between connection points existing in the target navigation grid so that the NPC performs cross-layer movement until the NPC moves to the last connection point of the path segment;
in the embodiment of the invention, if the target navigation grid has a corresponding connection point, a cross-layer path is necessarily present, so that the target navigation grid can be directly switched into the cross-layer path to perform interpolation movement. Thus, the embodiment of step S103-3 described above may include:
step C1: calculating the distance between the current connection point and the next connection point;
step C2: if the distance is greater than the total distance moved by the NPC, updating the total distance moved by the NPC according to the moving distance of each frame of the NPC;
In an embodiment of the present invention, the total distance that the NPC has moved may be determined according to the movement speed of the NPC per frame.
It will be appreciated that interpolation essentially calculates the position of the NPC over time by a linear function, i.e. y=ax+b, where X is the ratio of the distance that has been travelled over to the total distance between the two nodes over time, and the total distance that has been travelled over is calculated by integrating the speed over time, i.e. cumulatively summing the speed over time to obtain the total displacement of the NPC over a period of time.
Step C3: determining the next connection point as the current connection point, returning to the step of calculating the distance between the current connection point and the next connection point until the current connection point is the last connection point in the target navigation grid, and controlling the NPC to move from the target navigation grid to the next target navigation grid.
For example, there are three connections a, B, and C, the current connection is a, the next connection point B is interpolated, and the position of the next connection point B is described, then the connection point B is continued as the current connection point, the interpolation from B to C is performed, and the manner of regarding the connection point B as the current connection point is: the value of the position index of the current connection point is increased by 1 so that the current connection point becomes B and the path that has been taken to record the connection points a and B is cleared to zero.
S103-4, if the target navigation grid is the second exchange label, performing position interpolation movement between the target navigation grid and the next target navigation grid;
in the embodiment of the invention, if the target navigation grid does not have a corresponding connection point, the condition that a cross-layer path does not exist is indicated, and path switching is not needed at this time, and interpolation is directly carried out between the target navigation grid and the next target navigation grid. Thus, the embodiment of step S103-4 described above may include:
step D1: taking the navigation grid where the NPC is located after moving as the current navigation grid;
step D2: calculating the distance between the current target navigation grid and the next target navigation grid; step D3: if the distance is greater than the total distance moved by the NPC, updating the total distance moved by the NPC according to the moving distance of each frame of the NPC;
it will be appreciated that if the range is greater than or equal to the total range of the two grids, then the interpolation endpoint for both grids is indicated.
Step D4: the NPC is controlled to move to the next target navigation grid and returns to the step of calculating the distance between the current target navigation grid and the next target navigation grid.
For example, create a task, execute move logic per frame call. NPC movement speed is speed (meters/second), and the total length that has been moved is recorded with the variable usedLen per frame movement distance dist=speed 0.03 (assuming one frame of 0.03 seconds). Each frame performs:
Calculating the length of the current path point NodeA and the next path point NodeB;
if usedLen > =length, indicating that the distance between the NodeB and the NodeB has been moved, then the NodeB and the NodeB are updated, set to the NodeB and the next-path point NodeB, respectively, and usedLen is increased by the movement distance dist.
And repeating the steps, and continuously updating the path point and the moving distance every frame to realize the moving effect of the NPC in smooth transition from one point to the next point. Simulating more realistic movement behavior.
S103-5, stopping interpolation movement after moving to the last target navigation grid.
In the embodiment of the invention, the interpolation mode of the NPC between each target navigation grid can be determined through exchanging the labels, so that the NPC can be controlled to temporarily switch from the optimal path to the cross-layer path through the exchanging labels to execute cross-layer movement, and the intelligent cross-layer effect of the NPC under the condition of no cross-layer channel (such as stairs) is realized.
The above embodiments are illustrated in the context of climbing from the ground to the roof, and similar methods may be used from the ground below the roof. In specific cases, the speed setting can be performed by combining different NPCs, such as NPCs with smaller body sizes and similar spiders, and the effect achieved by the method can be that the NPCs slowly climb to the ground from the roof, and if the NPCs with larger body sizes are used, the speed setting can be faster, so that the interpolation speed can be faster, and the effect is that the NPCs jump from the roof.
Based on the same inventive concept, the embodiment of the present invention further provides a cross-layer path-finding device, please refer to fig. 5, fig. 5 is a functional block diagram of a cross-layer path-finding device 500 provided by the embodiment of the present invention, which includes: an acquisition module 510, a search module 520, and a way finding module 530.
An obtaining module 510, configured to obtain a start point and an end point of the NPC; wherein the start point and the end point are located at two different levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to a navigation grid;
the searching module 520 is configured to perform a path search by using a navigation grid corresponding to the starting point as a starting navigation grid, and determine a plurality of target navigation grids located on an optimal path and a switch label corresponding to each target navigation grid in a path searching process;
the exchange label characterizes whether a cross-layer path exists in the target navigation grid; the partial connection points positioned in the target navigation grid form partial path sections of the cross-layer path;
and the path searching module 530 is configured to control the NPC to move from the level where the starting point is located to the level where the ending point is located according to all the target navigation grids and the switch labels.
It will be appreciated that the acquisition module 510, the search module 520 and the routing module 530 may cooperatively perform the steps of fig. 1 to achieve the corresponding technical effects.
It should be noted that, in the above embodiments of the present application, the division of the modules is merely schematic, and there may be another division manner in actual implementation, and in addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or may exist separately and physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated unit may already be stored in a readable storage medium if implemented in the form of a software functional unit and sold or used as a stand-alone product. Based on such understanding, the technical solution of the present application may be embodied essentially or in part or all or part of the technical solution contributing to the prior art or in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a Processor (Processor) to perform all or part of the steps of the methods of the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, etc., which can store various program codes.
The embodiment of the invention also provides a computer device 600 for deploying the cross-layer path-finding device 500 shown in fig. 5, please refer to fig. 6, fig. 6 is a schematic structural diagram of the computer device 600 according to the embodiment of the invention. The computer device 600 may include a memory 601, a processor 602, and a communication interface 603, where the memory 601, the processor 602, and the communication interface 603 are electrically connected to each other directly or indirectly to enable transmission or interaction of data. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
The memory 601 may be used for storing software programs and modules, such as program instructions/modules corresponding to the cross-layer routing device 500 provided herein, and the processor 602 executes the software programs and modules stored in the memory 601, thereby performing various functional applications and data processing, and further performing the steps of the live assistant interaction method provided herein. The communication interface 603 may be used for communication of signaling or data with other node devices.
The Memory 601 may be, but is not limited to, a random access Memory (Random Access Memory, RAM), a Read Only Memory (ROM), a programmable Read Only Memory (Programmable Read-Only Memory, PROM), an erasable Read Only Memory (Erasable Programmable Read-Only Memory, EPROM), an electrically erasable programmable Read Only Memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
The processor 602 may be an integrated circuit chip having signal processing capabilities. The processor 602 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a Network Processor (NP), etc.; but also digital signal processors (Digital Signal Processing, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
It is to be understood that the configuration shown in fig. 6 is merely illustrative, and that the computer device 600 may also include more or fewer components than shown in fig. 6, or have a different configuration than shown in fig. 6. The components shown in fig. 6 may be implemented in hardware, software, or a combination thereof.
Based on the above embodiments, the present application further provides a storage medium, in which a computer program is stored, which when executed by a computer, causes the computer to execute the cross-layer routing method provided in the above embodiments.
Based on the above embodiments, the present application further provides a computer program, which when run on a computer, causes the computer to execute the cross-layer routing method provided in the above embodiments.
Based on the above embodiments, the embodiments of the present application further provide a chip, where the chip is configured to read a computer program stored in a memory, and is configured to execute the cross-layer routing method provided in the above embodiments.
Also provided in embodiments of the present application is a computer program product comprising instructions that, when run on a computer, cause the computer to perform the cross-layer routing method provided in the above embodiments.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by instructions. These instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The present invention is not limited to the above embodiments, and any changes or substitutions that can be easily understood by those skilled in the art within the technical scope of the present invention are intended to be included in the scope of the present invention. Therefore, the protection scope of the invention is subject to the protection scope of the claims.

Claims (10)

1. A cross-layer way finding method, the method comprising:
acquiring a starting point and an ending point of NPC; wherein the start point and the end point are located at two different levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to one navigation grid;
performing path search by taking a navigation grid corresponding to the starting point as an initial navigation grid, and determining a plurality of target navigation grids positioned on an optimal path and a switching label corresponding to each target navigation grid in the path search process;
the exchange label characterizes whether a cross-layer path exists in the target navigation grid; a part of the connection points located in the target navigation grid form part of the path section of the cross-layer path;
and controlling the NPC to move from the level where the starting point is located to the level where the ending point is located according to all the target navigation grids and the exchange labels.
2. The method of claim 1, wherein performing a path search with the navigation grid corresponding to the starting point as an initial navigation grid, and determining a plurality of target navigation grids located on an optimal path and a switch label corresponding to each target navigation grid during the path search, comprises:
Taking out the navigation grid with the minimum total distance from the candidate navigation grid data table as a current navigation grid, and adding the current navigation grid into the considered navigation grid table;
the candidate navigation grid data table is used for maintaining distance information, father node information and the exchange label of the navigation grids to be considered; the distance information comprises an actual distance, a heuristic distance and a total distance corresponding to the navigation grid; the considered navigation grid table is used for maintaining navigation grids which are already involved in path searching;
if the current navigation grid is not the navigation grid corresponding to the end point, determining a plurality of adjacent navigation grids of the current navigation grid and the exchange label, and determining a target adjacent navigation grid meeting a preset condition and the distance information of the target adjacent navigation grid from the plurality of adjacent navigation grids;
adding the target adjacent navigation grid, the distance information of the target adjacent navigation grid and the father node information into the candidate navigation grid data table, returning to the step of taking out the navigation grid with the minimum total distance from the candidate navigation grid data table as the current navigation grid, and adding the current navigation grid into the considered navigation grid table;
If the current navigation grid is the navigation grid corresponding to the terminal point, or the candidate navigation grid data table is empty, tracing back a path according to the parent node information of the current navigation grid until a parent node encountered by tracing back is empty;
and taking all the traced navigation grids as the target navigation grid.
3. The cross-layer routing method of claim 2, wherein determining a target neighboring navigation grid satisfying a preset condition and the distance information of the target neighboring navigation grid from among a plurality of neighboring navigation grids of the current navigation grid, comprises:
judging whether the adjacent navigation grids are positioned in the candidate navigation grid data table or the considered navigation grid data table;
if not, determining the adjacent navigation grids as the target adjacent navigation grids and determining the distance information corresponding to the target navigation grids;
if the candidate navigation grid data table is located, new distance information of the adjacent navigation grids is redetermined;
when the actual distance in the new distance information is smaller than the actual distance stored in the candidate navigation grid data table, determining that the adjacent navigation grid is the target navigation grid, and replacing the stored distance information with the new distance information;
And presetting the current navigation grid as a father node of the target adjacent navigation grid.
4. A cross-layer routing method as recited in claim 3, wherein determining a plurality of adjacent navigation grids of the current navigation grid and the switch label comprises:
determining a navigation grid adjacent to the current navigation grid in a horizontal direction and a vertical direction as the adjacent navigation grid;
judging whether the connection point exists in the current navigation grid;
if yes, setting a first exchange label for the current navigation grid, and determining the navigation grid corresponding to the path end point of the partial path section formed by the connection points as the adjacent navigation grid;
if not, setting a second exchange label for the current navigation grid; wherein the first switch label characterizes the cross-layer path existing in the current navigation grid; the second switch label characterizes that the cross-layer path does not exist in the current navigation grid.
5. The cross-layer routing method of claim 1, wherein controlling the NPC to move from the level at which the start point is located to the level at which the end point is located according to all of the target navigation grid and the switch labels comprises:
Sequentially taking out each target navigation grid from the initial navigation grid;
judging whether the exchange label of the target navigation grid is a first exchange label or a second exchange label;
if the NPC is a first exchange tag, performing position interpolation between the connection points existing in the target navigation grid so as to enable the NPC to perform cross-layer movement until the NPC moves to the last connection point of the path segment;
if the target navigation grid is the second exchange label, performing position interpolation movement between the target navigation grid and the next target navigation grid;
and stopping interpolation movement after moving to the last target navigation grid.
6. The cross-layer routing method of claim 5, wherein interpolating locations between the connection points present within the target navigation grid to cause the NPC to perform cross-layer movement until the last of the connection points comprises:
calculating the distance between the current connection point and the next connection point;
if the distance is larger than the total distance moved by the NPC, updating the total distance moved by the NPC according to the moving distance of each frame of the NPC;
and determining the next connection point as the current connection point, and returning to the step of calculating the distance between the current connection point and the next connection point until the current connection point is the last connection point in the target navigation grid, and controlling the NPC to move from the target navigation grid to the next target navigation grid.
7. The cross-layer routing method of claim 5, wherein performing a position interpolation movement between the target navigation grid and a next target navigation grid comprises:
taking the navigation grid where the NPC is located after moving as a current target navigation grid;
calculating the distance between the current target navigation grid and the next target navigation grid;
if the distance is larger than the total distance which the NPC has moved, updating the total distance which the NPC has moved according to the moving distance of each frame of the NPC;
and controlling the NPC to move to the next target navigation grid, and returning to the step of calculating the distance between the current target navigation grid and the next target navigation grid.
8. A cross-layer way-finding device, comprising:
the acquisition module is used for acquiring the starting point and the end point of the NPC; wherein the start point and the end point are located at two different levels; the connecting area between the two levels is preset with a plurality of connecting points; each connection point corresponds to one navigation grid;
the searching module is used for searching a path by taking the navigation grid corresponding to the starting point as an initial navigation grid, and determining a plurality of target navigation grids positioned on the optimal path and a switching label corresponding to each target navigation grid in the path searching process;
The exchange label characterizes whether a cross-layer path exists in the target navigation grid; a part of the connection points located in the target navigation grid form part of the path section of the cross-layer path;
and the path finding module is used for controlling the NPC to move from the level where the starting point is located to the level where the ending point is located according to all the target navigation grids and the exchange labels.
9. A computer device, characterized in that it comprises a processor and a memory, in which at least one instruction or at least one program is stored, which is loaded and executed by the processor to implement the cross-layer routing method according to any of claims 1-7.
10. A readable storage medium having stored therein at least one instruction or at least one program loaded and executed by a processor to implement a cross-layer routing method as claimed in any one of claims 1 to 7.
CN202311688569.7A 2023-12-08 2023-12-08 Cross-layer path finding method, device, computer equipment and readable storage medium Pending CN117732072A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311688569.7A CN117732072A (en) 2023-12-08 2023-12-08 Cross-layer path finding method, device, computer equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311688569.7A CN117732072A (en) 2023-12-08 2023-12-08 Cross-layer path finding method, device, computer equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN117732072A true CN117732072A (en) 2024-03-22

Family

ID=90260185

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311688569.7A Pending CN117732072A (en) 2023-12-08 2023-12-08 Cross-layer path finding method, device, computer equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN117732072A (en)

Similar Documents

Publication Publication Date Title
CN110882542B (en) Training method, training device, training equipment and training storage medium for game intelligent agent
US7537523B2 (en) Dynamic player groups for interest management in multi-character virtual environments
CN107198883B (en) Path finding method and device for game object in virtual game
Szlapczynski Evolutionary sets of safe ship trajectories: a new approach to collision avoidance
CN100517346C (en) Path-finding method for optimal path
CN110755848B (en) Path finding method in game, terminal and readable storage medium
CN108268971B (en) Path searching method, device, processor and electronic device
CN108665117B (en) Calculation method and device for shortest indoor space path, terminal equipment and storage medium
CN110141862B (en) Method and device for mobile control in game, electronic equipment and storage medium
CN107367278A (en) A kind of indoor navigation method and equipment
CA2560722A1 (en) Pathfinding system
CN111202986B (en) Method and device for generating virtual track in game, processor and electronic device
CN111481931B (en) Path finding control method for virtual object in game, electronic equipment and storage medium
CN110909961B (en) BIM-based indoor path query method and device
CN112419779B (en) Selection method and device of unmanned vehicle stop point, storage medium and electronic equipment
US20020049690A1 (en) Method of expressing crowd movement in game, storage medium, and information processing apparatus
CN111773717A (en) Object control method and apparatus, storage medium, and electronic apparatus
CN111773687A (en) Map way finding method and device, storage medium and electronic device
KR20220095452A (en) Computer system of providing service consumption plan for efficient service migration in mobile edge computing environments, and method thereof
CN117732072A (en) Cross-layer path finding method, device, computer equipment and readable storage medium
CN116764225A (en) Efficient path-finding processing method, device, equipment and medium
CN107970610B (en) Planning method and device for 3D scene vertical space flight route
Amador et al. xTrek: An Influence‐Aware Technique for Dijkstra’s and A⁎ Pathfinders
Silva et al. Moving virtual agents forward in space and time
CN110472159A (en) Path generating method, device, medium and terminal device based on community service point

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination