Virtual character path planning method and device, electronic device, and storage medium
By obtaining the initial path sequence of the start and end points in the game scene, performing curve fitting and sampling, identifying and adjusting the curve path points, and generating a smooth and uniform target path sequence, the problem of uneven movement of virtual characters in the prior art is solved, and smooth movement of virtual characters in accordance with kinematic laws is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-19
- Publication Date
- 2026-03-17
AI Technical Summary
In existing path planning schemes, the path points are not smooth or uniform, and the curvature is too high, which causes the movement of the AI-controlled virtual character to be uneven, and the starting direction is inconsistent with the initial orientation, which cannot meet the kinematic requirements.
By obtaining the starting and ending points of the virtual character in the game scene, the initial path sequence is determined, and curve fitting and sampling are performed to identify the sub-path sequence of curves. For path points with insufficient turning radius, curve fitting is performed again to generate a smooth and uniform target path sequence.
The generated target path sequence enables the virtual character to move smoothly, conforms to the laws of kinematics, avoids the problems of drastic changes in direction and excessive curvature at path points, and achieves smooth movement of the virtual character.
Smart Images

Figure CN114404985B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to path planning methods and apparatus for virtual characters, electronic devices, and storage media. Background Technology
[0002] AI (Artificial Intelligence) controlled virtual characters, added to games, are important participants, playing a crucial role in protecting new players, improving matchmaking speed, customizing game content, and ensuring long-term game operation. For movable AI virtual characters, finding a path that meets constraints is essential for enabling them to autonomously move from any given starting point to a destination within the scene. Generally, the sequence of waypoints connecting the starting and ending points is called a path, and the strategy for constructing the path is called path planning.
[0003] In related technologies, path planning is generally performed by converting the game scene into a data object and then running a search algorithm on the data object. Existing path planning schemes have the following problems with the resulting path sequences: 1) Unsmooth path points: the direction of the lines connecting path points changes drastically, causing the AI-controlled character to move unevenly; 2) Uneven path points: the distance between adjacent path points in the path sequence is too large, which is not conducive to controlling the movement of the AI-controlled character; 3) Excessively high path point curvature: there may be situations where the turning radius of a curve formed by several consecutive path points in the path sequence is too small, which may not meet the kinematic movement requirements of the AI-controlled character; 4) Starting problems: the direction of the path sequence may be inconsistent with the initial orientation of the AI-controlled character. When the AI-controlled virtual character cannot turn in place, the AI-controlled character cannot use the path sequence.
[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0005] In view of the above problems, this application is made to provide a path planning method and apparatus, electronic device, and storage medium for virtual characters that overcome or at least partially solve the above problems, including:
[0006] A path planning method for a virtual character, the method comprising:
[0007] Obtain the starting point and ending point of the virtual character in the game scene, and determine the initial path sequence connecting the starting point and the ending point based on the game scene;
[0008] The initial path sequence is subjected to curve fitting to obtain a fitted curve;
[0009] The fitted curve is sampled to obtain a sampling path sequence, which includes multiple sampling path points;
[0010] Determine multiple sub-path sequences in the sampling path sequence to form curves, each sub-path sequence consisting of turning path points that form the same curve;
[0011] When the turning radius of a turning point in the sub-path sequence is less than a preset first turning radius threshold, the turning point in the sub-path sequence is subjected to curve fitting again to update the path corresponding to the sub-path sequence in the fitted curve, and the updated fitted curve is sampled to obtain the target path sequence.
[0012] Optionally, determining the initial path sequence connecting the starting point and the ending point based on the game scene includes:
[0013] Generate the pathfinding mesh model corresponding to the game scene;
[0014] Based on the pathfinding grid model, a preset pathfinding algorithm is used to determine the initial path sequence from the starting point to the ending point.
[0015] Optionally, determining the initial path sequence from the starting point to the ending point using a preset pathfinding algorithm based on the pathfinding grid model includes:
[0016] Determine the inflection points from the starting point to the ending point in the pathfinding mesh model;
[0017] For each inflection point, when the inflection point is located at the boundary between the walkable region and the non-walkable region in the pathfinding grid model, the inflection point is moved along the edge of the grid it is located towards the walkable region to update the inflection point and obtain the corresponding updated inflection point.
[0018] The starting point, the updated inflection point, and the ending point are used as initial path points to obtain the initial path sequence.
[0019] Optionally, the step of performing curve fitting on the initial path sequence to obtain a fitted curve includes:
[0020] Using the initial path points in the initial path sequence as control points, a cubic Hermit curve is constructed to obtain the fitted curve.
[0021] Optionally, determining the sub-path sequence used to form the curve in the sampled path sequence, wherein the sub-path sequence is composed of turning path points that form the same curve, includes:
[0022] Calculate the angle between the tangents of two adjacent sampling path points in the sampling path sequence in turn;
[0023] Two sampling path points whose tangent angle is greater than a preset first angle threshold are identified as turning path points;
[0024] Multiple adjacent turning path points are defined as a sub-path sequence.
[0025] Optionally, when the turning radius of a turning point in the sub-path sequence is less than a preset first turning radius threshold, performing curve fitting again on the turning point in the sub-path sequence includes:
[0026] The sub-path sequence with a turning radius of a turning path point that is less than a preset first turning radius threshold is identified as the target sub-path sequence;
[0027] When the number of sampling path points between two adjacent target sub-path sequences is less than a preset interval threshold, the turning path points in the two adjacent target sub-path sequences and the sampling path points between them are merged to obtain a new target sub-path sequence.
[0028] Optionally, the target path sequence consists of multiple target path points, and the method further includes:
[0029] In the target path sequence, target path points with a turning radius smaller than a preset second turning radius threshold are identified, and these target path points with a turning radius smaller than the preset second turning radius threshold are identified as curvature path points to be improved; the preset second turning radius threshold is smaller than the first preset turning radius threshold.
[0030] Multiple adjacent curvature path points to be improved are identified as a curvature path sequence to be improved;
[0031] For each curvature path sequence to be improved, determine the minimum turning radius circle corresponding to the curvature path sequence to be improved;
[0032] Determine the point of curvature path to be improved in the curvature path sequence to be improved, and the mapping point on the circumference of the circle with the minimum turning radius, and update the corresponding point of curvature path to be improved using the mapping point.
[0033] Optionally, the method further includes:
[0034] When the arc length between two adjacent mapping points on the minimum turning radius circle is greater than a preset length threshold, at least one additional mapping point is added between the two adjacent mapping points.
[0035] Optionally, the target path sequence includes other target path points besides the curvature path point to be improved; the method further includes:
[0036] Following the order from near to far from the circle with the minimum turning radius, the transition fitting curves obtained by curve fitting the other target path points and the mapping points are calculated sequentially.
[0037] When the transition fitting curve meets the preset conditions, the mapping point is over-stitched with other target path points in the target path sequence to update the target path sequence.
[0038] Optionally, the method further includes:
[0039] Based on the starting point, orientation, and minimum turning radius of the virtual characters, determine the minimum turning circles of the two virtual characters;
[0040] Based on the starting method of the virtual character, determine the minimum target turning circle corresponding to the starting method; the starting methods include forward-left turn, forward-right turn, backward-left turn, and backward-right turn.
[0041] Based on the target minimum turning circle and the first target path point in the target path sequence that is outside the target minimum turning circle, determine the transition path sequence corresponding to each starting mode;
[0042] Determine the target transition path sequence from the transition path sequence;
[0043] The target path sequence is processed according to the target transition path sequence to obtain the processed target path sequence.
[0044] Optionally, determining the transition path sequence corresponding to each starting mode based on the target minimum turning circle and the first target path point in the target path sequence located outside the target minimum turning circle includes:
[0045] The minimum turning circle of the target is sampled to obtain the turning circle waypoint;
[0046] Determine whether the turning point is located within a walkable area of the game scene;
[0047] If so, then determine the first target path point in the target path sequence that is outside the target turning circle, and determine the target turning circle point in the target minimum turning circle. The target turning circle point is the turning circle point in the target minimum turning circle that is closest to the first target path point in the reverse direction of the path corresponding to the starting mode.
[0048] Calculate the angle between the turning tangents of the first target path point and the target turning circle point;
[0049] If the included angle of the steering tangent is less than the preset second included angle threshold, then the steering circle point between the target steering circle point and the starting point is obtained as the steering circle point to be fitted.
[0050] Curve fitting is performed on the turning circle point to be fitted and the first target path point to obtain the transition path curve;
[0051] The transition path curve is sampled to obtain a transition path sequence.
[0052] A path planning device for a virtual character, the device comprising:
[0053] An initial path generation module is used to obtain the start and end points of the virtual character in the game scene, and determine the initial path sequence connecting the start and end points based on the game scene;
[0054] The curve fitting generation module is used to perform curve fitting on the initial path sequence to obtain a fitted curve.
[0055] The sampling path generation module is used to sample the fitted curve to obtain a sampling path sequence, wherein the sampling path sequence includes multiple sampling path points;
[0056] A curve path generation module is used to determine multiple sub-path sequences in the sampled path sequence that form curves, each of the sub-path sequences consisting of turning path points that form the same curve;
[0057] The target path generation module is used to perform curve fitting on the turning points in the sub-path sequence again and then sample them when the turning radius of a turning point in the sub-path sequence is less than a preset first turning radius threshold, so as to obtain the target path sequence.
[0058] Optionally, the initial path generation module includes:
[0059] The pathfinding mesh model generation module is used to generate the pathfinding mesh model corresponding to the game scene;
[0060] The initial path generation module based on the network model is used to determine the initial path sequence from the starting point to the ending point according to the pathfinding grid model and a preset pathfinding algorithm.
[0061] Optionally, the initial path generation module based on the network model includes:
[0062] The inflection point determination module is used to determine the inflection points from the starting point to the ending point in the pathfinding grid model;
[0063] The inflection point optimization module is used to move the inflection point along the edge of the grid it is located on toward the walkable area when the inflection point is located at the boundary between the walkable area and the non-walkable area in the pathfinding grid model, so as to update the inflection point and obtain the corresponding updated inflection point.
[0064] The module for generating an initial path based on the optimized inflection point is used to take the starting point, the updated inflection point, and the ending point as initial path points to obtain an initial path sequence.
[0065] Optionally, the fitting curve generation module is used to construct a cubic Hermit curve using the initial path points in the initial path sequence as control points to obtain the fitting curve.
[0066] Optionally, the sampling path generation module includes:
[0067] The sampling path point angle calculation module is used to calculate the tangent angle between two adjacent sampling path points in the sampling path sequence in turn.
[0068] A turning path point generation module is used to determine two sampled path points whose tangent angle is greater than a preset first angle threshold as turning path points;
[0069] The curve path determination module is used to determine multiple adjacent turning path points into a sub-path sequence.
[0070] Optionally, the target path generation module includes:
[0071] The secondary fitting path determination module is used to determine the sub-path sequence with a turning radius of turning path points that is less than a preset first turning radius threshold as the target sub-path sequence;
[0072] The first target path update module is used to merge the turning path points in the two adjacent target sub-path sequences and the sampling path points of the interval when the number of sampling path points between two adjacent target sub-path sequences is less than a preset interval number threshold, so as to obtain a new target sub-path sequence.
[0073] Optionally, the target path sequence consists of multiple target path points, and the device includes:
[0074] The curvature path point determination module is used to determine the target path points in the target path sequence whose turning radius is less than a preset second turning radius threshold, and to determine the target path points whose turning radius is less than the preset second turning radius threshold as curvature path points to be improved; the preset second turning radius threshold is less than the first preset turning radius threshold;
[0075] The curvature path point determination module is used to determine multiple adjacent curvature path points to be improved as a curvature path sequence to be improved.
[0076] The minimum turning radius circle determination module is used to determine the minimum turning radius circle corresponding to each curvature path sequence to be improved.
[0077] The curvature path point update module is used to determine the curvature path points to be improved in the curvature path sequence to be improved, the mapping points on the circumference of the circle with the minimum turning radius, and update the corresponding curvature path points to be improved using the mapping points.
[0078] Optionally, the device includes:
[0079] The mapping point interpolation module is used to add at least one mapping point between two adjacent mapping points when the arc length between two adjacent mapping points on the minimum turning radius circle is greater than a preset length threshold.
[0080] Optionally, the target path sequence includes other target path points besides the curvature path point to be improved; the device further includes:
[0081] The transition fitting curve determination module is used to calculate the transition fitting curves obtained by fitting the other target path points with the mapping points in order from near to far from the minimum turning radius circle.
[0082] The second target path update module is used to over-join the mapping point with other target path points in the target path sequence when the transition fitting curve meets the preset conditions, so as to update the target path sequence.
[0083] Optionally, the device further includes:
[0084] The minimum turning circle determination module is used to determine the minimum turning circle of two virtual characters based on the starting point, orientation, and minimum turning radius of the virtual characters.
[0085] The target minimum turning circle determination module is used to determine the target minimum turning circle corresponding to the starting method of the virtual character; the starting method includes forward-left turn, forward-right turn, backward-left turn, and backward-right turn;
[0086] The transition path sequence determination module is used to determine the transition path sequence corresponding to each starting mode based on the target minimum turning circle and the first target path point in the target path sequence that is located outside the target minimum turning circle;
[0087] A target filtering path sequence determination module is used to determine a target transition path sequence from the transition path sequence;
[0088] The third update module for the target path sequence is used to process the target path sequence according to the target transition path sequence to obtain the processed target path sequence.
[0089] Optionally, the transition path sequence determination module includes:
[0090] The turning circle path point determination module is used to sample the target minimum turning circle to obtain the turning circle path point;
[0091] The turning circle point determination module is used to determine whether the turning circle point is located in the walkable area of the game scene;
[0092] The target turning circle point determination module is used to determine, if yes, the first target path point located outside the target turning circle in the target path sequence, and to determine the target turning circle point in the target minimum turning circle, wherein the target turning circle point is the turning circle point in the target minimum turning circle that is closest to the first target path point in the reverse direction of the path corresponding to the starting mode.
[0093] The steering tangent angle calculation module is used to calculate the steering tangent angle between the first target path point and the target steering circle point;
[0094] The module for determining the turning circle point to be fitted is used to obtain the turning circle point between the target turning circle point and the starting point as the turning circle point to be fitted if the included angle of the turning tangent is less than a preset second included angle threshold.
[0095] The module for determining the transition path curve based on the turning circle point is used to perform curve fitting on the turning circle point to be fitted and the first target path point to obtain the transition path curve.
[0096] The transition path sequence determination module is used to sample the transition path curve to obtain the transition path sequence.
[0097] An electronic device includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the path planning method for a virtual character as described above.
[0098] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the path planning method for a virtual character as described above.
[0099] This application has the following advantages:
[0100] In the embodiments of this application, the starting point and ending point of the virtual character in the game scene are obtained, and an initial path sequence connecting the starting point and the ending point is determined based on the game scene; the initial path sequence is curve-fitted to obtain a fitted curve; the fitted curve is sampled to obtain a sampled path sequence, the sampled path sequence including multiple sampled path points; a sub-path sequence for forming curves is determined in the sampled path sequence, the sub-path sequence being composed of turning path points forming the same curve; when the turning radius of a turning path point in the sub-path sequence is less than a preset first turning radius threshold, the turning path point in the sub-path sequence is curve-fitted again to update the path corresponding to the sub-path sequence in the fitted curve, and the updated fitted curve is sampled to obtain a target path sequence; the target path sequence generated in the embodiments of this application has smooth and uniform path points, which facilitates the control of virtual character movement and enables smooth movement of the virtual character, conforming to movement rules. Attached Figure Description
[0101] To more clearly illustrate the technical solution of this application, the drawings used in the description of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0102] Figure 1 This is a flowchart illustrating the steps of a path planning method for a virtual character according to an embodiment of this application.
[0103] Figure 2 This is a schematic diagram illustrating the inflection point optimization in the embodiments of this application;
[0104] Figure 3 This is a schematic diagram of cubic Emil türth curve fitting and sampling in an embodiment of this application;
[0105] Figure 4 This is a schematic diagram illustrating the curvature improvement in an embodiment of this application;
[0106] Figure 5 This is a schematic diagram of the start-up transition in an embodiment of this application;
[0107] Figure 6 This is a structural block diagram of a virtual character path planning device according to an embodiment of this application. Detailed Implementation
[0108] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only some, not all, of the embodiments of this 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.
[0109] In gaming applications, AI-controlled virtual characters are typically added. The realism of these AI-controlled virtual characters largely determines the game's playability. Movement is the most basic action command for AI-controlled virtual characters, and the level of their movement skills directly affects their realism. The quality of these movement skills is directly reflected in the intelligence of the path planning method.
[0110] AI-controlled virtual characters are subject to specific kinematic constraints during movement, including minimum turning radius and turning speed constraints. For wheeled vehicles such as cars, the direction of travel is generally determined by the steering wheels. The minimum turning radius refers to the radius of the circle traced by the center of the outer steering wheel on the supporting plane when the steering wheels are turned to their extreme positions and the vehicle is turning at its lowest stable speed. If the curvature of the path is too large and the turning radius is smaller than the vehicle's minimum turning radius, the vehicle cannot follow the path. Furthermore, the virtual character's turning is also limited by the turning speed and cannot be completed instantaneously. When there is a sudden change in orientation at a waypoint, tracked vehicles that can turn on the spot need to stop and turn, while wheeled vehicles may be unable to proceed.
[0111] In related technologies, the game scene is generally converted into a data object, and then a search algorithm is run on the data object to perform path planning. However, the resulting path points may be uneven, have excessive curvature, or have a direction that is inconsistent with the initial orientation of the AI-controlled virtual character. This can cause the AI-controlled virtual character to be unable to move according to kinematic laws, resulting in low motion simulation.
[0112] In view of this, embodiments of this application provide a path planning method for virtual characters to overcome the deficiencies of the prior art.
[0113] Reference Figure 1 The diagram illustrates a flowchart of a path planning method for a virtual character according to an embodiment of this application. In this embodiment, the method includes the following steps:
[0114] Step 101: Obtain the starting point and ending point of the virtual character in the game scene, and determine the initial path sequence connecting the starting point and the ending point based on the game scene;
[0115] Step 102: Perform curve fitting on the initial path sequence to obtain the fitted curve;
[0116] Step 103: Sample the fitted curve to obtain a sampling path sequence, the sampling path sequence including multiple sampling path points;
[0117] Step 104: Determine the sub-path sequence used to form the curve in the sampling path sequence, wherein the sub-path sequence is composed of turning path points that form the same curve;
[0118] Step 105: When the turning radius of the turning path point in the sub-path sequence is less than the preset first turning radius threshold, the turning path point in the sub-path sequence is subjected to curve fitting again to update the path corresponding to the sub-path sequence in the fitted curve, and the updated fitted curve is sampled to obtain the target path sequence.
[0119] This application embodiment obtains the start and end points of a virtual character in a game scene, and determines an initial path sequence connecting the start and end points based on the game scene; performs curve fitting on the initial path sequence to obtain a fitted curve; samples the fitted curve to obtain a sampled path sequence, the sampled path sequence including multiple sampled path points; determines a sub-path sequence in the sampled path sequence used to form curves, the sub-path sequence consisting of turning path points forming the same curve; when the turning radius of a turning path point in the sub-path sequence is less than a preset first turning radius threshold, performs curve fitting again on the turning path points in the sub-path sequence to update the path corresponding to the sub-path sequence in the fitted curve, and samples the updated fitted curve to obtain a target path sequence; the target path sequence generated by this application embodiment has smooth and uniform path points, which facilitates the control of virtual character movement and enables smooth virtual character movement that conforms to movement rules.
[0120] The path planning method for virtual characters in this exemplary embodiment will be further explained below.
[0121] The virtual character in this application embodiment can be an AI-controlled virtual character. For example, the virtual character is an AI-controlled virtual vehicle. A virtual vehicle is a machine or equipment used to transport goods, personnel, etc., and may include vehicles, ships, etc.
[0122] In step 101, the starting point and ending point of the virtual character in the game scene are obtained, and an initial path sequence connecting the starting point and the ending point is determined based on the game scene.
[0123] In game applications, the starting point and ending point of a virtual character can be determined. The starting point is generally the coordinate point of the virtual character's current position in the game scene, and the ending point is the target position that the virtual character needs to move to. This can be updated according to the game progress.
[0124] The game scene can include movable and immovable areas for virtual characters. For example, in a water scene, the virtual character is a boat, the movable area can be the water surface, and the immovable area can include areas corresponding to reefs, areas corresponding to isolated islands, etc.
[0125] Based on the movable areas in the game scene and the starting and ending points of the virtual character, an initial path sequence can be determined from the starting point to the ending point, traversing only the movable areas. This initial path sequence is generally the shortest path sequence among all paths the virtual character takes from the starting point to the ending point through the movable areas. The initial path sequence consists of multiple initial path points, including the starting point and the ending point. Each initial path point has corresponding coordinates, which represent its specific location in the game scene.
[0126] In an optional embodiment of this application, the process of determining the initial path sequence connecting the starting point and the ending point based on the game scene may include:
[0127] Generate the pathfinding mesh model corresponding to the game scene;
[0128] Based on the pathfinding grid model, a preset pathfinding algorithm is used to determine the initial path sequence from the starting point to the ending point.
[0129] In this embodiment, the game scene can be divided into a mesh to obtain a pathfinding mesh model, which allows data objects of the same scene area to use fewer vertices, occupy less memory in the game, and improve the efficiency of the pathfinding algorithm.
[0130] The pathfinding mesh model is a form of graph. The basic definition of a graph is: the expression of a graph is G = (V, E), where V represents the set of vertices, and E and V are a binary relation, which can be understood as "edges". For example, if there is an edge that runs from vertex S to vertex T, then E can be represented by (S, T) for this edge.
[0131] For example, the Recast tool of the Recast&Detour pathfinding engine can be used to process the scene mesh data of the game scene to obtain the pathfinding mesh model mentioned above.
[0132] After obtaining the pathfinding grid model, a preset pathfinding algorithm can be used to determine the initial path sequence from the starting point to the ending point. This preset pathfinding algorithm can include A* pathfinding algorithm, B* pathfinding algorithm, greedy pathfinding algorithm, depth-first search algorithm, breadth-first search algorithm, etc.
[0133] The A* pathfinding algorithm is a direct search method for finding the shortest path in a static road network. The closer the distance estimate in the A* algorithm is to the actual distance, the faster the search speed. The A* pathfinding algorithm corresponds to a cost estimation function:
[0134] F(n) = G(n) + H(n)
[0135] F(n) is the estimated minimum-cost path from the starting point to the destination via node n. G(n) is the actual cost of the path already traversed from the starting point to node n. H(n) is the estimated cost of the possible optimal path from node n to the destination, and H(n) indicates the heuristic information used by the algorithm. Based on F(n), the cost of the current node can be calculated, and the next reachable node can be evaluated. The algorithm finds the shortest path step by step by finding the point with the minimum cost in each search and then continuing the search outwards.
[0136] In an optional embodiment of this application, the Detour tool of the Recast & Detour pathfinding engine can be used to determine the initial path sequence from the starting point to the destination.
[0137] The Detour tool employs the A* pathfinding algorithm and the funnel algorithm to determine the initial path sequence from the starting point to the destination. Specifically, the funnel algorithm identifies inflection points in the path from the starting point to the destination, while the A* pathfinding algorithm determines the shortest path.
[0138] Furthermore, to ensure that the virtual character can move normally after the initial path sequence is processed subsequently, in an optional embodiment of this application, the above-mentioned determination of the initial path sequence from the starting point to the ending point using a preset pathfinding algorithm based on the pathfinding grid model includes:
[0139] Determine the inflection points from the starting point to the ending point in the pathfinding mesh model;
[0140] For each inflection point, when the inflection point is located at the boundary between the walkable and non-walkable regions in the pathfinding grid model, the inflection point is moved along the edge of the grid it is located towards the walkable region to update the inflection point and obtain the corresponding updated inflection point. It should be noted that when the inflection point is not located at the boundary between the walkable and non-walkable regions in the pathfinding grid model, the updated inflection point is the original inflection point.
[0141] The starting point, the updated inflection point, and the ending point are used as initial path points to obtain the initial path sequence.
[0142] In this embodiment, after the funnel algorithm is used to determine the inflection points from the starting point to the ending point in the pathfinding grid model, it is sequentially determined whether each inflection point is located at the boundary of the pathfinding grid model. This boundary is the intersection of the walkable and non-walkable areas in the pathfinding grid model. If so, the inflection points located at the boundary are optimized. The path sequence consisting of the starting point, the optimized inflection points, and the ending point is the initial path sequence.
[0143] Specifically, the inflection points obtained using the funnel algorithm must be located on the edges of a grid, where a grid refers to a single grid that makes up the pathfinding grid model. The inflection point optimization process involves moving the inflection point along the edge of its grid towards the walkable region to update the original inflection point.
[0144] More specifically, the process of moving the inflection point along the edge of its grid toward the walkable region includes:
[0145] When the length of the edge of the grid containing the inflection point is greater than or equal to a preset length, the inflection point moves a first distance along the edge of the grid towards the walkable area, replacing the original inflection point with the moved one to update the original inflection point. The preset length and the first distance can be set according to actual needs. For example, the preset length can be the maximum width of the virtual character, and the first distance can be half the maximum width of the virtual character. For instance, when the virtual character is a car, the preset length can be equal to the maximum width of the car, and the first distance can be equal to half the maximum width of the car.
[0146] When the length of the edge of the grid containing the inflection point is less than a preset length, the grid moves a second distance along its edge into the walkable area, replacing the original inflection point with the moved one to update the original inflection point. The second distance can be related to the total length of the edges of the grid containing the inflection point. For example, the second distance can be half the length of the edge of the grid containing the inflection point, or one-third the length of the edge of the grid containing the inflection point, etc.
[0147] Figure 2 This is a schematic diagram of inflection point optimization in the embodiments of this application, such as... Figure 2 As shown, circles represent the original inflection points, and squares represent the inflection points after movement. By optimizing inflection points, we can prevent the virtual character from colliding with obstacles (such as rocks) in the game scene when moving along the target path obtained in subsequent processing.
[0148] In step 102, the initial path sequence is subjected to curve fitting to obtain a fitted curve.
[0149] In this embodiment, various curve fitting algorithms can be used to fit the initial path sequence to obtain a fitted curve. For example, the Bezier curve fitting method or the B-spline curve fitting method can be used to fit the initial path sequence, etc.
[0150] In an optional embodiment of this application, the process of performing curve fitting on the initial path sequence to obtain a fitted curve may include:
[0151] Using the initial path points in the initial path sequence as control points, a cubic Hermit curve is constructed to obtain the fitted curve.
[0152] In this context, the initial path points are the path points that constitute the initial path sequence. A Hermitian curve is a curve defined by knowing the coordinates of its two endpoints and the tangent line at each endpoint. This embodiment uses the initial path points as control points and employs a cubic Hermitian curve to fit the initial path sequence, ensuring that the resulting fitted curve passes through all the initial path points in the initial path sequence. It can be understood that in the curve fitting process of this embodiment, starting from the starting point, adjacent initial path points are sequentially used as the two endpoints of the cubic Hermitian curve fitting, resulting in multiple connected curves, which constitute the fitted curve.
[0153] For example, the formula for a cubic Hermit curve is as follows:
[0154] P(t)=(2t 3 -3t 2 +1)P0+(t 3 -2t 2 +t)R0+(t 3 -t 2 )R1+(-2t 3 +3t 2 P1
[0155] Here, t takes values between 0 and 1, and the coordinates of any point on the curve are functions of t. When performing cubic Hermitian curve fitting, the value of t can be determined according to the number of initial path points in the initial path sequence. P0 and P1 represent the coordinates of the two known endpoints, and R0 and R1 represent the tangents of the two known endpoints.
[0156] During the calculation, the Hermitian matrix can be set as:
[0157]
[0158] Let the geometric vector of the Hermitian curve be:
[0159] G h=[P0 P1 R0 R1] T
[0160] Where T is a vector about t, it can be represented as:
[0161] T = [t] 3 ,t 2 ,t,1]
[0162] The points on the Hermitian curve can be obtained as follows:
[0163] Q(t) = T*M h *G h ,t∈[0,1]
[0164] In step 103, the fitted curve is sampled to obtain a sampling path sequence, which includes multiple sampling path points.
[0165] In this embodiment, after obtaining the fitted curve, the fitted curve can be sampled to obtain multiple sampling path points, which together form a sampling path sequence. Each sampling path point carries its corresponding sampling path point coordinates and corresponding tangent direction.
[0166] The number of sampling path points for sampling the fitted curve can be preset according to requirements. For example, the relationship between the length of the fitted curve and the number of sampling path points can be preset. After obtaining the fitted curve, the number of sampling path points can be determined based on the relationship between the length of the fitted curve and the number of sampling path points, and the fitted curve can be sampled at equal length or randomly based on the determined number of sampling path points. Alternatively, the number of sampling path points can be preset, and after obtaining the fitted curve, the fitted curve can be sampled at equal length or randomly based on the preset number of sampling path points.
[0167] For example, in the process of sampling the fitted curve to the same length, the curve length S can be calculated first using the Gauss-Legendre quadrature formula. The number of equal divisions of the fitted curve is then determined according to actual needs. For example, if the curve needs to be divided into n equal parts, then the length of each part is S / n, meaning n t values need to be calculated such that any two t values are equal. i and t i+1 The curve length between the curves is S / n. The value of t can be determined using Newton's tangent method. The number of equal parts the curve is divided into can be determined based on the curve length and the sampling length; for example, the number of equal parts = curve length / sampling length. The sampling length is generally related to the size of the virtual character. For example, when the virtual character is a ship with a length of 5 meters and the curve length is 20 meters, the sampling length can be either 5 meters or 10 meters.
[0168] In the solution process, we can assume that the length is a function of t as S = Y(t), and differentiate both sides with respect to t, that is... Introducing the differential ds of length, the equation is rewritten as follows: so This is the derivative of the length with respect to t, which has already been listed above. Integrating this expression with t, we get:
[0169]
[0170] At this point, given s, we need to find t to make the equation hold. For the right-hand side, we use Newton's tangent method to approximate the solution. We define a function F(t) = g(t) - s. By iterating the following equation until a certain precision is reached, we can obtain an approximate solution:
[0171]
[0172] After obtaining n t values, we can perform equal-length sampling on the Hermit curve.
[0173] Figure 3 This is a schematic diagram of cubic Emil datum curve fitting and sampling in an embodiment of this application, where the circles are control points and the squares are sampling path points of equal length sampling. Figure 3 As shown, the fitted curve obtained by cubic Ellert curve fitting is smoother than the path formed by connecting the initial path points. By sampling path points of equal length, it is easier to control the movement of the virtual character.
[0174] In step 104, a sub-path sequence for forming curves is determined in the sampling path sequence, the sub-path sequence being composed of turning path points that form the same curve.
[0175] To prevent excessive curvature of curves in the path obtained through path planning, which could prevent the virtual character from moving normally along the planned path, in this embodiment, after obtaining the sampled path sequence, it is also necessary to identify the sub-path sequences used to form curves in the sampled path sequence.
[0176] Optionally, the process of determining the sub-path sequence used to form the curve in the sampling path sequence described above may include:
[0177] Calculate the angle between the tangents of two adjacent sampling path points in the sampling path sequence in turn;
[0178] Two sampling path points whose tangent angle is greater than a preset first angle threshold are identified as turning path points;
[0179] Multiple adjacent turning path points are defined as a sub-path sequence.
[0180] Since the sampling path points are points on the fitted curve, the tangent vector of each sampling path point can be determined based on the fitted curve, and then the angle between the tangent vectors of two adjacent sampling path points can be determined, i.e., the tangent angle. Specifically, starting from the starting sampling path point in the sampling path sequence, each sampling path point can be traversed. If there is a subsequent sampling path point for the currently traversed sampling path point, the tangent angle between the currently traversed sampling path point and its adjacent subsequent sampling path point can be calculated.
[0181] When the included angle of the tangents is not equal to 0, it means that the two adjacent sampling path points are located in a curve.
[0182] Generally, only when the curvature of a curve is large will it affect the normal movement of the virtual character. Therefore, in this embodiment, sampling path points with tangent angles greater than a preset angle threshold are determined as turning path points. For example, the preset first angle threshold can be 20 degrees. In this way, multiple turning path points can be determined. Based on whether the multiple turning path points are adjacent, at least one sub-path sequence can be obtained. The turning path points in each sub-path sequence are continuous, that is, each sub-path sequence consists of multiple turning path points that make up the same curve.
[0183] In step 105, when the turning radius of the turning path point in the sub-path sequence is less than the preset first turning radius threshold, the turning path point in the sub-path sequence is subjected to curve fitting again to update the path corresponding to the sub-path sequence in the fitted curve, and the updated fitted curve is sampled to obtain the target path sequence.
[0184] After obtaining the sub-path sequence, the turning radius corresponding to each turning point in each sub-path sequence can be further calculated. During the calculation of the turning path for each turning point, if there are two adjacent turning points, the radius of the circle formed by the current turning point and the previous turning point, and the radius of the circle formed by the current turning point and the next turning point, are calculated respectively. The smaller radius is taken as the turning radius of the current turning point. The previous and next turning points are defined based on the path direction, which refers to the direction from the virtual character's starting point along the fitted curve to the virtual character's ending point.
[0185] For example, for each sub-path sequence, starting from the first turning point of the sub-path sequence, a circle can be determined based on the position of the first turning point, the position of the adjacent second turning point, and the tangent of the first turning point. The radius of this circle is then determined as the radius of the first turning point. For the second turning point, a circle can be determined based on the positions of the first and second turning points, and the tangent of the second turning point. The radius of this circle is then obtained and denoted as the first optional radius. If a third turning point exists adjacent to the second turning point, a circle can be determined based on the positions of the second and third turning points, and the tangent of the second turning point. The radius of this circle is then obtained and denoted as the second optional radius. By comparing the sizes of the first and second optional radii, the radius with the smaller value is determined as the turning radius of the second turning point. If no third turning point exists adjacent to the second turning point, the first optional radius is determined as the turning radius of the second turning point.
[0186] After calculating the turning radius of each turning point in each sub-path sequence, the relationship between the turning radius of each turning point and a preset first turning radius threshold can be determined. The preset first turning radius threshold is at least greater than the minimum turning radius of the virtual character; optionally, it can be twice the minimum turning radius of the virtual character. When at least one turning point in a sub-path sequence has a turning radius less than the preset first turning radius threshold, curve fitting is performed again on the turning paths in that sub-path sequence. To facilitate differentiation, the sub-path sequence with turning points having turning radii less than the preset first turning radius threshold is identified as the target sub-path sequence. Curve fitting is then performed again on the target sub-path sequence, and the new fitted curve obtained at this point replaces the corresponding sub-path sequence curve. The process of performing curve fitting again can be referred to the description in step 102 above, and will not be repeated here.
[0187] Similarly, all sub-path sequences that need to be curve-fitted again can be identified, and curve fitting is performed on these sub-path sequences to obtain new fitted curves. These new fitted curves replace the corresponding sub-path sequence curves, and are then merged with the original path sequences in the sampled path sequences that were not replaced to obtain new sampled path sequences. These new sampled path sequences are then sampled to obtain the target path sequence. The sampling process can be referred to in step 103 above, and will not be repeated here. It should be noted that when equal-length sampling is used twice, the sampling lengths of the two equal-length samplings can be the same or different.
[0188] Optionally, after obtaining the target path sequence, you can return to step 103 above and continue execution until the turning radius of the non-existent path points in the target path sequence is less than the preset first turning radius threshold.
[0189] Furthermore, to improve the smoothness of the second fitted curve obtained after the second curve fitting, in an optional embodiment of this application, when the turning radius of a turning point in the sub-path sequence is less than a preset first turning radius threshold, the turning point in the sub-path sequence is subjected to curve fitting again, including:
[0190] The sub-path sequence with a turning radius of a turning path point that is less than a preset first turning radius threshold is identified as the target sub-path sequence;
[0191] When the number of sampling path points between two adjacent target sub-path sequences is less than a preset interval threshold, the turning path points in the two adjacent target sub-path sequences and the interval sampling path points are merged to obtain a new target sub-path sequence. The preset interval threshold can be selected according to the actual request; optionally, the preset interval threshold can be 3.
[0192] In this embodiment, the target sub-path sequences that are close together and require curve fitting again are merged together with the sampled path points that are spaced apart to obtain a longer target sub-path sequence that requires curve fitting again, and then curve fitting is performed on the target sub-path sequence.
[0193] This application embodiment obtains the start and end points of a virtual character in a game scene, and determines an initial path sequence connecting the start and end points based on the game scene; performs curve fitting on the initial path sequence to obtain a fitted curve; performs equal-length sampling on the fitted curve to obtain a sampled path sequence, the sampled path sequence including multiple sampled path points; determines a sub-path sequence in the sampled path sequence used to form curves, the sub-path sequence consisting of turning path points forming the same curve; when the turning radius of a turning path point in the sub-path sequence is less than a preset first turning radius threshold, performs curve fitting again on the turning path points in the sub-path sequence, and then performs equal-length sampling again to obtain a target path sequence; the target path sequence generated by this application embodiment has smooth and uniform path points, which facilitates the control of virtual character movement and can achieve smooth virtual character movement that conforms to movement rules.
[0194] Furthermore, in an optional embodiment of this application, the target path sequence consists of multiple target path points. After obtaining the target path sequence, the path planning method for the virtual character may further include:
[0195] In the target path sequence, target path points with a turning radius smaller than a preset second turning radius threshold are identified, and these target path points with a turning radius smaller than the preset second turning radius threshold are identified as curvature path points to be improved; the preset second turning radius threshold is smaller than the first preset turning radius threshold.
[0196] Multiple adjacent curvature path points to be improved are identified as a curvature path sequence to be improved;
[0197] For each curvature path sequence to be improved, determine the minimum turning radius circle corresponding to the curvature path sequence to be improved;
[0198] Determine the point of curvature path to be improved in the curvature path sequence to be improved, and the mapping point on the circumference of the circle with the minimum turning radius, and update the corresponding point of curvature path to be improved using the mapping point.
[0199] Through steps 101 to 105 above, a smooth path from the starting point to the ending point can be obtained, namely the target path. The target path consists of multiple target path points with equal intervals. If a target path point is in a turning sub-sequence (a sequence of target path points whose turning radius is less than a preset second turning radius threshold), then the target path point and its adjacent target path points form the turning radius of the curve.
[0200] By traversing the target path sequence, the turning radius of each target path point is compared with a preset second turning radius threshold. This second turning radius threshold can be the minimum turning radius of the virtual character. If the turning radius of the target path point is smaller than the minimum turning radius of the virtual character, it is likely that the movement requirements of the virtual character cannot be met because the virtual character has specific kinematic constraints; these kinematic constraints can specifically include minimum turning radius constraints and turning speed constraints. This indicates that the target path point needs curvature improvement, and the target path point requiring curvature improvement is identified as the curvature path point to be improved. Similarly, all target path points requiring curvature improvement can be obtained, i.e., all curvature path points to be improved can be obtained.
[0201] A sequence of adjacent curvature path points to be improved is defined as a curvature path sequence to be improved, which can yield one or more curvature path sequences to be improved. Of course, if there are no curvature path points to be improved, then correspondingly, there is no curvature path sequence to be improved.
[0202] For each curvature path sequence to be improved, starting from the first curvature path point in the sequence, two adjacent curvature path points are grouped together. Based on the position and tangent direction of the two adjacent curvature path points, two circle centers can be determined, thereby determining multiple circle centers of the curvature path sequence to be improved. Then, the coordinate center of the multiple circle centers is calculated, that is, the average of the x-coordinates of the multiple circle centers is used as the x-coordinate of the circle center of the curvature path sequence to be improved, and the average of the y-coordinates of the multiple circle centers is used as the y-coordinate of the circle center of the curvature path sequence to be improved.
[0203] After determining the center position of the curvature path sequence to be improved, a circle corresponding to the minimum turning radius of the virtual character's minimum turning radius is generated. All curvature path points in the curvature path sequence that are located within the circle of the minimum turning radius are mapped onto the circumference of the circle of the minimum turning radius. Specifically, the center of the circle of the minimum turning radius and the curvature path points to be improved located within the circle of the minimum turning radius can be connected, and the connecting line can be extended to intersect with the circumference of the circle of the minimum turning radius. The intersection point is the mapping point corresponding to the curvature path point to be improved, replacing the original curvature path point to be improved.
[0204] Optionally, after obtaining the mapping points of each path point to be improved on the circle of minimum turning radius, the arc length between two adjacent mapping points is calculated. If the arc length exceeds a preset length threshold, interpolation is performed. The preset length threshold can be the length between two adjacent target path points in the target path. The interpolation process can involve adding at least one mapping point between two adjacent mapping points.
[0205] For example, after obtaining the arc length, the ratio of the arc length to a preset length threshold can be calculated. The ratio is then rounded down to determine the number of mapping points that need to be added. These mapping points are then added to the arc length so that the central angles of two adjacent mapping points in the arc length are equal. Through interpolation, it is possible to avoid adjacent path points being too far apart.
[0206] Further, in an optional embodiment of this application, after obtaining the mapping points on the minimum turning radius circle (including mapping points corresponding to each path point to be improved, and / or mapping points for which the arc length exceeds the path sampling length by interpolation), in order to make the mapping points on the minimum turning radius circle more smoothly connected to the target path, the target path sequence includes other target path points besides the curvature path points to be improved; the method may further include:
[0207] Following the order from near to far from the circle with the minimum turning radius, the transition fitting curves obtained by curve fitting the other target path points and the mapping points are calculated sequentially.
[0208] When the transition curve meets the preset conditions, the mapping point is over-stitched with other target path points in the target path sequence to update the target path sequence.
[0209] In this embodiment, for each mapping point of the minimum turning radius circle, the original target path contains at least a preceding path point subsequence (i.e., a path point subsequence from the starting point to the direction of the curvature path sequence to be improved) before the curvature path sequence to be improved corresponding to the minimum turning radius circle, or a following path subsequence (i.e., a path point subsequence from the curvature path sequence to the end point) after the curvature path sequence to be improved corresponding to the minimum turning radius circle. During the process of concatenating the mapping point of the minimum turning radius circle with its corresponding preceding and / or following path subsequences, curve fitting is performed sequentially on other target path points and the mapping point in order from near to far to obtain a transition fitting curve. When the transition fitting curve meets preset conditions, it is used to concatenate the mapping point with other target path points corresponding to the transition fitting curve, thereby achieving the concatenation of the mapping point with its preceding and / or following path subsequences.
[0210] For example, for the preceding path subsequence of the mapping point, starting from the other target path point in the preceding path subsequence that is closest to the mapping point, for ease of description, the other target path point that is closest to the minimum turning radius circle at this time is determined as the first other target path point. The first other target path point is then fitted with all the mapping points on the minimum turning radius circle to obtain the first transition fitting curve. Then, the first transition fitting curve is sampled to determine whether the sampled first transition fitting curve meets the turning constraints of the virtual character, that is, whether the turning radius of each path point on the sampled first transition fitting curve is greater than the minimum turning radius of the virtual character. If so, it means that the first transition fitting curve meets the preset requirements. The first transition fitting curve and the mapping point sequence and the preceding path subsequence connected to it together form a new target path.
[0211] If the first transition fitting curve obtained from the first other target path point does not meet the preset requirements, then a second other target path point adjacent to the first other target path point in the preceding path subsequence is obtained. The distance between the second other target path point and the starting mapping point in the minimum turning radius circle is greater than the distance between the first other target path point and the starting mapping point. The second other target path point is curve-fitted with all mapping points on the minimum turning radius circle to obtain the second transition fitting curve. Then, the second transition fitting curve is sampled to determine whether the sampled second transition fitting curve meets the turning constraints of the virtual character. If it does, it means that the second transition fitting curve meets the preset requirements. The second transition curve and the sequence of mapping points connected to it, as well as the preceding path subsequence (at this time, the preceding path subsequence does not contain the first other target path point), together form a new target path.
[0212] Similarly, the subsequent path subsequences can be processed to obtain the transition fitting curves of the subsequent path subsequences and the mapping point sequences.
[0213] Figure 4 This is a schematic diagram illustrating the curvature improvement in an embodiment of this application; as shown Figure 4 As shown, square points represent paths with excessive curvature, i.e., points on paths with curvature to be improved; hollow circles are mapping points; solid circles are other target path points in the original target path besides square points; and star points are transition path points where mapping points on the minimum turning radius circle are joined with the original target path.
[0214] Furthermore, in an optional embodiment of this application, in order to solve the virtual character starting problem, the above-mentioned virtual character path planning method further includes:
[0215] Based on the starting point, orientation, and minimum turning radius of the virtual characters, determine the minimum turning circles of the two virtual characters;
[0216] Based on the starting method of the virtual character, determine the minimum target turning circle corresponding to the starting method; the starting methods include forward-left turn, forward-right turn, backward-left turn, and backward-right turn.
[0217] Based on the target minimum turning circle and the first target path point in the target path sequence that is outside the target minimum turning circle, determine the transition path sequence corresponding to each starting mode;
[0218] Determine the target transition path sequence from the transition path sequence;
[0219] The target path sequence is processed according to the target transition path sequence to obtain the processed target path sequence.
[0220] In this embodiment, during the initial adjustment process, the starting point of the virtual character (i.e., the position of the virtual character) is taken as a point on the minimum turning circle, the orientation of the virtual character is taken as the tangent of the minimum turning circle, and the minimum turning radius of the virtual character is taken as the radius of the minimum turning circle. Two tangent circles can be generated, which are the minimum turning circles of the virtual character. This ensures that the virtual character can move along the arc, thereby achieving the purpose of adjusting the direction.
[0221] The virtual character can have four starting methods: forward-left turn, forward-right turn, backward-left turn, and backward-right turn. The minimum target turning circle may differ for each starting method. For example, the minimum target turning circles for forward-left turn and forward-right turn are different, while the minimum target turning circles for forward-left turn and backward-left turn are the same. After determining the virtual character's starting method, the minimum target turning circle corresponding to that starting method can be determined.
[0222] Based on the target turning circle and the first target path point located outside the target minimum turning circle in the target path, determine the transition path sequence corresponding to each starting mode.
[0223] After obtaining the transition path sequences corresponding to each starting method, the feasible and shortest transition path sequence is selected as the target transition path sequence. Among them, the feasible transition path sequence refers to the transition path sequence in which the curvature satisfies the motion constraint (i.e., the curvature is greater than or equal to the minimum turning curvature of the virtual character) and all waypoints of the transition path sequence are in the walkable area.
[0224] Finally, the target path sequence is processed using the target transition path sequence to obtain the processed target path sequence. This processed target path sequence solves the virtual character start transition problem and ensures that the virtual character can start smoothly.
[0225] The process of determining the transition path sequence corresponding to each starting mode based on the target minimum turning circle and the first target path point in the target path sequence that is outside the target minimum turning circle may specifically include the following steps:
[0226] The minimum turning circle of the target is sampled to obtain the turning circle waypoint;
[0227] Determine whether the turning point is located within a walkable area of the game scene;
[0228] If not, the transition path corresponding to the aforementioned starting method cannot be obtained;
[0229] If so, then determine the first target path point in the target path sequence that is outside the target turning circle, and determine the target turning circle point in the target minimum turning circle that is closest to the first target path point in the opposite direction of the path corresponding to the starting mode;
[0230] Calculate the angle between the turning tangents of the first target path point and the target turning circle point;
[0231] If the included angle of the steering tangent is less than the preset second included angle threshold, then the steering circle point between the target steering circle point and the starting point is obtained as the steering circle point to be fitted.
[0232] Curve fitting is performed on the turning circle point to be fitted and the first target path point to obtain the transition path curve;
[0233] The transition path curve is sampled to obtain a transition path sequence.
[0234] For example, please refer to Figure 5 , Figure 5 This illustration shows a starting transition diagram of an embodiment of this application; taking a forward-right turn as an example, since it is a right turn, the target minimum turning circle is the lower turning circle; the target turning circle is sampled to obtain the turning circle path point (e.g., Figure 5 Hollow dots in the target path (e.g., hollow dots); preferably, the target turning circle can be sampled at equal lengths to obtain the turning circle waypoint. First, find the hollow dots in the target path (e.g., hollow dots in the target path); Figure 5 The curve formed by the sequence of solid circles in the target path sequence (which can be a target path sequence obtained through curve fitting, or a target path sequence after curve fitting and curvature improvement) is used to calculate the first path point outside the target turning circle, denoted as A. Then, the turning circle path points on the target minimum turning circle are traversed, and the following steps are used to calculate:
[0235] Determine whether the turning point on the target minimum turning circle is within the walkable area of the game scene. If not, it means that the forward-right turn starting method cannot obtain a legal transition path sequence due to obstacles or other reasons. Optionally, in conjunction with the starting method, determine whether the turning point on the target minimum turning circle, starting from the starting point and following the path direction corresponding to the starting method, to the intersection of the target minimum turning circle radius and the route corresponding to the target path sequence, is within the walkable area of the game scene.
[0236] If it is, then calculate the angle between the tangent of the turning circle point on the target minimum turning circle and the tangent of point A. When its value is less than a threshold (e.g., less than 45 degrees), it indicates that there is feasibility for curve fitting. Specifically, the angle between the tangent of the turning circle point on the target minimum turning circle, starting from the starting point, along the path direction corresponding to the starting mode, to the intersection of the target minimum turning circle radius and the route corresponding to the target path sequence, and the tangent of point A can be calculated.
[0237] In the forward direction, starting from the turning point, perform curve fitting on the target path sequence starting from point A to check if a valid transition path sequence can be obtained. This includes ensuring that the curvature meets motion constraints (i.e., the curvature is greater than or equal to the minimum turning curvature of the virtual character) and that all waypoints in the transition path sequence are within the walkable area. If these conditions are met, the path formed by this transition path sequence is determined as the transition path for this forward-right-turn start mode. Figure 5 The star-shaped dots represent transition path points in the transition path sequence, and the long dashed line with dots in the figure represents the transition path.
[0238] If multiple starting methods can yield a valid transition path sequence, the shortest transition path sequence is selected as the target transition path sequence. The target path sequence is then processed using the target transition path sequence to obtain the processed target path sequence, which is the final path sequence of the virtual character.
[0239] In this embodiment, curve fitting of the path sequence using cubic Hermitian curves smooths the path; equal-length sampling of the fitted curve ensures a uniform waypoint sequence; curvature correction using the minimum turning radius of the virtual character reduces path curvature, ensuring the waypoint sequence satisfies the virtual character's kinematic constraints; and starting adjustment using the minimum turning radius circle allows for a smooth start for the virtual character. This improves upon the shortcomings of existing path planning techniques, yielding a globally optimal path that satisfies kinematic constraints, enabling various vehicles to use motion control algorithms for line following and achieving smooth and excellent movement performance in the game.
[0240] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of this application.
[0241] Reference Figure 6The diagram illustrates a structural block diagram of an embodiment of a path planning device for a virtual character according to this application. In this embodiment, the path planning device for the virtual character may include the following modules:
[0242] The initial path generation module 601 is used to obtain the start point and end point of the virtual character in the game scene, and determine the initial path sequence connecting the start point and the end point based on the game scene;
[0243] The fitting curve generation module 602 is used to perform curve fitting on the initial path sequence to obtain a fitting curve;
[0244] The sampling path generation module 603 is used to sample the fitted curve to obtain a sampling path sequence, wherein the sampling path sequence includes multiple sampling path points;
[0245] The curve path generation module 604 is used to determine multiple sub-path sequences in the sampled path sequence that form a curve, each of the sub-path sequences consisting of turning path points that form the same curve;
[0246] The target path generation module 605 is used to perform curve fitting on the turning points in the sub-path sequence again and then sample them when the turning radius of a turning point in the sub-path sequence is less than a preset first turning radius threshold, so as to obtain the target path sequence.
[0247] Optionally, the initial path generation module 601 includes:
[0248] The pathfinding mesh model generation module is used to generate the pathfinding mesh model corresponding to the game scene;
[0249] The initial path generation module based on the network model is used to determine the initial path sequence from the starting point to the ending point according to the pathfinding grid model and a preset pathfinding algorithm.
[0250] Optionally, the initial path generation module based on the network model includes:
[0251] The inflection point determination module is used to determine the inflection points from the starting point to the ending point in the pathfinding grid model;
[0252] The inflection point optimization module is used to move the inflection point along the edge of the grid it is located on toward the walkable area when the inflection point is located at the boundary between the walkable area and the non-walkable area in the pathfinding grid model, so as to update the inflection point and obtain the corresponding updated inflection point.
[0253] The module for generating an initial path based on the optimized inflection point is used to take the starting point, the updated inflection point, and the ending point as initial path points to obtain an initial path sequence.
[0254] Optionally, the fitting curve generation module 602 is used to construct a cubic Hermit curve using the initial path points in the initial path sequence as control points to obtain the fitting curve.
[0255] Optionally, the sampling path generation module 603 includes:
[0256] The sampling path point angle calculation module is used to calculate the tangent angle between two adjacent sampling path points in the sampling path sequence in turn.
[0257] A turning path point generation module is used to determine two sampled path points whose tangent angle is greater than a preset first angle threshold as turning path points;
[0258] The curve path determination module is used to determine multiple adjacent turning path points into a sub-path sequence.
[0259] Optionally, the target path generation module includes:
[0260] The secondary fitting path determination module is used to determine the sub-path sequence with a turning radius of turning path points that is less than a preset first turning radius threshold as the target sub-path sequence;
[0261] The first target path update module is used to merge the turning path points in the two adjacent target sub-path sequences and the sampling path points of the interval when the number of sampling path points between two adjacent target sub-path sequences is less than a preset interval number threshold, so as to obtain a new target sub-path sequence.
[0262] Optionally, the target path sequence consists of multiple target path points, and the device includes:
[0263] The curvature path point determination module is used to determine the target path points in the target path sequence whose turning radius is less than a preset second turning radius threshold, and to determine the target path points whose turning radius is less than the preset second turning radius threshold as curvature path points to be improved; the preset second turning radius threshold is less than the first preset turning radius threshold;
[0264] The curvature path point determination module is used to determine multiple adjacent curvature path points to be improved as a curvature path sequence to be improved.
[0265] The minimum turning radius circle determination module is used to determine the minimum turning radius circle corresponding to each curvature path sequence to be improved.
[0266] The curvature path point update module is used to determine the curvature path points to be improved in the curvature path sequence to be improved, the mapping points on the circumference of the circle with the minimum turning radius, and update the corresponding curvature path points to be improved using the mapping points.
[0267] Optionally, the device includes:
[0268] The mapping point interpolation module is used to add at least one mapping point between two adjacent mapping points when the arc length between two adjacent mapping points on the minimum turning radius circle is greater than a preset length threshold.
[0269] Optionally, the target path sequence includes other target path points besides the curvature path point to be improved; the device further includes:
[0270] The transition fitting curve determination module is used to calculate the transition fitting curves obtained by fitting the other target path points with the mapping points in order from near to far from the minimum turning radius circle.
[0271] The second target path update module is used to over-join the mapping point with other target path points in the target path sequence when the transition fitting curve meets the preset conditions, so as to update the target path sequence.
[0272] Optionally, the device further includes:
[0273] The minimum turning circle determination module is used to determine the minimum turning circle of two virtual characters based on the starting point, orientation, and minimum turning radius of the virtual characters.
[0274] The target minimum turning circle determination module is used to determine the target minimum turning circle corresponding to the starting method of the virtual character; the starting method includes forward-left turn, forward-right turn, backward-left turn, and backward-right turn;
[0275] The transition path sequence determination module is used to determine the transition path sequence corresponding to each starting mode based on the target minimum turning circle and the first target path point in the target path sequence that is located outside the target minimum turning circle;
[0276] A target filtering path sequence determination module is used to determine a target transition path sequence from the transition path sequence;
[0277] The third update module for the target path sequence is used to process the target path sequence according to the target transition path sequence to obtain the processed target path sequence.
[0278] Optionally, the transition path sequence determination module includes:
[0279] The turning circle path point determination module is used to sample the target minimum turning circle to obtain the turning circle path point;
[0280] The turning circle point determination module is used to determine whether the turning circle point is located in the walkable area of the game scene;
[0281] The target turning circle point determination module is used to determine, if yes, the first target path point located outside the target turning circle in the target path sequence, and to determine the target turning circle point in the target minimum turning circle, wherein the target turning circle point is the turning circle point in the target minimum turning circle that is closest to the first target path point in the reverse direction of the path corresponding to the starting mode.
[0282] The steering tangent angle calculation module is used to calculate the steering tangent angle between the first target path point and the target steering circle point;
[0283] The module for determining the turning circle point to be fitted is used to obtain the turning circle point between the target turning circle point and the starting point as the turning circle point to be fitted if the included angle of the turning tangent is less than a preset second included angle threshold.
[0284] The module for determining the transition path curve based on the turning circle point is used to perform curve fitting on the turning circle point to be fitted and the first target path point to obtain the transition path curve.
[0285] The transition path sequence determination module is used to sample the transition path curve to obtain the transition path sequence.
[0286] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0287] This application also discloses an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the path planning method for a virtual character as described above.
[0288] This application also discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the path planning method for a virtual character as described above.
[0289] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0290] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0291] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0292] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0293] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0294] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0295] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0296] The path planning method, apparatus, electronic device, and storage medium for a virtual character provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A path planning method for a virtual character, characterized by, The method comprises: obtaining a starting point and an ending point of a virtual character in a game scene, and determining an initial path sequence connecting the starting point and the ending point based on the game scene; curve fitting is performed on the initial path sequence to obtain a fitting curve; sampling is performed on the fitting curve to obtain a sampling path sequence, the sampling path sequence comprising a plurality of sampling path points; determining a plurality of sub-path sequences in the sampling path sequence for composing a curve, each of the sub-path sequences being composed of turning path points composing a same curve; when a turning radius of a turning path point in the sub-path sequence is less than a preset first turning radius threshold, performing curve fitting again on the turning path point in the sub-path sequence to update a path corresponding to the sub-path sequence in the fitting curve, and sampling the updated fitting curve to obtain a target path sequence, the target path sequence being used for controlling movement of the virtual character; the method further comprises: determining minimum turning circles of the two virtual characters according to the starting point, the orientation and the minimum turning radius of the virtual character; determining a target minimum turning circle corresponding to a starting mode of the virtual character according to the starting mode, the starting mode comprising forward-left turn, forward-right turn, backward-left turn and backward-right turn; determining a transition path sequence corresponding to each starting mode according to the target minimum turning circle and a first target path point in the target path sequence which is located outside the target minimum turning circle; determining a target transition path sequence from the transition path sequence; processing the target path sequence according to the target transition path sequence to obtain a processed target path sequence.
2. The method of claim 1, wherein, The method comprises: generating a pathfinding grid model corresponding to the game scene; determining an initial path sequence from the starting point to the ending point based on the pathfinding grid model and a preset pathfinding algorithm.
3. The method of claim 2, wherein, The method comprises: determining inflection points from the starting point to the ending point in the pathfinding grid model; for each of the inflection points, when the inflection point is located on a boundary between a walkable region and a non-walkable region in the pathfinding grid model, moving the inflection point along an edge of a grid where the inflection point is located to the walkable region to update the inflection point to obtain a corresponding updated inflection point; taking the starting point, the updated inflection points and the ending point as initial path points to obtain an initial path sequence.
4. The method of claim 1, wherein, The method comprises: taking the initial path points in the initial path sequence as control points to construct a cubic Hermite curve to obtain a fitting curve.
5. The method of claim 1, wherein, The method comprises: calculating a tangent angle between two adjacent sampling path points in the sampling path sequence; determine two sampling path points with an included angle greater than a preset first included angle threshold as a turning path point; determine a plurality of adjacent turning path points as a sub-path sequence.
6. The method of claim 1, wherein, when a turning radius of a turning path point in the sub-path sequence is less than a preset first turning radius threshold, perform curve fitting on the turning path point in the sub-path sequence again, including: determine a sub-path sequence in which a turning radius of a turning path point is less than a preset first turning radius threshold as a target sub-path sequence; when a number of interval sampling path points between two adjacent target sub-path sequences is less than a preset interval number threshold, merge the turning path points in the two adjacent target sub-path sequences and the interval sampling path points to obtain a new target sub-path sequence.
7. The method of claim 1, wherein, the target path sequence is composed of a plurality of target path points, and the method further includes: determine a target path point in the target path sequence with a turning radius less than a preset second turning radius threshold, and determine the target path point with the turning radius less than the preset second turning radius threshold as a curvature improvement path point to be improved; the preset second turning radius threshold is less than the preset first turning radius threshold; determine a plurality of adjacent curvature improvement path points to be improved as a curvature improvement path sequence to be improved; for each of the curvature improvement path sequences to be improved, determine a minimum turning radius circle corresponding to the curvature improvement path sequence to be improved; determine a mapping point of a curvature improvement path point in the curvature improvement path sequence to be improved on a circumference of the minimum turning radius circle, and update the corresponding curvature improvement path point by using the mapping point.
8. The method of claim 7, wherein, the method further includes: when an arc length between two adjacent mapping points on the minimum turning radius circle is greater than a preset length threshold, add at least one mapping point between the two adjacent mapping points.
9. The method of claim 8, wherein, the target path sequence includes other target path points in addition to the curvature improvement path points to be improved; the method further includes: in order from near to far of the minimum turning radius circle, sequentially calculate a transition fitting curve obtained by curve fitting of the other target path points and the mapping points; when the transition fitting curve meets a preset condition, splice the mapping points and the other target path points in the target path sequence to update the target path sequence.
10. The method of claim 1, wherein, determine a transition path sequence corresponding to each starting mode according to the target minimum turning circle and a first target path point in the target path sequence located outside the target minimum turning circle, including: sample the target minimum turning circle to obtain a turning circle point; determine whether the turning circle point is located in a walkable area of the game scene; if yes, determine a first target path point in the target path sequence located outside the target minimum turning circle, and determine a target turning circle point in the target minimum turning circle, the target turning circle point being a turning circle point in the target minimum turning circle closest to the first target path point in a direction opposite to a path corresponding to the starting mode; calculate a turning tangent included angle of the first target path point and the target turning circle point; If the included angle between the steering tangent line and the first tangent line is less than a preset second included angle threshold, a steering circle point between the target steering circle point and the starting point is obtained as a to-be-fitted steering circle point; Curve fitting is performed on the to-be-fitted steering circle point and the first target path point to obtain a transition path curve; The transition path curve is sampled to obtain a transition path sequence.
11. A virtual character path planning apparatus, characterized by comprising: The device comprises: An initial path generation module configured to obtain a starting point and an ending point of a virtual character in a game scene, and determine an initial path sequence connecting the starting point and the ending point based on the game scene; A fitted curve generation module configured to perform curve fitting on the initial path sequence to obtain a fitted curve; A sampling path generation module configured to sample the fitted curve to obtain a sampling path sequence, the sampling path sequence comprising a plurality of sampling path points; A curved path generation module configured to determine a plurality of sub-path sequences for composing a curved path in the sampling path sequence, each of the sub-path sequences being composed of steering path points for composing a same curved path; A target path generation module configured to, when a steering radius of a steering path point in the sub-path sequence is less than a preset first steering radius threshold, perform curve fitting again on the steering path point in the sub-path sequence and then perform sampling to obtain a target path sequence, the target path sequence being used to control movement of the virtual character; The device further comprises: A minimum steering circle determination module configured to determine a minimum steering circle of two virtual characters according to a starting point, a direction of the virtual character, and a minimum steering radius; A target minimum steering circle determination module configured to determine a target minimum steering circle corresponding to a starting mode of the virtual character according to the starting mode, the starting mode comprising forward-left turn, forward-right turn, backward-left turn, and backward-right turn; A transition path sequence determination module configured to determine a transition path sequence corresponding to each starting mode according to the target minimum steering circle and a first target path point in the target path sequence that is located outside the target minimum steering circle; A target filtered path sequence determination module configured to determine a target filtered path sequence from the transition path sequence; A target path sequence third update module configured to process the target path sequence according to the target filtered path sequence to obtain a processed target path sequence.
12. An electronic device, comprising: The computer program is stored on the computer readable storage medium and is executable on the processor to implement the steps of the virtual character path planning method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, The computer program is stored on the computer readable storage medium and is executable on the processor to implement the steps of the virtual character path planning method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Way-finding control method and device for game, processing equipment and storage medium
CN113101663A
Path fitting method and device, electronic equipment and storage medium
CN113487693A