Game pathfinding control methods, devices, processing equipment, and storage media
Patent Information
- Application Number
- CN202410102326.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-20
- Publication Date
- 2026-09-01
- Estimated Expiration
- 2041-04-20
AI Technical Summary
[0006]本发明的目的在于,针对上述现有技术中的不足,提供一种游戏的寻路控制方法、装置、处理设备及存储介质,以便解决相关技术中,玩家对应的目标对象在寻路路径上移动时,容易被障碍物所干扰,降低了用户体验的问题
[0065]本发明的有益效果是:本申请实施例提供一种游戏的寻路控制方法,包括:从游戏场景中的主干道路上,确定距离目标虚拟对象的起点最近的路点为起始参考点,其中,主干道路为游戏场景中障碍物的数量小于或等于预设数量阈值的道路;从主干道路上,确定距离目标虚拟对象的终点最近的路点为终止参考点;从起始参考点和终止参考点之间的多条路径中,确定第一目标路径;根据第一目标路径,控制目标虚拟对象从起点移动至终点;根据第一目标路径,控制目标虚拟对象从起点移动至终点之前,方法还包括:采用预设的直接寻路算法,获取从起点至终点的第二目标路径;分别计算第一目标路径和第二目标路径的寻路距离,寻路距离用于指示:通过对应路径进行移动所需的消耗值;根据第一目标路径,控制目标虚拟对象从起点移动至终点,包括:若第一目标路径的寻路距离小于或等于第二目标路径的寻路距离,则根据第一目标路径,控制目标虚拟对象从起点移动至终点。基于目标虚拟对象的起点和终点分别从主干道上确定起始参考点和终止参考点,继而从起始参考点和终止参考点之间多条路径确定第一目标路径,根据第一目标路径控制目标虚拟对象从起点移动至终点,主干道路上的障碍物的数量小于或等于预设数量阈值,降低了目标虚拟对象被障碍物干扰的概率,而且还可以减小目标虚拟对象在移动过程中的消耗,提高了用户体验。
Smart Images

