Method and apparatus for controlling movement of virtual object, storage medium, and electronic device
By extending and searching the best possible path to the virtual object when there is a blockage in the next frame position of the virtual object in the game, the target movement path of the virtual object is generated, solving the problem of jagged feeling when the virtual object moves on the blocking edge, real-time path smooth and efficient path generation is achieved.
Patent Information
- Application Number
- CN202210799679.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-06
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2042-07-06
AI Technical Summary
In the game, virtual objects are prone to jagging when moving the blocking edge. The existing path smoothing algorithm needs to know the target points of the virtual objects and cannot handle the uncertain target points in real time.
When there is a blockage in the next frame position of the virtual object's current position, the first target point is determined and extended to obtain a second target point, and a search is performed based on the second target point to obtain the best point, and a target movement path of the virtual object is generated.
Real-time smoothing of virtual object movement paths is achieved, and the occurrence of jagging is avoided. There is no need to determine the target points of virtual objects in advance, and it does not affect the upper-level pathfinding results, which improves the efficiency of path smoothing.
Smart Images

Figure CN115193047B_ABST
Abstract
Description
Background Art
[0002] The movement of virtual objects is an essential part in games. In games, the navigation mesh is the most common and simplest way to block movement, which converts the movement of virtual objects from continuous space to discrete space.
[0003] When pathfinding in a discrete grid, when a virtual object approaches an obstacle, due to the obstacle being meshed, there will be an obvious sense of jaggedness when the virtual object moves along the edge of the obstacle. In related technologies, the path smoothing algorithm is used to solve this technical problem. Common path smoothing algorithms include the Floyd path smoothing algorithm and Bezier curves.
[0004] However, both the Floyd path smoothing algorithm and Bezier curves require knowing the target point of the virtual object's movement, and they cannot play a role in path smoothing for the movement of virtual objects with uncertain target points.
[0005] Therefore, a new method for controlling the movement of virtual objects needs to be provided.
[0006] It should be noted that the information of the invention in the above background art section is only used to strengthen the understanding of the background of the present invention, and thus may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention
[0007] The purpose of the present disclosure is to provide a method for controlling the movement of virtual objects, a device for controlling the movement of virtual objects, a computer-readable storage medium, and an electronic device, so as to at least overcome to some extent the problem of jaggedness when a virtual object moves along the edge of an obstacle caused by the limitations and defects of related technologies.
[0008] According to one aspect of the present disclosure, a method for controlling the movement of virtual objects is provided, including:
[0009] Responding to the user's manipulation of the virtual object, controlling the virtual object to move;
[0010] During the movement, when there is an obstacle at the next frame position of the current position of the virtual object, determining the first target point of the virtual object;
[0011] Extending the first target point to obtain a second target point, and searching based on the second target point to obtain the optimal point corresponding to the second target point;
[0012] Generating a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and controlling the virtual object to move according to the target movement path.
[0013] In an exemplary embodiment of the present disclosure, determining a first target point of the virtual object includes:
[0014] When there is no obstruction at the next frame position of the current position of the virtual object, determine the target point reached by the virtual object according to the user's manipulation of the virtual object;
[0015] Determine the target point reached by the virtual object as the first target point.
[0016] In an exemplary embodiment of the present disclosure, extending the first target point to obtain a second target point includes:
[0017] Obtain the moving direction of the virtual object, and obtain the extension distance of the first target point according to the moving speed of the virtual object and a preset moving parameter;
[0018] Extend the first target point along the moving direction of the virtual object through the extension to obtain the second target point.
[0019] In an exemplary embodiment of the present disclosure, searching based on the second target point to obtain an optimal point corresponding to the second target point includes:
[0020] Obtain idle nodes, and calculate the total cost from each of the idle nodes to the second target point through an A* search algorithm based on corner cost;
[0021] Obtain the optimal point corresponding to the second target point according to the total cost.
[0022] In an exemplary embodiment of the present disclosure, obtaining idle nodes and calculating the total cost from each of the idle nodes to the second target point through an A* search algorithm based on corner cost includes:
[0023] Obtain the distance cost from each of the idle nodes to the second target point through the A* search algorithm;
[0024] Calculate the corner cost of each of the idle nodes through a corner cost function;
[0025] Obtain the total cost from each of the idle nodes to the second target point through the distance cost and the corner cost of each of the idle nodes.
[0026] In an exemplary embodiment of the present disclosure, calculating the corner cost of each of the idle nodes through a corner cost function includes:
[0027] Obtain the maximum detection distance and the farthest detected node at the corner where each of the idle nodes is located;
[0028] Calculate the first distance and the second distance from each of the idle nodes to the corner, and the third distance and the fourth distance from each of the idle nodes to the farthest detected node;
[0029] Input the maximum detection distance, the first distance, the second distance, the third distance, and the fourth distance into the corner cost function to obtain the corner cost of each of the idle nodes.
[0030] In an exemplary embodiment of the present disclosure, obtaining the optimal point corresponding to the second target point according to the total cost includes:
[0031] Compare the total costs of each of the idle nodes to obtain the minimum total cost;
[0032] Use the idle node corresponding to the minimum total cost as the optimal point corresponding to the second target point.
[0033] In an exemplary embodiment of the present disclosure, generating the target movement path of the virtual object through the current position and the optimal point corresponding to the second target point includes:
[0034] Use the current position as the starting point and the optimal point corresponding to the second target point as the ending point, and through the A search algorithm to obtain the target movement path between the current position and the optimal point corresponding to the second target point.
[0035] According to one aspect of the present disclosure, there is provided a movement control device for a virtual object, including:
[0036] A virtual object movement module, configured to respond to a user's manipulation of the virtual object and control the virtual object to move;
[0037] A first target point determination module, configured to determine the first target point of the virtual object when there is an obstacle at the next frame position of the current position of the virtual object during the movement process;
[0038] A target point extension module, configured to extend the first target point to obtain a second target point, and perform a search based on the second target point to obtain the optimal point corresponding to the second target point;
[0039] A target movement path generation module, configured to generate the target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path.
[0040] According to one aspect of the present disclosure, there is provided a computer storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for controlling the movement of a virtual object described in any of the above exemplary embodiments is implemented.
[0041] According to one aspect of the present disclosure, there is provided an electronic device, including:
[0042] a processor; and
[0043] a memory for storing executable instructions of the processor;
[0044] wherein the processor is configured to execute the method for controlling the movement of a virtual object described in any of the above exemplary embodiments by executing the executable instructions.
[0045] A method for controlling the movement of a virtual object provided by an embodiment of the present disclosure responds to a user's manipulation of the virtual object and controls the virtual object to move; during the movement, when there is an obstacle at the next-frame position of the current position of the virtual object, a first target point of the virtual object is determined; the first target point is extended to obtain a second target point, and based on the second target point, a search is performed to obtain an optimal point corresponding to the second target point; through the current position and the optimal point corresponding to the second target point, a target movement path of the virtual object is generated, and the virtual object is controlled to move according to the target movement path; on the one hand, when there is an obstacle at the next-frame position of the current position of the virtual object, a first target point of the virtual object is determined, the first target point is extended to obtain a second target point, an optimal point corresponding to the second target point is obtained, and the path between the current position and the optimal point corresponding to the second target point is used as the target movement path of the virtual object. Compared with the traditional path smoothing algorithm, it is not necessary to determine the target point of the virtual object in advance. When there is an obstacle during the movement of the virtual object, the movement path of the virtual object is determined in real time, realizing real-time smoothing of the movement path of the virtual object; on the other hand, when smoothing the movement path of the virtual object, no additional storage space is required, nor is it necessary to change the terrain in the game, and the movement path of the virtual object is smoothed without affecting the upper-level pathfinding result, improving the efficiency of path smoothing.
[0046] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings here are incorporated into the specification and form a part of this specification, showing embodiments in accordance with the present invention, and are used together with the specification to explain the principles of the present invention. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0048] Figure 1 A flowchart schematically showing a method for controlling the movement of a virtual object according to an exemplary embodiment of the present invention.
[0049] Figure 2 A flowchart schematically showing a method for determining a first target point of a virtual object according to an exemplary embodiment of the present invention.
[0050] Figure 3 A flowchart schematically showing a method for extending the first target point to obtain a second target point according to an exemplary embodiment of the present invention.
[0051] Figure 4 A schematic diagram showing a scenario for extending the first target point according to an exemplary embodiment of the present invention.
[0052] Figure 5 A flowchart schematically showing a method for searching based on the second target point to obtain an optimal point corresponding to the second target point according to an exemplary embodiment of the present invention.
[0053] Figure 6 A flowchart schematically showing a method for calculating the total cost from each idle node to the second target point according to an exemplary embodiment of the present invention.
[0054] Figure 7 A flowchart schematically showing a method for calculating the corner cost of each idle node through a corner cost function according to an exemplary embodiment of the present invention.
[0055] Figure 8 A schematic diagram showing a scenario for calculating the corner cost of an idle node according to an exemplary embodiment of the present disclosure.
[0056] Figure 9 A flowchart schematically showing a method for obtaining an optimal point corresponding to the four-child target point according to the total cost according to an exemplary embodiment of the present disclosure.
[0057] Figure 10 A schematic diagram showing the movement trajectory of a virtual object when the optimal point corresponding to the first target point is used as the end point according to an exemplary embodiment of the present invention.
[0058] Figure 11Schematically shows a schematic diagram of the movement trajectory of a virtual object when the optimal point corresponding to the second target point is used as the end point, according to an exemplary embodiment of the present invention.
[0059] Figure 12 Schematically shows a block diagram of a movement control device for a virtual object, according to an exemplary embodiment of the present invention.
[0060] Figure 13 Schematically shows an electronic device for implementing the above-mentioned movement control method of a virtual object, according to an exemplary embodiment of the present invention. Detailed implementation manners
[0061] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, the exemplary embodiments can be implemented in various forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this invention will be more complete and comprehensive, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The features, structures, or characteristics described may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of the embodiments of the present invention. However, those skilled in the art will realize that the technical solutions of the present invention can be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be used. In other cases, well-known technical solutions are not shown or described in detail to avoid obscuring the various aspects of the present invention.
[0062] In addition, the accompanying drawings are only schematic illustrations of the present invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repeated description will be omitted. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0063] The movement of virtual objects is an essential part of games. Depending on different forms of obstacles, virtual objects usually have different movement and pathfinding behaviors. Among them, the navigation mesh is the most common and simplest way to implement movement obstacles. It plans the originally irregular terrain and obstacles into regular grids, converting the continuous space of the virtual object's movement into a discrete space.
[0064] There are a variety of implementation solutions for pathfinding in a discrete grid, such as: Dijkstra's algorithm, Floyd's algorithm, etc. Among them, Dijkstra's algorithm expands layer by layer outward from the starting point until it reaches the target point; Floyd's algorithm calculates the shortest path algorithm from one vertex to the remaining vertices, solving the shortest path problem in a graph. Common path smoothing algorithms include Floyd path smoothing algorithm and Bezier curve. The Floyd path smoothing algorithm tends to use straight lines to replace the jagged path, and the Bezier curve tends to use curves to replace several connected straight lines.
[0065] However, the paths obtained by traditional pathfinding algorithms can only guarantee the shortest path, but cannot consider the movement performance of virtual objects. As a result, obvious jaggedness will occur when virtual objects move near obstacles. Traditional path smoothing algorithms need to know the target point that the virtual object will reach later, and are usually used for path smoothing of robots, and cannot smooth the paths of virtual objects with unclear target points.
[0066] Based on one or more of the above problems, in this exemplary embodiment, a method for controlling the movement of a virtual object is first provided. This method can run on a device terminal, and the device terminal can include a desktop computer, a portable computer, a smart phone, a tablet computer, etc.; of course, those skilled in the art can also run the method of the present invention on other platforms according to needs, and this is not specifically limited in this exemplary embodiment.
[0067] The method for controlling the movement of a virtual object in an embodiment of the present disclosure can run on a terminal device or a server; among them, the terminal device can be a local terminal device. When the method for controlling the movement of a virtual object runs on the server, the method can be implemented and executed based on a cloud interaction system, where the cloud interaction system includes a server and a client device.
[0068] In an optional implementation, various cloud applications can be run under the cloud interaction system, such as cloud games. Taking cloud games as an example, cloud games refer to a game mode based on cloud computing. In the operation mode of cloud games, the operating body of the game program and the main body of the game screen presentation are separated. The storage and operation of the game character control method are completed on the cloud game server. The role of the client device is used for receiving and sending data and presenting the game screen. For example, the client device can be a display device with data transmission function close to the user side, such as a mobile terminal, a TV, a computer, a handheld computer, etc.; but the terminal device for information processing is a cloud game server in the cloud. When playing the game, the player operates the client device to send an operation instruction to the cloud game server. The cloud game server runs the game according to the operation instruction, encodes and compresses the game screen and other data, and returns it to the client device through the network. Finally, the client device decodes and outputs the game screen.
[0069] In an optional embodiment, the terminal device may be a local terminal device. Taking a game as an example, the local terminal device stores a game program and is used to present a game screen. The local terminal device is used to interact with the player through a graphical user interface, that is, the game program is downloaded and installed by an electronic device and run conventionally. The local terminal device may provide the graphical user interface to the player in a variety of ways, for example, it may be rendered and displayed on a display screen of the terminal, or provided to the player through a holographic projection. For example, the local terminal device may include a display screen and a processor, the display screen is used to present a graphical user interface, the graphical user interface includes a game screen, and the processor is used to run the game, generate a graphical user interface, and control the display of the graphical user interface on the display screen.
[0070] In a possible implementation, an embodiment of the present invention provides a method for controlling the movement of a virtual object, providing a graphical user interface through a device terminal, wherein the device terminal can be the local terminal device mentioned above, or can be a client device in the cloud interaction system mentioned above.
[0071] refer to Figure 1 As shown, the movement control method of the virtual object may include the following steps:
[0072] Step S110. In response to the user's manipulation of the virtual object, controlling the virtual object to move;
[0073] Step S120. During the movement, when there is an obstruction at the next frame position of the current position of the virtual object, determining a first target point of the virtual object;
[0074] Step S130. Extend the first target point to obtain a second target point, and perform a search based on the second target point to obtain the optimal point corresponding to the second target point;
[0075] Step S140. Generate a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path.
[0076] The above method for controlling the movement of a virtual object responds to the user's manipulation of the virtual object and controls the virtual object to move; during the movement, when there is an obstacle at the next frame position of the current position of the virtual object, determine the first target point of the virtual object; extend the first target point to obtain a second target point, and perform a search based on the second target point to obtain the optimal point corresponding to the second target point; generate a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path; on the one hand, when there is an obstacle at the next frame position of the current position of the virtual object, determine the first target point of the virtual object, extend the first target point to obtain a second target point, obtain the optimal point corresponding to the second target point, and use the path between the current position and the optimal point corresponding to the second target point as the target movement path of the virtual object. Compared with the traditional path smoothing algorithm, it is not necessary to determine the target point of the virtual object in advance. When there is an obstacle during the movement of the virtual object, the movement path of the virtual object is determined in real time, realizing real-time smoothing of the movement path of the virtual object; on the other hand, when smoothing the movement path of the virtual object, no additional storage space is required, nor is it necessary to change the terrain in the game. Moreover, without affecting the upper-level pathfinding result, the movement path of the virtual object is smoothed, improving the efficiency of path smoothing.
[0077] Hereinafter, each step involved in the method for controlling the movement of a virtual object according to the exemplary embodiments of the present disclosure will be explained and described in detail.
[0078] In step S110, in response to the user's manipulation of the virtual object, control the virtual object to move.
[0079] In the present exemplary embodiment, the user can control the movement of a virtual object in a game, including the movement direction and movement speed of the virtual object. Among them, the user's manipulation of the virtual object can be a pressing operation or a sliding operation in the user graphical interface displayed on the terminal device, and no specific limitation is made in the present exemplary embodiment. After responding to the user's manipulation of the virtual object on the terminal device, the virtual object is controlled to move in the navigation mesh according to the user's operation. Among them, the movement direction and movement speed of the virtual object are related to the user's manipulation; the navigation mesh, also commonly known as the walking surface, is a polygon mesh data structure used for navigation and pathfinding in complex spaces and marking where walking is possible, and is often used to carry more functions, such as identifying the terrain at that location and what actions the character at that location should take, such as walking, swimming, climbing, etc.
[0080] In step S120, during the movement, when there is an obstacle at the next frame position of the current position of the virtual object, determine the first target point of the virtual object.
[0081] In the present exemplary embodiment, when the virtual object moves in the navigation mesh, the current position of the virtual object and the next frame position of the current position can be obtained. When there is no obstacle at the next frame position of the current position of the virtual object, the virtual object will move in the navigation mesh according to the user's manipulation. However, when there is an obstacle at the next frame position of the current position of the virtual object, the first target point of the virtual object can be determined first. Refer to Figure 2 As shown, determining the first target point of the virtual object may include step S210 and step S220:
[0082] Step S210. When there is no obstacle at the next frame position of the current position of the virtual object, determine the target point reached by the virtual object according to the user's manipulation of the virtual object;
[0083] Step S220. Determine the target point reached by the virtual object as the first target point.
[0084] Hereinafter, step S210 and step S220 will be further explained and described. Specifically, when there is an obstacle at the next frame position of the current position of the virtual object, first, assume that the obstacle does not exist. When the obstacle does not exist, the virtual object can move in the navigation mesh according to the user's manipulation, and according to the user's manipulation, the target point that the virtual object can reach in the navigation mesh can be determined, and this target point is determined as the first target point. Among them, when there is no obstacle, the target point that the virtual object can reach can be determined by the movement direction of the virtual object, the movement speed of the virtual object, and the duration of one frame in the game.
[0085] In the present exemplary embodiment, when there is an obstacle at the next-frame position of the current position of the virtual object, a first target point is determined, and the movement path of the virtual object is optimized according to the first target point, thereby improving the accuracy of smooth path generation of the virtual object.
[0086] In step S130, the first target point is extended to obtain a second target point, and a search is performed based on the second target point to obtain an optimal point corresponding to the second target point.
[0087] In the present exemplary embodiment, when there is an obstacle at the next-frame position of the current position of the virtual object, since the virtual object cannot pass through the obstacle to reach the first target point and in order to smooth the path of the virtual object, the first target point can be extended. Referring to Figure 3 as shown, extending the first target point to obtain a second target point may include step S310 and step S320:
[0088] Step S310. Obtain the moving direction of the virtual object, and obtain the extension distance of the first target point according to the moving speed of the virtual object and a preset movement parameter.
[0089] Step S320. Along the moving direction of the virtual object, extend the first target point by the extension distance to obtain the second target point.
[0090] Hereinafter, step S310 and step S320 will be further explained and described. Specifically, when extending the first target point, first, obtain the moving direction of the virtual object, and obtain the extension distance of the first target point according to the moving speed of the virtual object and a preset movement parameter. The preset movement parameter may be the duration of one frame. In the present exemplary embodiment, the duration of one frame is not specifically limited, and those skilled in the art can limit the duration of one frame according to needs; the extension distance of the first target point can be obtained by multiplying the moving speed of the virtual object by the duration of one frame. After obtaining the extension distance of the first target point, the first target point can be extended along the moving direction of the virtual object to the second target point, and the distance between the first target point and the second target point is the extension distance.
[0091] For example, referring to Figure 4 as shown, in Figure 4In the case where the virtual object moves to before the obstruction, since the virtual object cannot pass through the obstruction, the target point that the virtual object can reach through the user's manipulation when there is no obstruction can be used as the first target point. After obtaining the first target point, the optimal point corresponding to the first target point can be obtained through the pathfinding algorithm. Among them, node A is the optimal point corresponding to the first target point. In the navigation grid, each grid in the navigation grid is called a node. After obtaining node A, the virtual object will move from the current position to node A. During this period, the user's manipulation of the virtual object remains valid all the time. Therefore, in order to avoid the jagged feeling generated by the movement of the virtual object, the first target point can be extended to obtain the second target point.
[0092] After obtaining the second target point, refer to Figure 5 As shown, based on the second target point, search is performed to obtain the optimal point corresponding to the second target point, which may include step S510 and step S520:
[0093] Step S510. Obtain idle nodes, and calculate the total cost from each of the idle nodes to the second target point through the A* search algorithm based on the corner cost; Step S520. Obtain the optimal point corresponding to the second target point according to the total cost.
[0094] Below, step S510 and step S520 will be further explained and described. Specifically, after obtaining the second target point, since the virtual object will not pass through the obstruction to reach the second target point, it is necessary to traverse the idle nodes to find the optimal point corresponding to the second target point among the idle nodes. First, obtain the idle nodes, and calculate the total cost from each idle node to the second target point through the A* search algorithm based on the corner cost, and obtain the optimal point corresponding to the second target point according to the total cost from each idle node to the second target point.
[0095] Further, refer to As shown, obtain the idle nodes, and calculate the total cost from each of the idle nodes to the second target point through the A* search algorithm based on the corner cost, which may include step S610 - step S630:
[0096] Further, refer to Figure 6 As shown, obtain the idle nodes, and calculate the total cost from each of the idle nodes to the second target point through the A* search algorithm based on the corner cost, which may include step S610 - step S630: Step S610. Obtain the distance cost from each of the idle nodes to the second target point through the A* search algorithm;
[0097] Step S610. Obtain the distance cost from each of the idle nodes to the second target point through the A* search algorithm; Step S620. Calculate the corner cost of each of the idle nodes through the corner cost function;
[0098] Step S620. Calculate the corner cost of each of the idle nodes through the corner cost function;
[0099] Step S630. Obtain the total cost from each of the idle nodes to the second target point based on the distance cost and the corner cost of each of the idle nodes.
[0100] Next, steps S610 - S630 will be further explained and described. Specifically, first, the distance cost from each idle node to the second target point is obtained through the A search algorithm. Among them, the distance cost can be obtained by calculating the Euclidean distance from the idle node to the second target point. After obtaining the distance cost, in order to avoid the optimal point corresponding to the second target point being located in the corner formed by the obstacles, therefore, the corner cost of each idle node can also be calculated through the corner cost function. When any idle node is closer to the corner formed by the obstacles, the corner cost of this idle node is greater, and it will be far away from this idle node during pathfinding; after obtaining the distance cost and the corner cost, the total cost from each idle node to the second target point can be obtained according to the sum of the distance cost and the corner cost.
[0101] In addition, when determining whether an idle node is located in the corner formed by the obstacles, it can be judged by the length of the nodes occupied by the obstacles. For example, when the number of nodes occupied by the first obstacle is 3, the number of nodes occupied by the second obstacle is 3, and there is an intersection between the first obstacle and the second obstacle, there must be a corner formed by the first obstacle and the second obstacle. When any idle node is located in the 3 × 3 rectangle composed of the number of nodes occupied by the first obstacle and the number of nodes occupied by the second obstacle, this idle node can be considered to be located in the corner.
[0102] Furthermore, referring to Figure 7 as shown, calculating the corner cost of each of the idle nodes through the corner cost function may include steps S710 - S730:
[0103] Step S710. Obtain the maximum detection distance and the farthest detection node of the corner where each of the idle nodes is located;
[0104] Step S720. Calculate the first distance and the second distance from each of the idle nodes to the corner, the third distance and the fourth distance from each of the idle nodes to the farthest detection node;
[0105] Step S730. Input the maximum detection distance, the first distance, the second distance, the third distance, and the fourth distance into the corner cost function to obtain the corner cost of each of the idle nodes.
[0106] Next, steps S710 - S730 will be further explained and described. Specifically, first, calculate the maximum detection distance of the corner where each idle node is located and the farthest detection node of each idle node; among them, the maximum detection distance of the corner where each idle node is located is related to the position of the idle node in the corner. First, determine the detection area included in the rectangle formed by the obstacles, then determine the detection area where the idle node is located, and determine the maximum detection distance of each idle node included in this detection area based on the number of navigation grids included in any side of this detection area; for the farthest detection node of each idle node, in the rectangle formed by the obstacles, with this idle node as the origin, move along the horizontal and vertical directions away from the corner respectively to obtain the first farthest detection node and the second farthest detection node.
[0107] Then, calculate the first distance and the second distance from the idle node to the corner, as well as the third distance and the fourth distance from the idle node to the farthest detection node; among them, the first distance and the second distance are respectively the number of navigation grids that the idle node moves in the horizontal and vertical directions to reach the corner; the third distance and the fourth distance are respectively the number of navigation grids that the idle node moves to the first farthest detection node and the second farthest detection node. After obtaining the maximum detection distance, the first distance, the second distance, the third distance, and the fourth distance, the maximum detection distance, the first distance, the second distance, the third distance, and the fourth distance can be input into the corner cost function to obtain the corner cost of each idle node. Among them, the corner cost function is the expression (1)
[0108] (1)
[0109] where x is any idle node, K is a constant coefficient, D is the maximum detection distance, d 1 is the first distance, d 2 is the second distance, d 3 is the third distance, d 4 is the fourth distance.
[0110] Refer to Figure 8 as shown, in Figure 8The shaded area is a block. For the idle node E, the detection area where it is located can be a square formed by nodes E, F, H, and I, or a square formed by A, B, C, D, E, F, G, H, and I. Assuming the idle node is in the square formed by E, F, H, and I, the maximum detection distance is 2. Assuming the idle node is in the square formed by A, B, C, D, E, F, G, H, and I, the maximum detection distance is 3. The first distance from the idle node E to the corner is 2, the second distance is 2, the third distance to the farthest detection node is 2, and the fourth distance is 2. Therefore, when K is 1 and D is 3, the corner cost of D is 。
[0111] In the present exemplary embodiment, referring to Figure 9 as shown, obtaining the optimal point corresponding to the second target point according to the total cost may include step S910 and step S920:
[0112] Step S910. Compare the total costs of each of the idle nodes to obtain the minimum total cost;
[0113] Step S920. Use the idle node corresponding to the minimum total cost as the optimal point corresponding to the second target point.
[0114] Hereinafter, step S910 and step S920 will be further explained and described. First, compare the total costs of each idle node to obtain the minimum total cost, and use the idle node corresponding to the minimum total cost as the optimal point corresponding to the second target point.
[0115] In the present exemplary embodiment, referring to Figure 4 , when the first target point is not extended, after obtaining the optimal point A corresponding to the second target point, the virtual object will move from the current position to the optimal point A. When the user's manipulation of the virtual object remains unchanged, the virtual object will continuously move along the block, and the final movement trajectory refers to Figure 10 as shown, with an obvious sense of jaggedness. However, by extending the first target point to obtain the second target point, so that the virtual object bypasses the optimal point corresponding to the first target point and directly reaches the optimal point B corresponding to the second target point, its movement trajectory refers to Figure 11 as shown, reducing the jagged phenomenon generated during the movement of the virtual object.
[0116] In step S140, generate the target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path.
[0117] In the present exemplary embodiment, generating a target movement path of the virtual object based on the current position and the optimal point corresponding to the second target point includes:
[0118] Taking the current position as the starting point and the optimal point corresponding to the second target point as the ending point, and obtaining the target movement path between the current position and the optimal point corresponding to the second target point through an A search algorithm.
[0119] Specifically, taking the current position of the virtual object as the starting point and the optimal point corresponding to the second target point as the ending point, and performing a search through an A search algorithm to obtain the path between the current position and the optimal point corresponding to the second target point, and determining this path as the target movement path of the virtual object, so that the virtual object moves according to this target movement path, realizing smooth movement of the virtual object.
[0120] In the present exemplary embodiment, it is not necessary to change the terrain in the game, nor will it affect the upper-level pathfinding result. Directly through an A search algorithm, search for the target movement path between the current position and the optimal point corresponding to the second target point. During the movement of the virtual object, it avoids entering corners, realizes the smoothing of the movement path of the virtual object, and improves the efficiency of path smoothing.
[0121] The method for controlling the movement of a virtual object provided by the exemplary embodiment of the present disclosure has at least the following advantages: On the one hand, when there is an obstacle at the next frame position of the current position of the virtual object, determine the first target point of the virtual object, and extend the first target point to obtain the second target point, obtain the optimal point corresponding to the second target point, and use the path between the current position and the optimal point corresponding to the second target point as the target movement path of the virtual object. Compared with the traditional path smoothing algorithm, it is not necessary to determine the target point of the virtual object in advance. When there is an obstacle during the movement of the virtual object, the movement path of the virtual object is determined in real time, realizing real-time smoothing of the movement path of the virtual object; on the other hand, when smoothing the movement path of the virtual object, no additional storage space is required, nor is it necessary to change the terrain in the game, and the movement path of the virtual object is smoothed without affecting the upper-level pathfinding result, improving the efficiency of path smoothing.
[0122] The exemplary embodiment of the present disclosure also provides a device for controlling the movement of a virtual object. Referring to Figure 12 as shown, it may include: a virtual object movement module 1210, a first target point determination module 1220, a target point extension module 1230, and a target movement path generation module 1240. Among them:
[0123] A virtual object movement module 1210, configured to control the movement of the virtual object in response to a user's manipulation of the virtual object;
[0124] A first target point determination module 1220, configured to determine a first target point of the virtual object when there is an obstruction at the next frame position of the current position of the virtual object during the movement;
[0125] A target point extension module 1230, configured to extend the first target point to obtain a second target point, and search based on the second target point to obtain an optimal point corresponding to the second target point;
[0126] A target movement path generation module 1240, configured to generate a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path.
[0127] The specific details of each module in the above virtual object movement control device have been described in detail in the corresponding virtual object movement control method, and thus will not be elaborated here.
[0128] In an exemplary embodiment of the present disclosure, determining the first target point of the virtual object includes:
[0129] When there is no obstruction at the next frame position of the current position of the virtual object, determining a target point reached by the virtual object according to the user's manipulation of the virtual object;
[0130] Determining the target point reached by the virtual object as the first target point.
[0131] In an exemplary embodiment of the present disclosure, extending the first target point to obtain a second target point includes:
[0132] Obtaining the movement direction of the virtual object, and obtaining an extension distance of the first target point according to the movement speed of the virtual object and a preset movement parameter;
[0133] Extending the first target point along the movement direction of the virtual object through the extension to obtain the second target point.
[0134] In an exemplary embodiment of the present disclosure, searching based on the second target point to obtain an optimal point corresponding to the second target point includes:
[0135] Obtaining free nodes, and calculating the total cost from each free node to the second target point through an A* search algorithm based on corner cost; Calculating the total cost from each of the free nodes to the second target point;
[0136] Obtain the optimal point corresponding to the second target point according to the total cost.
[0137] In an exemplary embodiment of the present disclosure, obtain idle nodes, and calculate the total cost from each of the idle nodes to the second target point through an A* search algorithm, including:
[0138] Obtain the distance cost from each of the idle nodes to the second target point through the A* search algorithm;
[0139] Calculate the corner cost of each of the idle nodes through a corner cost function;
[0140] Obtain the total cost from each of the idle nodes to the second target point through the distance cost and the corner cost of each of the idle nodes.
[0141] In an exemplary embodiment of the present disclosure, calculate the corner cost of each of the idle nodes through a corner cost function, including:
[0142] Obtain the maximum detection distance and the farthest detection node of the corner where each of the idle nodes is located;
[0143] Calculate the first distance and the second distance from each of the idle nodes to the corner, and the third distance and the fourth distance from each of the idle nodes to the farthest detection node;
[0144] Input the maximum detection distance, the first distance, the second distance, the third distance, and the fourth distance into the corner cost function to obtain the corner cost of each of the idle nodes.
[0145] In an exemplary embodiment of the present disclosure, obtain the optimal point corresponding to the second target point according to the total cost, including:
[0146] Compare the total costs of each of the idle nodes to obtain the minimum total cost;
[0147] Use the idle node corresponding to the minimum total cost as the optimal point corresponding to the second target point.
[0148] In an exemplary embodiment of the present disclosure, generate a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, including:
[0149] Use the current position as the starting point and the optimal point corresponding to the second target point as the ending point, and obtain the target movement path between the current position and the optimal point corresponding to the second target point through the A* search algorithm.
[0150] It should be noted that although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present invention, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0151] In addition, although the steps of the method in the present invention are described in a specific order in the drawings, this does not require or imply that these steps must be executed in that specific order, or that all the steps shown must be executed to achieve the desired result. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step for execution, and / or one step may be decomposed into multiple steps for execution, etc.
[0152] In an exemplary embodiment of the present invention, an electronic device capable of implementing the above method is also provided.
[0153] Those skilled in the art can understand that various aspects of the present invention can be implemented as a system, a method, or a program product. Therefore, various aspects of the present invention can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software aspects, which can be collectively referred to as "circuitry", "module", or "system" here.
[0154] The following refers to Figure 13 to describe the electronic device 1300 according to this embodiment of the present invention. Figure 13 The shown electronic device 1300 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.
[0155] As Figure 13 shown, the electronic device 1300 is presented in the form of a general-purpose computing device. The components of the electronic device 1300 may include, but are not limited to: the at least one processing unit 1310 mentioned above, the at least one storage unit 1320 mentioned above, a bus 1330 connecting different system components (including the storage unit 1320 and the processing unit 1310), and a display unit 1340.
[0156] Among them, the storage unit stores program code, and the program code can be executed by the processing unit 1310, so that the processing unit 1310 executes the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of this specification. For example, the processing unit 1310 can execute as Figure 1Step S110 shown in the figure: In response to a user's manipulation of a virtual object, control the virtual object to move; S120: During the movement, when there is an obstacle at the next frame position of the current position of the virtual object, determine a first target point of the virtual object; S130: Extend the first target point to obtain a second target point, and search based on the second target point to obtain an optimal point corresponding to the second target point; S140: Generate a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path.
[0157] The storage unit 1320 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 13201 and / or a cache storage unit 13202, and may further include a read-only storage unit (ROM) 13203.
[0158] The storage unit 1320 may further include a program / utilities 13204 having a set (at least one) of program modules 13205. Such program modules 13205 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment.
[0159] The bus 1330 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of a variety of bus structures.
[0160] The electronic device 1300 may also communicate with one or more external devices 1400 (such as a keyboard, a pointing device, a Bluetooth device, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1300, and / or may communicate with any device that enables the electronic device 1300 to communicate with one or more other computing devices (such as a router, a modem, etc.). Such communication may be carried out through an input / output (I / O) interface 1350. And, the electronic device 1300 may also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 1360. As shown in the figure, the network adapter 1360 communicates with other modules of the electronic device 1300 through the bus 1330. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0161] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described herein can be implemented by software or by a combination of software and necessary hardware. Therefore, the technical solutions according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present invention.
[0162] In an exemplary embodiment of the present invention, there is also provided a computer-readable storage medium, on which a program product capable of implementing the above method of this specification is stored. In some possible embodiments, various aspects of the present invention can also be implemented in the form of a program product, which includes program code. When the program product runs on a terminal device, the program code is used to cause the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of this specification.
[0163] The program product for implementing the above method according to the embodiments of the present invention can adopt a portable compact disc read-only memory (CD-ROM) and include program code, and can run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, the readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device.
[0164] The program product can adopt any combination of one or more readable media. The readable media can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0165] A computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. The readable signal medium can also be any readable medium other than a readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device.
[0166] The program code contained on the readable medium can be transmitted using any appropriate medium, including but not limited to wireless, wired, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0167] The program code for performing the operations of the present invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, executed as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user's computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., by connecting through the Internet using an Internet service provider).
[0168] In addition, the above drawings are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present invention, and are not for limiting purposes. It is easy to understand that the processes shown in the above drawings do not indicate or limit the chronological order of these processes. Additionally, it is also easy to understand that these processes can be executed, for example, synchronously or asynchronously in multiple modules.
[0169] Those skilled in the art will readily think of other embodiments of the present invention after considering the specification and practicing the invention herein. This application is intended to cover any variations, uses, or adaptations of the present invention that follow the general principles of the present invention and include known common knowledge or conventional technical means in the technical field not invented by the present invention. The specification and embodiments are only regarded as exemplary, and the true scope and spirit of the present invention are pointed out by the claims.
Claims
1. A method for controlling the movement of a virtual object, characterized in that, comprising: responding to the user's manipulation of the virtual object, and controlling the virtual object to move; during the movement, when there is an obstruction at the next frame position of the current position of the virtual object, assuming that there is no obstruction at the next frame position of the current position of the virtual object, and determining the target point reached by the virtual object according to the user's manipulation of the virtual object; determining the target point reached by the virtual object as the first target point; Obtain the moving direction of the virtual object, and obtain the extended distance of the first target point based on the moving speed of the virtual object and the duration of one frame; along the moving direction of the virtual object, extend the first target point to obtain a second target point; through A Use a search algorithm to obtain the distance cost from each idle node to the second target point; obtain the maximum detection distance and the farthest detection node of the corner where each idle node is located; calculating the first distance and the second distance from each of the free nodes to the corner, the third distance and the fourth distance from each of the free nodes to the farthest detection node; inputting the maximum detection distance, the first distance, the second distance, the third distance and the fourth distance into a corner cost function to obtain the corner cost of each of the free nodes; obtaining the total cost from each of the free nodes to the second target point through the distance cost and the corner cost of each of the free nodes; obtaining the optimal point corresponding to the second target point according to the total cost; The corner cost function , where x is any idle node, K is a constant coefficient, D is the maximum detection distance, and d 1 is the first distance, d 2 is the second distance, d 3 is the third distance, d 4 is the fourth distance; the first distance and the second distance are respectively the number of navigation grids included when the idle node moves to the corner in the horizontal and vertical directions; the third distance and the fourth distance are respectively the number of navigation grids included when the idle node moves to the first farthest detection node and the second farthest detection node; the first farthest detection node and the second farthest detection node are nodes obtained by moving along the horizontal and vertical directions away from the corner with the idle node as the origin in the rectangle formed by the obstacles. generating a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, and controlling the virtual object to move according to the target movement path.
2. The method for controlling the movement of a virtual object according to claim 1, characterized in that, obtaining the optimal point corresponding to the second target point according to the total cost, including: comparing the total cost of each of the free nodes to obtain the minimum total cost; taking the free node corresponding to the minimum total cost as the optimal point corresponding to the second target point.
3. The method for controlling the movement of a virtual object according to claim 1, characterized in that, generating a target movement path of the virtual object through the current position and the optimal point corresponding to the second target point, including: Taking the current position as the starting point and the optimal point corresponding to the second target point as the ending point, through the A search algorithm, obtain the target movement path between the current position and the optimal point corresponding to the second target point.
4. A device for controlling the movement of a virtual object, characterized in that, comprising: a virtual object movement module, configured to respond to the user's manipulation of the virtual object and control the virtual object to move; a first target point determination module, configured to, during the movement, when there is an obstruction at the next frame position of the current position of the virtual object, assume that there is no obstruction at the next frame position of the current position of the virtual object, and determine the target point reached by the virtual object according to the user's manipulation of the virtual object; determining the target point reached by the virtual object as the first target point; The target point extension module is used to obtain the moving direction of the virtual object, and obtain the extension distance of the first target point according to the moving speed of the virtual object and the duration of one frame; along the moving direction of the virtual object, extend the first target point to obtain a second target point; through A The search algorithm obtains the distance cost from each idle node to the second target point; obtain the maximum detection distance and the farthest detection node of the corner where each idle node is located; calculating the first distance and the second distance from each of the free nodes to the corner, the third distance and the fourth distance from each of the free nodes to the farthest detection node; inputting the maximum detection distance, the first distance, the second distance, the third distance and the fourth distance into a corner cost function to obtain the corner cost of each of the free nodes; obtaining the total cost from each of the free nodes to the second target point through the distance cost and the corner cost of each of the free nodes; obtaining the optimal point corresponding to the second target point according to the total cost; The corner cost function , where x is any idle node, K is a constant coefficient, D is the maximum detection distance, d 1 is the first distance, d 2 is the second distance, d 3 is the third distance, d 4 is the fourth distance; the first distance and the second distance are respectively the number of navigation grids included when the idle node moves horizontally and vertically to the corner; the third distance and the fourth distance are respectively the number of navigation grids included when the idle node moves to the first farthest detection node and the second farthest detection node; the first farthest detection node and the second farthest detection node are nodes obtained by moving the idle node as the origin along the horizontal and vertical directions away from the corner in the rectangle formed by the blockage; A target movement path generation module is configured to generate a target movement path of the virtual object based on the current position and the optimal point corresponding to the second target point, and control the virtual object to move according to the target movement path.
5. A computer storage medium having a computer program stored thereon, wherein, when the computer program is executed by a processor, it implements the method for controlling the movement of a virtual object according to any one of claims 1-3.
6. An electronic device, wherein, it includes: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the method for controlling the movement of a virtual object according to any one of claims 1-3 by executing the executable instructions.
Citation Information
Patent Citations
Way-finding method and device, and computer readable storage medium
CN113368499A
Path planning method, electronic equipment and mobile device
CN114184203A