Figure CN117899482B_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application filed on April 20, 2021, with parent application number 2021104275395 and titled "Pathfinding Control Method, Apparatus, Processing Equipment and Storage Medium for Games". Technical Field
[0002] This invention relates to the field of game technology, and more specifically, to a pathfinding control method, apparatus, processing device, and storage medium for games. Background Technology
[0003] With the continuous development of internet technology, the gaming industry has also experienced rapid growth, resulting in a proliferation of diverse games. Games typically incorporate various functions, with automatic pathfinding being one of the most common.
[0004] In related technologies, a preset automatic pathfinding algorithm is used to find the shortest path and determine the path. The pathfinding path is easy to plan in the area where the obstacle is located.
[0005] However, in related technologies, when the player's target object moves along the pathfinding path, it is easily interfered with by obstacles, which reduces the user experience. Summary of the Invention
[0006] The purpose of this invention is to address the shortcomings of the prior art by providing a pathfinding control method, device, processing equipment, and storage medium for games, so as to solve the problem that in the related art, when the player's target object moves on the pathfinding path, it is easily interfered with by obstacles, which reduces the user experience.
[0007] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows:
[0008] In a first aspect, embodiments of the present invention provide a pathfinding control method for a game, the method comprising:
[0009] From the main road in the game scene, determine the waypoint closest to the starting point of the target virtual object as the starting reference point, wherein the main road is a road in the game scene with a number of obstacles less than or equal to a preset number threshold;
[0010] From the main road, determine the waypoint closest to the endpoint of the target virtual object as the termination reference point;
[0011] A first target path is determined from multiple paths between the starting reference point and the ending reference point;
[0012] Based on the first target path, control the target virtual object to move from the starting point to the ending point;
[0013] Before controlling the target virtual object to move from the starting point to the ending point according to the first target path, the method further includes:
[0014] A pre-defined direct pathfinding algorithm is used to obtain a second target path from the starting point to the ending point;
[0015] Calculate the pathfinding distances for the first target path and the second target path, respectively. The pathfinding distances are used to indicate the cost required to move along the corresponding paths.
[0016] The step of controlling the target virtual object to move from the starting point to the ending point according to the first target path includes:
[0017] If the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, then the target virtual object is controlled to move from the starting point to the ending point according to the first target path.
[0018] Optionally, the method further includes:
[0019] Configure a preset area centered on the main road as a road safety zone to delay the actions of non-player characters entering the preset area.
[0020] Optionally, determining the first target path from multiple paths between the starting reference point and the ending reference point includes:
[0021] The evaluation value of each path is calculated based on the weight value corresponding to the road type of each waypoint on each path and the path length of the road type.
[0022] Based on the evaluation value of each path, the first target path is determined from the plurality of paths.
[0023] Optionally, the method further includes:
[0024] If the pathfinding distance of the first target path is greater than the pathfinding distance of the second target path, then the target virtual object is controlled to move from the starting point to the ending point according to the second target path.
[0025] Optionally, before controlling the target virtual object to move from the starting point to the ending point according to the first target path if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, the method further includes:
[0026] Determine the starting and ending points in the first target path respectively;
[0027] The pathfinding distance of the first target path is obtained by performing a weighted sum operation on the path length from the starting point to the initial entry point, the path length from the initial entry point to the final entry point, and the path length from the final entry point to the end point.
[0028] Optionally, determining the starting point in the first target path includes:
[0029] Based on the starting point, starting from the starting reference point on the first target path, multiple waypoints in the first direction are used as multiple first entry points, and the first direction is the movement direction of the target virtual object on the first target path;
[0030] The starting point is determined from the plurality of first entry points by connecting the starting point with each first entry point.
[0031] Optionally, determining the starting point from the plurality of first entry points based on the lines connecting the starting point and each first entry point includes:
[0032] Determine the line connecting the starting point and each first entry point, and the first angle between the line connecting each first entry point and the adjacent first entry point in the first direction;
[0033] The first entry point when the first included angle is an obtuse angle is taken as the starting entry point.
[0034] Optionally, determining the termination cut-in point in the first target path includes:
[0035] Based on the endpoint, starting from the termination reference point on the first target path, multiple waypoints in a second direction serve as multiple second entry points, where the second direction is the opposite of the first direction.
[0036] The termination entry point is determined from the plurality of second entry points based on the lines connecting the endpoint and each second entry point.
[0037] Optionally, determining the termination cut-in point in the first target path includes:
[0038] Determine the line connecting the endpoint and each second entry point, and the second included angle between each second entry point and the line connecting the adjacent second entry point in the second direction;
[0039] The second entry point when the second included angle is obtuse is taken as the termination entry point.
[0040] Optionally, the step of using a preset direct pathfinding algorithm to obtain the second target path from the starting point to the ending point includes:
[0041] A preset direct pathfinding algorithm is used to determine multiple candidate paths from the game scene with the shortest path length and a distance of multiple preset interval thresholds from the scene edge.
[0042] The connecting path with the largest interval among the multiple candidate paths is determined as the second target path.
[0043] Secondly, embodiments of the present invention also provide a pathfinding control device for a game, the device comprising:
[0044] The determination module is used to determine the starting point of the target virtual object from the main road in the game scene as the starting reference point, wherein the main road is a road in the game scene with the number of obstacles less than or equal to a preset threshold; determine the ending point of the target virtual object from the main road as the ending reference point; and determine a first target path from multiple paths between the starting reference point and the ending reference point.
[0045] The control module is used to control the target virtual object to move from the starting point to the ending point according to the first target path;
[0046] The device further includes:
[0047] The acquisition module is used to acquire a second target path from the starting point to the ending point using a preset direct pathfinding algorithm;
[0048] The calculation module is used to calculate the pathfinding distances of the first target path and the second target path, respectively. The pathfinding distances are used to indicate the cost required to move through the corresponding paths.
[0049] The control module is further configured to, if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, control the target virtual object to move from the starting point to the ending point according to the first target path.
[0050] Optionally, the device further includes:
[0051] The configuration module is used to configure a preset area centered on the main road as a road safety zone, so as to delay the actions of non-player characters entering the preset area.
[0052] Optionally, the determining module is further configured to calculate the evaluation value of each path based on the weight value corresponding to the road type of each waypoint on each path and the path length of the road type; and determine the first target path from the multiple paths based on the evaluation value of each path.
[0053] Optionally, the device further includes:
[0054] The first control module is configured to, if the pathfinding distance of the first target path is greater than the pathfinding distance of the second target path, control the target virtual object to move from the starting point to the ending point according to the second target path.
[0055] Optionally, the device further includes:
[0056] The first determining module is used to determine the starting cut-in point and the ending cut-in point in the first target path, respectively;
[0057] The second control module is used to perform a weighted sum operation on the path length from the starting point to the initial cut-in point, the path length between the initial cut-in point and the final cut-in point, and the path length between the final cut-in point and the end point to obtain the pathfinding distance of the first target path.
[0058] Optionally, the first determining module is further configured to, based on the starting point, take multiple waypoints along the first target path from the starting reference point as multiple first entry points, where the first direction is the movement direction of the target virtual object on the first target path; and determine the starting entry point from the multiple first entry points based on the lines connecting the starting point and each of the first entry points.
[0059] Optionally, the first determining module is further configured to determine the line connecting the starting point and each first entry point, and the first angle between the line connecting each first entry point and the adjacent first entry point in the first direction; and to take the first entry point when the first angle is obtuse as the starting entry point.
[0060] Optionally, the first determining module is further configured to, based on the endpoint, use multiple waypoints on the first target path starting from the termination reference point in a second direction as multiple second entry points, wherein the second direction is the opposite direction to the first direction; and determine the termination entry point from the multiple second entry points based on the line connecting the endpoint and each of the second entry points.
[0061] Optionally, the first determining module is further configured to determine the line connecting the endpoint and each second entry point, and the second included angle between the line connecting each second entry point and the adjacent second entry point in the second direction; and to take the second entry point when the second included angle is an obtuse angle as the termination entry point.
[0062] Optionally, the acquisition module is used to use a preset direct pathfinding algorithm to determine multiple candidate paths from the game scene whose distance from the scene edge is a multiple preset interval threshold and whose path length is the shortest; and to determine the connecting path with the largest interval from the multiple candidate paths as the second target path.
[0063] Thirdly, embodiments of the present invention also provide an electronic device, including: a memory and a processor, wherein the memory stores a computer program executable by the processor, and the processor executes the computer program to implement the pathfinding control method for the game described in any of the first aspects above.
[0064] Fourthly, embodiments of the present invention also provide a storage medium storing a computer program, wherein when the computer program is read and executed, it implements the pathfinding control method for the game described in any of the first aspects above.
[0065] The beneficial effects of this invention are as follows: This application provides a pathfinding control method for a game, comprising: determining a starting reference point from a main road in the game scene that is closest to the starting point of a target virtual object, wherein the main road is a road in the game scene where the number of obstacles is less than or equal to a preset threshold; determining a ending reference point from the main road that is closest to the ending point of the target virtual object; determining a first target path from multiple paths between the starting reference point and the ending reference point; controlling the target virtual object to move from the starting point to the ending point according to the first target path; before controlling the target virtual object to move from the starting point to the ending point according to the first target path, the method further comprises: using a preset direct pathfinding algorithm to obtain a second target path from the starting point to the ending point; calculating the pathfinding distance of the first target path and the second target path respectively, the pathfinding distance being used to indicate the cost required to move through the corresponding path; controlling the target virtual object to move from the starting point to the ending point according to the first target path, comprising: if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, then controlling the target virtual object to move from the starting point to the ending point according to the first target path. Based on the starting point and ending point of the target virtual object, a starting reference point and an ending reference point are determined from the main road. Then, a first target path is determined from multiple paths between the starting reference point and the ending reference point. The target virtual object is controlled to move from the starting point to the ending point according to the first target path. The number of obstacles on the main road is less than or equal to a preset threshold, which reduces the probability of the target virtual object being interfered with by obstacles. In addition, it can also reduce the consumption of the target virtual object during the movement process and improve the user experience. Attached Figure Description
[0066] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0067] Figure 1 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0068] Figure 2 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0069] Figure 3 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0070] Figure 4 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0071] Figure 5 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0072] Figure 6 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0073] Figure 7 A schematic diagram of a movement path provided in an embodiment of the present invention;
[0074] Figure 8 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0075] Figure 9 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0076] Figure 10 A flowchart illustrating a pathfinding control method for a game provided in an embodiment of the present invention;
[0077] Figure 11 A schematic diagram of the structure of a pathfinding control device for a game provided in an embodiment of the present invention;
[0078] Figure 12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0079] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0080] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0081] In the description of this application, it should be noted that if the terms "upper", "lower", etc. appear to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship that the product of this application is usually placed in, it is only for the convenience of describing this application and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.
[0082] Furthermore, the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Additionally, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion.
[0083]
[0084] 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 that are clearly listed, but may include other steps or units that are not clearly listed or that are inherent to those processes, methods, products, or devices.
[0085] It should be noted that, where there is no conflict, the features in the embodiments of this application can be combined with each other.
[0086] This application provides a pathfinding control method for games. The executing entity can be a terminal, a server, or other types of electronic devices, and this application does not impose specific limitations on this. When the executing entity is a terminal, the terminal can be any one of a desktop computer, laptop computer, tablet computer, or smartphone. The following uses a terminal as an example to explain the pathfinding control method for games provided in this application.
[0087] Figure 1 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 1 As shown, the method may include:
[0088] S101. From the main road in the game scene, determine the waypoint closest to the starting point of the target virtual object as the starting reference point.
[0089] Among them, the main road is the road in the game scene where the number of obstacles is less than or equal to a preset threshold.
[0090] In this embodiment, the obstacle can be a virtual non-player object that can attack the target virtual object. Since there are fewer virtual non-player objects on main roads, attacks from virtual non-player objects can be reduced when the target virtual object moves on the main road. Of course, the obstacle can also be other virtual objects that hinder the movement of the target virtual object; this embodiment imposes specific limitations on this.
[0091] In addition, the preset quantity threshold can be set according to actual needs, based on experience, or in other ways. This application embodiment does not impose specific restrictions on this.
[0092] It should be noted that the starting point of the target virtual object can be its current location within the game scene. The target virtual object can be the virtual object corresponding to the current player. The game scene may or may not display the target virtual object; instead, the game scene will be presented from the perspective of the target virtual object.
[0093] S102. From the main road, determine the waypoint closest to the endpoint of the target virtual object as the termination reference point.
[0094] The endpoint of the target virtual object can be the location that the target virtual object is expected to reach. Both the starting reference point and the ending reference point are reference points on the main road.
[0095] In addition, main roads can be roads that developers have planned in advance in the game scene.
[0096] S103. Determine the first target path from the multiple paths between the starting reference point and the ending reference point.
[0097] Among them, multiple paths share the same starting and ending reference points.
[0098] In some implementations, the terminal may employ a first target path determination algorithm to determine an optimal path from among multiple paths between the starting reference point and the ending reference point, as the first target path.
[0099] It should be noted that the first target path can be the path that is most convenient for the target virtual object to walk on among multiple paths. For example, the first target path can be the path with the shortest distance, the path with the shortest walking time, or the path with the least consumption of resources, etc.
[0100] S104. Based on the first target path, control the target virtual object to move from the starting point to the end point.
[0101] In one possible implementation, the terminal can determine the final path based on the first target path, and automatically navigate based on the path to control the target virtual object to move from the starting point to the destination, thereby achieving automatic pathfinding.
[0102] In summary, this application provides a pathfinding control method for games, comprising: determining a starting reference point from a main road in the game scene that is closest to the starting point of a target virtual object, wherein the main road is a road in the game scene where the number of obstacles is less than or equal to a preset threshold; determining a ending reference point from the main road that is closest to the ending point of the target virtual object; determining a first target path from multiple paths between the starting reference point and the ending reference point; and controlling the target virtual object to move from the starting point to the ending point according to the first target path. By determining the starting and ending reference points from the main road based on the starting and ending points of the target virtual object, and then determining the first target path from multiple paths between the starting and ending reference points, and controlling the target virtual object to move from the starting point to the ending point according to the first target path, the method reduces the probability of the target virtual object being interfered with by obstacles, thus improving the user experience, as the number of obstacles on the main road is less than or equal to the preset threshold.
[0103] Furthermore, in the pathfinding control method for games provided in this application embodiment, the main roads in the game scene are all far from the scene edge, which can improve the smoothness of automatic pathfinding when the target virtual character moves on the main road.
[0104] In this embodiment, the types of main road points may further include: main road points, branch road points, interactive gateway points, and teleportation gateway points. Interactive gateway points: When a pathfinding reaches an interactive gateway point, the system checks for obstructions in the directional ray from the interactive gateway point to the next path point. If a gateway-type obstruction exists, the system waits; otherwise, it can proceed directly. Teleportation gateway points: These points have triggers. When entering a teleportation gateway point, the system determines whether the pathfinding is on the other side of the portal based on the direction and distance, and continues pathfinding along the original route.
[0105] Optionally, the method may further include:
[0106] Configure a preset area centered on the main road as a road safety zone, and delay the actions of non-player characters who enter the preset area.
[0107] Optionally, action delay processing may include: reaction speed delay processing.
[0108] In some implementations, the terminal can determine a preset safe distance, and the area at a preset safe distance from the main road can be configured as a road safety zone. When a non-player character enters the preset area, the reaction speed of the non-player character can be delayed.
[0109] For example, non-player characters can be virtual monster AI (Artificial Intelligence).
[0110] It should be noted that the preset area may include: the area on the left side of the main road that is at a preset safe distance from the center line of the main road, and the area on the right side of the main road that is at a preset safe distance from the center line of the main road.
[0111] In summary, by specially treating the obstacles in this safe zone, making their reaction speed slower than that of regular obstacles and delaying their entry into combat, the obstacles are unable to catch up with the target virtual character as it moves forward without stopping, further reducing the danger of the target virtual character automatically navigating.
[0112] Optional, Figure 2 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 2 As shown, the first target path is determined from multiple paths between the starting reference point and the ending reference point, including:
[0113] S201. Calculate the evaluation value of each path based on the weight value corresponding to the road type of each waypoint on each path and the path length of the road type.
[0114] Each path can include multiple waypoints, and each waypoint can have a corresponding road type.
[0115] In some implementations, for a given path, the terminal can determine the length of each road type based on the road type of each waypoint along the path, and then perform a weighted sum of the lengths of each road type and the corresponding weight values to obtain the evaluation value of the path. This process can be applied to other paths as well, and will not be elaborated upon here.
[0116] Furthermore, for a waypoint of a certain road type on a path, the length of that road type can be obtained by calculating and summing the distances between any two consecutive waypoints of that road type. This process can be repeated to calculate the lengths of other road types.
[0117] For example, for path a, the path length is x when the road type is a main road and y when the road type is a branch road. The weight value of the main road can be m and the weight value of the branch road can be n. Then the evaluation value of path a = x*m + y*n. The weight value of the main road can be less than the weight value of the branch road.
[0118] S202. Based on the evaluation value of each path, determine the first target path from multiple paths.
[0119] Optionally, the terminal can determine the path with the smallest evaluation value from multiple paths as the first target path based on the evaluation value of each path.
[0120] Optional, Figure 3 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 3 As shown, before the process of controlling the target virtual object to move from the starting point to the ending point according to the first target path in S104, the method may further include:
[0121] S301. Using a preset direct pathfinding algorithm, obtain the second target path from the starting point to the ending point.
[0122] Optionally, the terminal can use a preset direct pathfinding algorithm to find the path from the starting point to the terminal according to the principle of shortest path finding.
[0123] S302. Calculate the pathfinding distances for the first target path and the second target path, respectively.
[0124] The pathfinding distance indicates the cost required to move along the corresponding path.
[0125] The process of controlling the target virtual object to move from the starting point to the ending point according to the first target path in S104 above may include:
[0126] S303. If the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, then according to the first target path, control the target virtual object to move from the starting point to the ending point.
[0127] The terminal can control the target virtual object to find its way based on the path with the lowest cost.
[0128] In this embodiment of the application, if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, it indicates that the consumption value of the first target path is small, and the target virtual object can be controlled to move from the starting point to the ending point according to the first target path.
[0129] Optionally, the method may further include:
[0130] If the pathfinding distance of the first target path is greater than the pathfinding distance of the second target path, then the target virtual object is controlled to move from the starting point to the ending point according to the second target path.
[0131] Similarly, if the pathfinding distance of the first target path is greater than that of the second target path, it means that the cost of the second target path is smaller, and the target virtual object can be controlled to move from the starting point to the ending point according to the second target path.
[0132] In some implementations, the cost of the second target path can be the sum of the distances between waypoints on the second target path. The cost of the second target path can be represented by costByDirect, and the cost of the first target path can be represented by costByTrunk.
[0133] Optional, Figure 4 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 4 As shown, in S303 above, if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, before controlling the target virtual object to move from the starting point to the ending point according to the first target path, the method may further include:
[0134] S401. Determine the starting and ending entry points in the first target path respectively.
[0135] It should be noted that the target virtual object can move directly from the starting point to the starting point, and the target virtual object can move directly from the ending point to the ending point.
[0136] S402. Perform a weighted sum operation on the path length from the starting point to the initial entry point, the path length between the initial entry point and the final entry point, and the path length between the final entry point and the end point to obtain the pathfinding distance of the first target path.
[0137] In this embodiment of the application, the path length from the starting point to the initial cut-in point and the path length from the ending cut-in point to the end point can have the same weight, which can be called weight coefficient 1; the path length between the initial cut-in point and the ending cut-in point can be called weight coefficient 2.
[0138] In addition, the path length from the starting point to the initial entry point can be represented by preDis, the path length between the initial entry point and the final entry point can be represented by trunkDis, and the path length between the final entry point and the end point can be represented by afterDis. Then the pathfinding distance of the first target path can be: weight coefficient 1*(preDis+afterDis)+weight coefficient 2*trunkDis.
[0139] Optional, Figure 5 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 5 As shown, the process of determining the starting point in the first target path in S401 above may include:
[0140] S501. Based on the starting point, starting from the initial reference point on the first target path, multiple waypoints in the first direction are used as multiple first entry points.
[0141] The first direction can be the direction in which the target virtual object moves along the first target path.
[0142] In addition, the number of multiple first entry points can be a first preset number.
[0143] S502. Determine the starting point from among the multiple first entry points based on the lines connecting the starting point and each first entry point.
[0144] In some implementations, the terminal determines multiple first entry points. The terminal can sequentially traverse multiple first entry points in a first direction, draw lines between the starting point and each first entry point, analyze the lines corresponding to each first entry point, and determine the starting entry point from multiple first entry points.
[0145] In summary, based on the lines connecting the starting point and each first entry point, a starting entry point is determined from multiple first entry points. This allows the target virtual character to move directly from the starting point to the starting entry point, thereby moving onto the first target path, making the movement path of the target virtual character from the starting point to the first target path more reasonable.
[0146] Optional, Figure 6 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 6 As shown, the process of determining the starting point from multiple first entry points based on the lines connecting the starting point and each first entry point in S501 above may include:
[0147] S601. Determine the line connecting the starting point and each first entry point, and the first included angle between the line connecting each first entry point and the adjacent first entry point in the first direction.
[0148] S602, take the first entry point when the first included angle is obtuse as the starting entry point.
[0149] In this embodiment, the terminal can sequentially traverse multiple first entry points along a first direction until it obtains a first entry point where the first included angle is obtuse, and then stop traversing. Alternatively, the terminal can determine the first included angle corresponding to each first entry point, thus identifying the first entry point with the obtuse angle from among the multiple first entry points.
[0150] It should be noted that if the first included angle corresponding to each of the multiple first entry points is not an obtuse angle, then the last first entry point in the first direction among the multiple first entry points can be taken as the starting entry point.
[0151] Figure 7 A schematic diagram of a movement path provided in an embodiment of the present invention, such as... Figure 7 As shown, multiple initial entry points can include: point A, point B, and point C. The starting point can be O, where the angle between the line connecting point O and point A, and the line connecting point A and point B, is acute; and the angle between the line connecting point O and point B, and the line connecting point B and point C, is obtuse. Therefore, point B can be used as the initial entry point.
[0152] In summary, the target virtual character can move directly from the starting point to the initial entry point, and then move onto the first target path, continuing to move along the first direction. Using the first entry point where the first included angle is obtuse as the initial entry point makes the target virtual character's movement trajectory more reasonable, preventing the target virtual character from taking detours.
[0153] Optional, Figure 8 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 8 As shown, the process of determining the termination point in the first target path in S401 above may include:
[0154] S801. Based on the destination, starting from the termination reference point on the first target path, multiple waypoints in the second direction are used as multiple second entry points.
[0155] The second direction is the opposite direction to the first direction.
[0156] Furthermore, the number of multiple second entry points can be a second preset number. The first preset number and the second preset number can be the same or different, and this application embodiment does not impose specific limitations on this.
[0157] S802. Determine the termination point from multiple second entry points based on the lines connecting the endpoint and each second entry point.
[0158] In some implementations, the terminal determines multiple second entry points. The terminal can sequentially traverse multiple second entry points in the second direction, draw lines between the endpoint and each second entry point, analyze the lines corresponding to each second entry point, and determine the termination entry point from multiple second entry points.
[0159] In summary, based on the lines connecting the endpoint and each of the second entry points, a termination entry point is determined from among the multiple second entry points. This allows the target virtual character to move directly from the termination entry point to the endpoint, thus moving from the first target path to the endpoint, making the movement path of the target virtual character from the first target path to the endpoint more reasonable.
[0160] Optional, Figure 9 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 9 As shown, the process of determining the termination point in the first target path in S401 above may include:
[0161] S901. Determine the line connecting the endpoint and each second entry point, and the second included angle between the line connecting each second entry point and the adjacent second entry point in the second direction.
[0162] S902, take the second entry point when the second included angle is obtuse as the termination entry point.
[0163] In this embodiment, the terminal can sequentially traverse multiple second entry points in the second direction until a second entry point with an obtuse angle is obtained, at which point the traversal stops. Alternatively, the terminal can determine the second angle corresponding to each second entry point, thus identifying the second entry point with an obtuse angle from among the multiple second entry points.
[0164] It should be noted that if the included angle corresponding to each of the multiple second entry points is not an obtuse angle, then the last second entry point in the second direction among the multiple second entry points can be taken as the termination entry point.
[0165] Figure 7 A schematic diagram of a movement path provided in an embodiment of the present invention, such as... Figure 7 As shown, multiple second entry points can include: point D, point E, and point F. The endpoint can be P. If the angle between the line connecting point P and point D, and the angle between the line connecting point D and point E, is obtuse, then point D can be used as the termination entry point.
[0166] In summary, the target virtual character can move directly from the termination entry point to the destination, thus exiting the first target path. Using the second entry point, where the second included angle is obtuse, as the termination entry point makes the movement trajectory of the target virtual character from the first target path to the destination more reasonable, preventing the target virtual character from taking a detour.
[0167] Optional, Figure 10 This is a flowchart illustrating a pathfinding control method for a game according to an embodiment of the present invention, as shown below. Figure 10 As shown, the process of obtaining the second target path from the starting point to the ending point using a preset direct pathfinding algorithm in S301 above may include:
[0168] S1001. Using a preset direct pathfinding algorithm, determine multiple candidate paths from the game scene with the shortest path length and a distance of multiple preset interval thresholds from the scene edge.
[0169] Among them, the intervals from the scene edge are multiple preset interval thresholds, and the shortest candidate paths can form a multi-layer pathfinding map.
[0170] In addition, multiple preset interval thresholds can be set according to experience or actual needs. For example, the multiple preset interval thresholds can be 1 meter, 0.4 meters and 0.2 meters respectively.
[0171] S1002. Determine the connecting path with the largest interval from multiple candidate paths as the second target path.
[0172] It should be noted that the terminal can find the collision radius of the largest connection from the routing graph with the largest collision radius decreasing in order of whether it is connected or not, so as to stay as far away from the edge as possible. That is, the terminal prioritizes the connected path with the largest interval as the second target path to ensure that the waypoints of the second target path are not close to the edge.
[0173] In summary, this application provides a pathfinding control method for games. Based on the starting and ending points of a target virtual object, a starting reference point and an ending reference point are determined from the main road. Then, a first target path is determined from multiple paths between the starting and ending reference points. The target virtual object is controlled to move from the starting point to the ending point according to the first target path. The number of obstacles on the main road is less than or equal to a preset threshold, reducing the probability of the target virtual object being interfered with by obstacles and improving the user experience. Furthermore, in this game pathfinding control method, the main roads in the game scene are all far from the scene edge, improving the smoothness of automatic pathfinding when the target virtual character moves on the main road. Additionally, when pathfinding according to the second target path, it is possible to stay as far away from the edge as possible to ensure that the waypoints of the second target path do not touch the edge.
[0174] The following describes the pathfinding control device, electronic device, and storage medium used to execute the pathfinding control method of the game provided in this application. For the specific implementation process and technical effects, please refer to the relevant content of the pathfinding control method of the game mentioned above, which will not be repeated below.
[0175] Figure 11This is a schematic diagram of the structure of a pathfinding control device for a game provided in an embodiment of the present invention, as shown below. Figure 11 As shown, the device may include:
[0176] The determining module 1101 is used to determine, from the main road in the game scene, the waypoint closest to the starting point of the target virtual object as the starting reference point, wherein the main road is a road in the game scene with the number of obstacles less than or equal to a preset number threshold; determine, from the main road, the waypoint closest to the ending point of the target virtual object as the ending reference point; and determine, from multiple paths between the starting reference point and the ending reference point, a first target path.
[0177] The control module 1102 is used to control the target virtual object to move from the starting point to the ending point according to the first target path.
[0178] Optionally, the device further includes:
[0179] The configuration module is used to configure a preset area centered on the main road as a road safety zone, so as to delay the actions of non-player characters entering the preset area.
[0180] Optionally, the determining module 1101 is further configured to calculate the evaluation value of each path based on the weight value corresponding to the road type of each waypoint on each path and the path length of the road type; and determine the first target path from the plurality of paths based on the evaluation value of each path.
[0181] Optionally, the device further includes:
[0182] The acquisition module is used to acquire a second target path from the starting point to the ending point using a preset direct pathfinding algorithm;
[0183] The calculation module is used to calculate the pathfinding distances of the first target path and the second target path, respectively. The pathfinding distances are used to indicate the cost required to move through the corresponding paths.
[0184] The control module is further configured to, if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, control the target virtual object to move from the starting point to the ending point according to the first target path.
[0185] Optionally, the device further includes:
[0186] The first control module is configured to, if the pathfinding distance of the first target path is greater than the pathfinding distance of the second target path, control the target virtual object to move from the starting point to the ending point according to the second target path.
[0187] Optionally, the device further includes:
[0188] The first determining module is used to determine the starting cut-in point and the ending cut-in point in the first target path, respectively;
[0189] The second control module is used to perform a weighted sum operation on the path length from the starting point to the initial cut-in point, the path length between the initial cut-in point and the final cut-in point, and the path length between the final cut-in point and the end point to obtain the pathfinding distance of the first target path.
[0190] Optionally, the first determining module is further configured to, based on the starting point, take multiple waypoints along the first target path from the starting reference point as multiple first entry points, where the first direction is the movement direction of the target virtual object on the first target path; and determine the starting entry point from the multiple first entry points based on the lines connecting the starting point and each of the first entry points.
[0191] Optionally, the first determining module is further configured to determine the line connecting the starting point and each first entry point, and the first angle between the line connecting each first entry point and the adjacent first entry point in the first direction; and to take the first entry point when the first angle is obtuse as the starting entry point.
[0192] Optionally, the first determining module is further configured to, based on the endpoint, use multiple waypoints on the first target path starting from the termination reference point in a second direction as multiple second entry points, wherein the second direction is the opposite direction to the first direction; and determine the termination entry point from the multiple second entry points based on the line connecting the endpoint and each of the second entry points.
[0193] Optionally, the first determining module is further configured to determine the line connecting the endpoint and each second entry point, and the second included angle between the line connecting each second entry point and the adjacent second entry point in the second direction; and to take the second entry point when the second included angle is an obtuse angle as the termination entry point.
[0194] Optionally, the acquisition module is used to use a preset direct pathfinding algorithm to determine multiple candidate paths from the game scene whose distance from the scene edge is a multiple preset interval threshold and whose path length is the shortest; and to determine the connecting path with the largest interval from the multiple candidate paths as the second target path.
[0195] The above-described device is used to execute the method provided in the foregoing embodiments, and its implementation principle and technical effect are similar, so they will not be described again here.
[0196] These modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more digital signal processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). Alternatively, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a system-on-a-chip (SOC).
[0197] Figure 12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, such as... Figure 12 As shown, the electronic device includes a processor 1201 and a memory 1202. The memory 1202 is used to store programs, and the processor 1201 calls the programs stored in the memory 1202 to execute the above-described method embodiment. The specific implementation and technical effects are similar, and will not be described in detail here.
[0198] Optionally, the present invention also provides a program product, such as a computer-readable storage medium, including a program that, when executed by a processor, is used to perform the above-described method embodiments.
[0199] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0200] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0201] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0202] The integrated units implemented as software functional units described above can be stored in a computer-readable storage medium. These software functional units, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0203] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A pathfinding control method for a game, characterized in that, The method includes: From the main road in the game scene, determine the waypoint closest to the starting point of the target virtual object as the starting reference point, wherein the main road is a road in the game scene with a number of obstacles less than or equal to a preset number threshold; From the main road, determine the waypoint closest to the endpoint of the target virtual object as the termination reference point; A first target path is determined from multiple paths between the starting reference point and the ending reference point; Based on the first target path, control the target virtual object to move from the starting point to the ending point; Before controlling the target virtual object to move from the starting point to the ending point according to the first target path, the method further includes: A pre-defined direct pathfinding algorithm is used to obtain a second target path from the starting point to the ending point; Calculate the pathfinding distances for the first target path and the second target path, respectively. The pathfinding distances are used to indicate the cost required to move along the corresponding paths. The step of controlling the target virtual object to move from the starting point to the ending point according to the first target path includes: If the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, then according to the first target path, the target virtual object is controlled to move from the starting point to the ending point; The method further includes: Configure a preset area centered on the main road as a road safety zone to delay the actions of non-player characters entering the preset area.
2. The method according to claim 1, characterized in that, Determining the first target path from multiple paths between the starting reference point and the ending reference point includes: The evaluation value of each path is calculated based on the weight value corresponding to the road type of each waypoint on each path and the path length of the road type. Based on the evaluation value of each path, the first target path is determined from the plurality of paths.
3. The method according to claim 1, characterized in that, The method further includes: If the pathfinding distance of the first target path is greater than the pathfinding distance of the second target path, then the target virtual object is controlled to move from the starting point to the ending point according to the second target path.
4. The method according to claim 3, characterized in that, If the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, then, based on the first target path, before controlling the target virtual object to move from the starting point to the ending point, the method further includes: Determine the starting and ending points in the first target path respectively; The pathfinding distance of the first target path is obtained by performing a weighted sum operation on the path length from the starting point to the initial entry point, the path length from the initial entry point to the final entry point, and the path length from the final entry point to the end point.
5. The method according to claim 3, characterized in that, Determining the starting point in the first target path includes: Based on the starting point, starting from the starting reference point on the first target path, multiple waypoints in the first direction are used as multiple first entry points, and the first direction is the movement direction of the target virtual object on the first target path; The starting point is determined from the plurality of first entry points by connecting the starting point with each first entry point.
6. The method according to claim 5, characterized in that, The step of determining the starting entry point from the plurality of first entry points based on the lines connecting the starting point and each first entry point includes: Determine the line connecting the starting point and each first entry point, and the first angle between the line connecting each first entry point and the adjacent first entry point in the first direction; The first entry point when the first included angle is an obtuse angle is taken as the starting entry point.
7. The method according to claim 3, characterized in that, Determining the termination cut-in point in the first target path includes: Based on the endpoint, starting from the termination reference point on the first target path, multiple waypoints in a second direction serve as multiple second entry points, where the second direction is the opposite of the first direction. The termination entry point is determined from the plurality of second entry points based on the lines connecting the endpoint and each second entry point.
8. The method according to claim 7, characterized in that, Determining the termination cut-in point in the first target path includes: Determine the line connecting the endpoint and each second entry point, and the second included angle between each second entry point and the line connecting the adjacent second entry point in the second direction; The second entry point when the second included angle is obtuse is taken as the termination entry point.
9. The method according to claim 1, characterized in that, The step of using a preset direct pathfinding algorithm to obtain the second target path from the starting point to the ending point includes: Using a preset direct pathfinding algorithm, multiple candidate paths with the shortest path length and a distance of multiple preset interval thresholds from the game scene edge are determined. The connecting path with the largest interval among the multiple candidate paths is determined as the second target path.
10. A pathfinding control device for a game, characterized in that, The device includes: The determination module is used to determine the starting point of the target virtual object from the main road in the game scene as the starting reference point, wherein the main road is a road in the game scene with the number of obstacles less than or equal to a preset threshold; determine the ending point of the target virtual object from the main road as the ending reference point; and determine a first target path from multiple paths between the starting reference point and the ending reference point. The control module is used to control the target virtual object to move from the starting point to the ending point according to the first target path; The device further includes: The acquisition module is used to acquire a second target path from the starting point to the ending point using a preset direct pathfinding algorithm; The calculation module is used to calculate the pathfinding distances of the first target path and the second target path, respectively. The pathfinding distances are used to indicate the cost required to move through the corresponding paths. The control module is further configured to, if the pathfinding distance of the first target path is less than or equal to the pathfinding distance of the second target path, control the target virtual object to move from the starting point to the ending point according to the first target path; The device further includes: The configuration module is used to configure a preset area centered on the main road as a road safety zone, so as to delay the actions of non-player characters entering the preset area.
11. An electronic device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program executable by the processor, and the processor executes the computer program to implement the pathfinding control method for the game according to any one of claims 1-9.
12. A storage medium, characterized in that, The storage medium stores a computer program, which, when read and executed, implements the pathfinding control method for the game as described in any one of claims 1-9.
Citation Information
Patent Citations
Way finding method and device in game, medium and electronic equipment
CN109621420A
Way-finding method in game, terminal and readable storage medium
CN110755848A