Mobile obstacle avoidance method and device for virtual object, electronic equipment and storage medium
By obtaining the moving path and obstacles of the virtual object in the game scene, building a collision sphere and updating the path, the problem of virtual objects passing through the mold when encountering obstacles on the navigation route is solved, achieving a better visual effect.
Patent Information
- Application Number
- CN202510193376.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-06-10
AI Technical Summary
In game scenes, virtual objects may encounter obstacles on the navigation route, causing virtual objects to penetrate the model and affect the visual effect.
By obtaining the first movement path and obstacle of the virtual object, determining the first section and road section endpoints in the first movement path, constructing a collision sphere, and determining the intersection boundary line between the obstacle and the collision sphere, updating the first movement path to a second movement path to avoid obstacles.
It reduces the situation of virtual objects wearing molds and improves the visual effect of virtual scenes.
Smart Images

Figure CN120114839A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of game data processing, and more particularly, to a method, apparatus, electronic device, and storage medium for moving and avoiding obstacles of virtual objects. Background Art
[0002] With the rapid development of three-dimensional games, game scenes are becoming increasingly grand. The virtual characters of players or the virtual vehicles controlled by players can move in the game scene under the guidance of navigation. Currently, in existing games, virtual objects often move along the navigation route in the game scene, but there may be obstacles on this route, which causes the virtual objects to penetrate the model and affects the overall visual effect of the virtual scene. Summary of the Invention
[0003] An object of an embodiment of the present disclosure is to provide a new technical solution for moving and avoiding obstacles of virtual objects.
[0004] According to a first aspect of the present disclosure, there is provided a method for moving and avoiding obstacles of a virtual object, the method including:
[0005] Obtaining a first movement path and an obstacle of the virtual object in a virtual scene;
[0006] Determining a first section within the obstacle in the first movement path and section endpoints of the first section;
[0007] Constructing a collision sphere with a first reference line where the section endpoints are located as the diameter;
[0008] Determining an intersection boundary line between the obstacle and the collision sphere;
[0009] Updating the first movement path to a second movement path according to the boundary line.
[0010] In a possible implementation, the determining the first section within the obstacle in the first movement path and section endpoints of the first section includes:
[0011] Grouping a first part of curves indicated in the first movement path into a first group;
[0012] Converting the first movement path into a plurality of line segments;
[0013] Extracting a first line segment within the first group from the plurality of line segments;
[0014] Setting the first line segments to form a first curve and using it as the first section within the obstacle in the first movement path;
[0015] Determining the section endpoints of the first section.
[0016] In a possible implementation, the road segment endpoints include a first road segment endpoint and a second road segment endpoint. The distance from the first road segment endpoint to the edge line of the obstacle is less than the distance from the second road segment endpoint to the edge line of the obstacle. The method further includes:
[0017] According to the position information of the road segment endpoints, set a first vector from the first road segment endpoint pointing to the edge line of the obstacle;
[0018] Set an offset point at a set distance from the first road segment endpoint along the first vector;
[0019] Use the connection line of the first road segment endpoint, the second road segment endpoint, and the offset point as the first reference line.
[0020] In a possible implementation, the step of updating the first movement path to a second movement path according to the junction line includes:
[0021] Determine a coincidence line in the junction line that coincides with the edge line of the obstacle;
[0022] On the coincidence line, determine a first segmentation point at the first position of the first road segment endpoint;
[0023] According to the first segmentation point, determine a first part of the coincidence line;
[0024] According to the first part, update the first movement path to a second movement path.
[0025] In a possible implementation, the step of determining a first part of the coincidence line according to the first segmentation point includes:
[0026] Determine a first segmentation line where the first endpoint of the coincidence line and the first segmentation point are located, and determine a second segmentation line where the second endpoint of the coincidence line and the first segmentation point are located;
[0027] Determine a first included angle between the first segmentation line and a set second reference line, and determine a second included angle between the second segmentation line and the second reference line;
[0028] Determine the minimum included angle among the first included angle and the second included angle;
[0029] According to the minimum included angle, determine a first part of the coincidence line.
[0030] In a possible implementation, the step of determining a first part of the coincidence line according to the minimum included angle includes:
[0031] When the first included angle is the minimum included angle, determine the part of the coincidence line with the first cut point and the first end point as the end points as the first part;
[0032] When the second included angle is the minimum included angle, determine the part of the coincidence line with the second cut point and the first end point as the end points as the first part.
[0033] In a possible implementation manner, the updating the first movement path to a second movement path according to the first part includes:
[0034] Combine the second part curve that is not indicated in the first movement path and the first part to obtain the second movement path.
[0035] According to a second aspect of the present disclosure, there is also provided a movement obstacle avoidance device for a virtual object, including:
[0036] An acquisition module, configured to acquire a first movement path and an obstacle of the virtual object in a virtual scene;
[0037] A first determination module, configured to determine a first section within the obstacle in the first movement path and the section end points of the first section;
[0038] A construction module, configured to construct a collision sphere with the first reference line where the section end points are located as the diameter;
[0039] A second determination module, configured to determine an intersection boundary line between the obstacle and the collision sphere;
[0040] An update module, configured to update the first movement path to a second movement path according to the boundary line.
[0041] According to a third aspect of the present disclosure, there is also provided a computer system. The computer system includes a processor. When the processor executes program instructions or code, the computer system implements the game scene control method in the first aspect. Exemplarily, the computer system further includes a memory, and the memory is used to store the program instructions or code.
[0042] According to a fourth aspect of the present disclosure, there is also provided a computer-readable storage medium. A computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-mentioned movement obstacle avoidance method for a virtual object when running.
[0043] According to a fifth aspect of the present disclosure, there is also provided a computer program product, including a game program. When the game program is executed, the computer is caused to execute the steps of the above-mentioned movement obstacle avoidance method for a virtual object.
[0044] According to a sixth aspect of the present disclosure, an electronic device is further provided, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to execute the method for moving and avoiding obstacles of the virtual object through the computer program.
[0045] One beneficial effect of the embodiments of the present disclosure is that the method for moving and avoiding obstacles of the virtual object provided by the embodiments of the present disclosure can obtain the first moving path and obstacles of the virtual object in the virtual scene, determine the first section of the first moving path and the section endpoints of the first section, construct a collision sphere through the section endpoints, then determine the intersection boundary line between the collision sphere and the obstacles, and further determine the second moving path that can avoid the obstacles through the boundary line, thereby reducing the occurrence of the virtual object penetrating the model and effectively improving the visual effect of the virtual scene.
[0046] Through the following detailed description of the exemplary embodiments of the present specification with reference to the accompanying drawings, the features and advantages of the embodiments of the present specification will become clear. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings incorporated in and constituting a part of this specification illustrate embodiments of the present specification and, together with the description, are used to explain the principles of the embodiments of the present specification.
[0048] Figure 1 The schematic diagram of the hardware structure of an electronic device that can be used to implement the method for moving and avoiding obstacles of the virtual object according to the embodiments of the present disclosure is shown;
[0049] Figure 2 The flowchart of the method for moving and avoiding obstacles of the virtual object according to some embodiments is shown;
[0050] Figure 3 The schematic diagram showing the first section according to some embodiments is shown;
[0051] Figure 4 The schematic diagram of the boundary line according to some embodiments is shown;
[0052] Figure 5 The schematic diagram of the structure of the device for moving and avoiding obstacles of the virtual object according to some embodiments is shown;
[0053] Figure 6 The schematic diagram of the hardware structure of an electronic device according to some embodiments is shown. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0054] Now, various exemplary embodiments of the present specification will be described in detail with reference to the accompanying drawings.
[0055] The following description of at least one exemplary embodiment is merely illustrative and is in no way a limitation on the embodiments of this specification, their applications, or uses.
[0056] It should be noted that like reference numerals and letters denote like items in the following figures. Therefore, once an item is defined in one figure, further discussion thereof is not required in subsequent figures.
[0057] It should be noted that all actions of obtaining signals, information, or data in the embodiments of the present disclosure are carried out on the premise of complying with the corresponding data protection regulations and policies of the country where the location is located and obtaining authorization from the corresponding device owner.
[0058] The embodiments of the present disclosure provide a new moving obstacle avoidance solution for virtual objects, which allows the virtual object to obtain the first moving path of the virtual object and the obstacles blocking the movement of the virtual object during the movement in the virtual scene, determine the first section of the first moving path and the section endpoints of the first section, construct a collision sphere through the section endpoints, then determine the intersection boundary line between the collision sphere and the obstacle, and further determine the second moving path that can avoid the obstacle through the boundary line, thereby reducing the occurrence of the virtual object penetrating the model and effectively improving the visual effect of the virtual scene.
[0059] Figure 1 The hardware structure diagram of an electronic device that can be used to implement the moving obstacle avoidance method of virtual objects according to the embodiments of the present disclosure is shown.
[0060] The electronic device 1000 is a device capable of running games. The game can be a local application installed on the electronic device, or a web game, a lightweight application, or a small program, etc., which is not limited herein. The electronic device 1000 can be a mobile phone, a tablet computer, a PC, etc., which is not limited herein.
[0061] As Figure 1 shown, the electronic device 1000 may include a processor 1101, a memory 1102, an interface device 1103, a communication device 1104, an output device 1105, an input device 1106, and so on. Figure 1 The hardware configuration shown is merely illustrative and is in no way intended to limit the present disclosure, its applications, or uses.
[0062] The processor 1101 is used to execute a computer program, which can be written in an instruction set of architectures such as x86, Arm, RISC, MIPS, SSE, etc. The memory 1102 includes, for example, ROM (Read-Only Memory), RAM (Random Access Memory), non-volatile memory such as a hard disk, etc. The interface device 1103 includes, for example, a USB interface, a network cable interface, a headphone interface, etc. The communication device 1104 can perform wired or wireless communication, for example. The communication device 1104 may include at least one short-range communication module, for example, any module that performs short-range wireless communication based on short-range wireless communication protocols such as the Hilink protocol, WiFi (IEEE 802.11 protocol), Mesh, Bluetooth, ZigBee, Thread, Z-Wave, NFC, UWB, LiFi, etc. The communication device 1104 may also include a remote communication module, for example, any module that performs WLAN, GPRS, 2G / 3G / 4G / 5G remote communication. The output device 1105 may include, for example, a liquid crystal display screen or a touch display screen, a speaker, etc. The input device 1106 may include, for example, a touch screen, a keyboard, a microphone, various sensors, etc.
[0063] In this embodiment, the memory 1102 of the electronic device 1000 is used to store a computer program, which is used to control the processor 1101 to operate to execute the method for moving and avoiding obstacles of a virtual object according to any embodiment of the present disclosure.
[0064] Next, taking the electronic device 1000 as an example of the implementation subject, various embodiments of the method for moving and avoiding obstacles of a virtual object will be described. Figure 1 For example, various embodiments of the method for moving and avoiding obstacles of a virtual object will be described.
[0065] <First Embodiment>
[0066] Figure 2 The method for moving and avoiding obstacles of a virtual object according to some embodiments is shown. The method for moving and avoiding obstacles of a virtual object may include the following steps S210 to step S230:
[0067] Step S210, obtaining a first movement path and an obstacle of the virtual object in the virtual scene.
[0068] In this embodiment, the virtual object is, for example, a virtual character, a virtual vehicle, or a virtual animal, etc. The obstacle is a virtual object that blocks the movement of the virtual object. Here, the virtual object is generally a virtual building, a virtual mountain, or a virtual river, etc. And, the obstacle is a virtual object that intersects the first movement path of the virtual object.
[0069] Step S220, determining a first section within the obstacle in the first movement path and the section endpoints of the first section.
[0070] In this embodiment, as Figure 3 shown, the edge line of the obstacle is a polygonal area D1, the first section of the first moving path inside the edge line of the obstacle is section D2, and the "1" point and the "0" point are the two section endpoints of the first section.
[0071] Step S230: Construct a collision sphere with the first reference line where the section endpoint is located as the diameter.
[0072] In this embodiment, as Figure 3 shown, the "0" point can be used as the center of the collision sphere, and section D2 as the radius of the collision sphere to construct a collision sphere.
[0073] Step S240: Determine the intersection boundary line between the obstacle and the collision sphere.
[0074] In this embodiment, since the obstacle is a three-dimensional virtual object, the intersection boundary line between the obstacle and the collision sphere is a closed area. As Figure 4 shown, the boundary line formed after the obstacle intersects with the collision sphere is a polygonal area D3.
[0075] Step S250: Update the first moving path to the second moving path according to the boundary line.
[0076] In this embodiment, the first section of the first moving path can be replaced by the first part or the second part of the boundary line. Here, the first part can be the edge section of the edge line of the obstacle in the boundary line, and the endpoints of this edge section include the first path endpoint. Among them, the first path endpoint is the path endpoint in the first section close to the edge line of the obstacle. Taking Figure 4 the shown boundary line as an example, this path endpoint is the "0" point, and the edge section can be the part connected in sequence from point "0" to point "20", or the part connected in sequence from the "0" point, point "39" to point "33".
[0077] According to the method for moving obstacle avoidance of virtual objects in the first embodiment of the present invention, it solves the problem in the prior art that there may be obstacles on the first moving path, which causes the virtual object to penetrate the model. Based on this method, the first moving path and the obstacle of the virtual object in the virtual scene are obtained, the first section of the first moving path and the section endpoints of the first section are determined, a collision sphere is constructed through the section endpoints, and then the intersection boundary line between the collision sphere and the obstacle is determined. Then, the second moving path that can avoid the obstacle is determined through this boundary line, thereby reducing the occurrence of the virtual object penetrating the model and effectively improving the visual effect of the virtual scene.
[0078] <Second Embodiment>
[0079] In this embodiment, in order to accurately determine the first section of the first moving path located within the obstacle and the section endpoints of the first section, the first moving path is converted into a plurality of line segments, and the first line segments within the obstacle in the first moving path are retained, while the second line segments outside the obstacle are removed. Then, the first line segments are combined to form a first curve, and the two endpoints of the first curve are obtained as the section endpoints of the first section.
[0080] In these embodiments, compared with the above first embodiment, step S220 may include the following steps S310 to S350:
[0081] Step S310, group the first partial curve indicated in the first moving path into a first group.
[0082] In this embodiment, step S310 may be: input the first partial curve indicated in the first moving path into a preset first configuration file, so that in the first configuration node 1.1matchsize7 of the first configuration file, the input first moving path that needs to be avoided is processed to ensure that the Y-axis coordinate of the center point is zero. In the second configuration node 1.2group1 of the first configuration file, select the first partial curve representing the end of the road in the input first moving path and group it into the inner_path2 group, that is, the first group.
[0083] Step S320, convert the first moving path into a plurality of line segments.
[0084] In this embodiment, step S320 may be: in the third configuration node 1.3convertline3 of the first configuration file, convert the first partial curve into a plurality of line segments.
[0085] Step S330, extract the first line segments within the first group from the plurality of line segments.
[0086] In this embodiment, step S330 may be: in the fourth configuration node 1.4blast3 of the first configuration file, delete the line segments not in the inner_path2 group. In the fifth configuration node 1.5remove_unconnected_points4 of the first configuration file, clear the unconnected points and clean up the redundant points, that is, extract the first line segments within the first group.
[0087] Step S340, set the first line segments to form a first curve and use it as the first section of the first moving path within the obstacle.
[0088] In this embodiment, step S340 may be: in the sixth configuration node 1.6 polypath4 of the first configuration file, convert the processed first line segment into a first curve. The first curve is, for example, the road segment D2 as shown in Figure 3 shown.
[0089] Step S350, determine the road segment endpoints of the first road segment.
[0090] In this embodiment, step S350 may be: start a loop at the seventh configuration node 1.7 foreach_begin1 of the first configuration file. Select two road segment endpoints of the first curve in the eighth configuration node 1.8 groupexpression13 of the first configuration file. Name the group where len(neighbours(0, @ptnum)) == 1 as end_point, that is, obtain the "0" point and "1" point as shown in Figure 3 shown. Delete the non-endpoint parts in the ninth configuration node 1.9 delete4 of the first configuration file. Measure the distance between the two road segment endpoints of the first curve in the tenth configuration node 1.10 measure2 of the first configuration file and record it in the perimeter attribute at the primitives level.
[0091] <Third Embodiment>
[0092] In this embodiment, in order to make the intersection line generated by the constructed collision sphere intersecting with the obstacle close to the first movement path, so that the virtual object can avoid obstacles when moving along the second movement path, the road segment endpoints may include a first road segment endpoint and a second road segment endpoint, and the distance from the first road segment endpoint to the edge line of the obstacle is less than the distance from the second road segment endpoint to the edge line of the obstacle.
[0093] In these embodiments, compared with the above first embodiment, before step S230, the method further includes the following steps S410 to S430:
[0094] Step S410, set a first vector from the first road segment endpoint pointing to the edge line of the obstacle according to the position information of the road segment endpoints.
[0095] In this embodiment, step S410 may be: in the eleventh configuration node 1.11 attribwrangle1 of the first configuration file, determine that the path endpoint is in the inner_end_pt point group (the point pressed inside the obstacle), assign it to the pos_inner vector, and find the normal vector from pos_inner to pos_edge, that is, the first vector.
[0096] Step S420, set an offset point at a set distance from the first road segment endpoint along the first vector.
[0097] In this embodiment, a new point, i.e., the offset point, is created at a position offset by a set distance along the first vector. Taking Figure 3 as shown, an extension line is set in the direction from point "1" towards point "0", and the length of this extension line is the set distance. Then, the end of the extension line far from point "0" is the offset point.
[0098] Step S430: Use the line connecting the endpoints of the first section, the endpoints of the second section, and the offset point as the first reference line.
[0099] In this embodiment, this extension line and the first curve are combined into a new curve, i.e., the first reference line. The code for generating the first reference line is as follows:
[0100] float distance = prim(0, "perimeter", 0);
[0101] string inner_end_pt = "inner_end_pt";
[0102] vector pos_inner, pos_edge;
[0103] for (int pt = 0; pt < npoints(0); ++pt)
[0104] {
[0105] if (inpointgroup(0, inner_end_pt, pt))
[0106] {
[0107] pos_inner = point(0, "P", pt);
[0108] }
[0109] else { pos_edge = point(0, "P", pt);}
[0110] }
[0111] vector nml0 = normalize(pos_edge - pos_inner);
[0112] / / Create a new point along the normal direction
[0113] vector newPos = pos_edge + distance * nml0;
[0114] int newPt = addpoint(0, newPos);
[0115] / / polyline
[0116] int newPrim = addprim(0, "polyline", 0, newPt);
[0117] In other words, by setting up the collision sphere constructed with the first reference line, a junction line capable of avoiding obstacles can be obtained, thereby achieving effective obstacle avoidance for the virtual object.
[0118] <Fourth Embodiment>
[0119] In this embodiment, in order to avoid obstacles along the shortest path on the premise of obstacle avoidance for the virtual object, by determining a first segmentation point at the first position of the endpoint of the first section, the first part of the coincidence line is determined, so that the virtual object moves along the first part when passing through the obstacle.
[0120] In these embodiments, compared with the above-mentioned third embodiment, step S250 may include the following steps S510 to S540:
[0121] Step S510, determining the coincidence line that coincides with the edge line of the obstacle in the junction line.
[0122] In this embodiment, step S230 may be: creating a collision sphere in the twelfth configuration node 1.12sphere1 of the first configuration file, using the first reference line as the diameter, and using it as a range detector.
[0123] In this embodiment, step S240 may be: importing the null3 node (i.e., the edge line of the obstacle) in the thirteenth configuration node 1.13object_merge8 of the first configuration file. In the fourteenth configuration node 1.14boolean5 of the first configuration file, an intersection operation is performed between the collision sphere and the edge line of the obstacle, and the intersection part is obtained and the junction line abseams_edge edge group is output.
[0124] In this embodiment, step S510 may be: converting the junction line abseams_edge edge group to point level and renaming it to the abseams point group in the fifteenth configuration node 1.15grouppromote2 of the first configuration file. In the sixteenth configuration node 1.16convertline7 of the first configuration file, the curves other than the abseams_edge edge group are converted to line segments, and the unused points are deleted, that is, the intersecting edges are deleted. In the seventeenth configuration node 1.17group2 node of the first configuration file, the points in the remaining line segments are grouped and named origin_pt, that is, the point group of the coincidence line that coincides with the edge line of the obstacle in the junction line is obtained.
[0125] Step S520: On the coincidence line, determine a first splitting point at a first position at the endpoint of the first section.
[0126] In this embodiment, step S520 may be: In the 18th configuration node 1.18curve_dir of the first configuration file, calculate the normal vector from the "0" point to the "1" point as the pointing direction of the coincidence line. The code for determining the pointing direction is as follows:
[0127]
[0128] In the 19th configuration node 1.19choose_nearPath of the first configuration file, with the "0" point (outer endpoint) input through the second channel as the center, set a search radius, and regroup the points in the point group input through the first channel within the radius into a point group named near_path, that is, select the points on the coincidence line closest to the outer endpoint. The code is as follows:
[0129]
[0130] {
[0131] setpointgroup(0,"near_path",ptIdx,1,"set");
[0132] }
[0133] In the 20th configuration node 1.20groupexpand4 of the first configuration file, expand the points on the coincidence line to select all the points on the entire coincidence line, and update the points included in the near_path point group. In the 21st configuration node 1.21blast11 of the first configuration file, delete the other points outside the near_path point group. In the 22nd configuration node 1.22groupexpression4 of the first configuration file, select the two end points of the coincidence line, len(neighbours(0, @ptnum)) == 1, and the group is start_pt. In the 23rd configuration node 1.23grouprange1 of the first configuration file, update the group start_pt by filtering the qualified points through the specified relative starting point, so that there is only one starting point inside. In the 24th configuration node 1.24distancealonggeometry1 of the first configuration file, with the points in start_pt as the starting points, calculate the cumulative distance along the specified path and output the normalized mask value (the entire length is 1). In the 25th configuration node 1.25add1 of the first configuration file, delete the points on the coincidence line and keep the points, and add a new point new. The position of this point comes from the position coordinates of the "0" point in the 10th configuration node 1.10measure2 node, that is, the first cut point, to be used as the target point for subsequent direction operations.
[0134] Step S530: Determine the first part of the coincidence line according to the first cut point.
[0135] In this embodiment, as Figure 4 shown, the first cut point is the "0" point, and the first part of the coincidence line can be the part sequentially connected by the "0" point to the "20" point, or the part sequentially connected by the "0" point, the "39" point to the "33" point.
[0136] Step S540: Update the first movement path to the second movement path according to the first part.
[0137] <Fifth Embodiment>
[0138] In this embodiment, in order to determine the shortest obstacle avoidance path of the virtual object, by splitting the coincidence line into a first cut line and a second cut line, comparing the magnitudes of the first included angle between the first cut line and the second reference line and the second included angle between the second cut line and the second reference line, and then selecting the cut line with the smaller included angle among the two included angles, determining the part of the coincidence line corresponding to the cut line, and using it as the shortest obstacle avoidance path.
[0139] In these embodiments, compared with the above fourth embodiment, this step S540 may include the following steps S610 to S640:
[0140] Step S610: Determine the first cut line where the first endpoint and the first splitting point of the overlapping line are located, and determine the second cut line where the second endpoint and the first splitting point of the overlapping line are located.
[0141] In this embodiment, step S610 may be: In the 26th configuration node 1.26attribtransfer1 of the first configuration file, transfer the mask attribute to the point group near_path. In the 27th configuration node 1.27sort1 of the first configuration file, rearrange the point numbers in ascending order according to the value of the mask. In the 28th configuration node 1.28add2 of the first configuration file, connect the parts of the non-abseams point group. In the 29th configuration node 1.29convertline4 of the first configuration file, select the part of the non-abseams group, which is the overlapping line just created, delete the isolated points that are not connected to this overlapping line, and record the length of the overlapping line in the restlength attribute. In the 30th configuration node 1.30group3 of the first configuration file, select the non-origin_pt group and group it as new_pt. In the 31st configuration node 1.31grouppromote3 of the first configuration file, convert to the primitives level through new_pt and name it the new_prim group. In the 32nd configuration node 1.32blast9 of the first configuration file, delete the polygon elements other than the new_prim group, aiming to screen the generated overlapping line to ensure that no extra points or lines are generated. In the 33rd configuration node 1.33split_by_newPt of the first configuration file, use the points in new_pt as the splitting points to split the overlapping line into two curves. The overlapping line splitting code is as follows:
[0142] int split_point_num = @ptnum;
[0143] int pts[] = primpoints(0,0);
[0144] if(find(pts, split_point_num) > -1)
[0145] {
[0146] / / add point
[0147] vector split_pt_pos = point(0, "P", split_point_num);
[0148] int split_point_copy = addpoint(0, split_pt_pos);
[0149] / / curve1
[0150] int newPrimBeforeSplit = addprim(0, "polyline");
[0151] for (int i = 0; i <= split_point_num; ++i)
[0152] {
[0153] int pt = pts[i];
[0154] addvertex(0, newPrimBeforeSplit, pt);
[0155] }
[0156] / / curve2
[0157] int newPrimAfterSplit = addprim(0, "polyline");
[0158] addvertex(0, newPrimAfterSplit, split_point_copy);
[0159] for (int i = split_point_num + 1; i < len(pts); ++i)
[0160] {
[0161] int pt = pts[i];
[0162] addvertex(0, newPrimAfterSplit, pt);
[0163] }
[0164] / / delete original curve
[0165] removeprim(0, 0, 1);
[0166] }
[0167] In the 34th configuration node 1.34sort2 of the first configuration file, according to the new connectivity, optimize the arrangement order of the point numbers, and add the 2 new endpoints cut out by the cutting point new to the arrangement order of the numbers. In the 35th configuration node 1.35groupexpression14 of the first configuration file, select the endpoints of two line segments where len(neighbours(0, @ptnum)) == 1, and the group is end_point. In the 36th configuration node 1.36blast4 of the first configuration file, delete the other points except the endpoints, and turn the two curves just cut out into the first cut line and the second cut line to prepare for the following angle calculation.
[0168] Step S620, determine the first angle between the first cut line and the set second reference line, and determine the second angle between the second cut line and the second reference line.
[0169] Step S630, determine the minimum angle among the first angle and the second angle.
[0170] In this embodiment, this step S620 can be: in the 37th configuration node 1.37get_closer_primnum1 of the first configuration file, according to curve_dir in the curve direction, that is, the second reference line, calculate each side respectively, find the side with the minimum angle with it, and record the primID of this side on the closer_prim attribute of the Detail level. The code to determine the side with the minimum angle is as follows:
[0171] vector shared_pos = point(1, "P", 0);
[0172] vector curve_dir = detail(1, "curve_dir");
[0173] vector min = (1e - 5, 1e - 5, 1e - 5);
[0174] float min_angle = M_PI;
[0175] int min_angle_primnum = -1;
[0176] for(int primnum = 0; primnum < nprimitives(0); ++primnum) {
[0177] / / Obtain the two points corresponding to each primitive
[0178] int pts[] = primpoints(0, primnum);
[0179] vector pos0 = point(0, "P", pts[0]);
[0180] vector pos1 = point(0, "P", pts[1]);
[0181] / / Compare which point is at the shared position
[0182] int shared_idx = -1;
[0183] if (pos0 - shared_pos < min)
[0184] shared_idx = 0;
[0185] if (pos1 - shared_pos < min)
[0186] shared_idx = 1;
[0187] if (shared_idx >= 0) {
[0188] / / Determine the position of the other endpoint. Using the point at the shared position as the starting point of the vector, calculate the direction vector
[0189] vector other_pos = shared_idx == 0? pos1 : pos0;
[0190] vector dir = normalize(other_pos - shared_pos);
[0191] float angle = acos(dot(dir, curve_dir));
[0192] if (angle < min_angle) {
[0193] min_angle = angle;
[0194] min_angle_primnum = primnum;
[0195] }
[0196] }
[0197] }
[0198] i@closer_prim = min_angle_primnum;
[0199] Step S640: Determine the first part of the overlapping line according to the minimum included angle.
[0200] <Sixth Embodiment>
[0201] In this embodiment, in order to determine the shortest obstacle avoidance path of the virtual object, compare the first included angle and the second included angle, and select the part corresponding to the minimum included angle in the overlapping line, so that the virtual object moves along the curve of this part when moving to the obstacle.
[0202] In these embodiments, compared with the above-mentioned fifth embodiment, this step S640 may include the following steps S710 and S720:
[0203] Step S710: When the first included angle is the minimum included angle, determine the part of the overlapping line with the first cut point and the first end point as the end points as the first part.
[0204] Step S720: When the second included angle is the minimum included angle, determine the part of the overlapping line with the second cut point and the first end point as the end points as the first part.
[0205] In the thirty-eighth configuration node 1.38choose_new_curve of the first configuration file, import the overlapping line in the thirty-third configuration node 1.33split_by_newPt node, and delete the curves other than the line corresponding to the ID number recorded in the closer_prim attribute, that is, only leave the part with the minimum included angle among the two segmented curves. The code for determining the part with the minimum included angle is as follows:
[0206]
[0207] In the thirty-ninth configuration node 1.39foreach_end1 of the first configuration file, end the loop. In the fortieth configuration node 1.40group5 of the first configuration file, group the cutting points as end_point_new and construct the second movement path together with the filtered curves.
[0208] <Seventh Embodiment>
[0209] In this embodiment, in order to enable the virtual object to move along the second movement path, the second part curve that is not indicated in the first movement path can be combined with the first part to obtain the second movement path.
[0210] In these embodiments, compared with the above-mentioned fourth embodiment, this step S540 may include the following step S810:
[0211] Step S810: Combine the second part curve that is not indicated in the first movement path with the first part to obtain the second movement path.
[0212] In this embodiment, the second partial curve that is not indicated in the first movement path may be other sections in the first movement path except for section D2. As Figure 4 shown, the first part is, for example, the part from the "0" point to the "20" point, and may be spliced with the first part in other sections to form the second movement path.
[0213] <Device Embodiment>
[0214] Figure 5 The composition structure diagram of the movement obstacle avoidance device for a virtual object according to an embodiment of the present disclosure is shown. As Figure 5 shown, the movement obstacle avoidance device 400 for the virtual object includes an acquisition module 410, a first determination module 420, a construction module 430, a second determination module 440, and an update module 450.
[0215] The acquisition module 410 is configured to acquire a first movement path and an obstacle of a virtual object in a virtual scene;
[0216] The first determination module 420 is configured to determine a first section within the obstacle in the first movement path and the section endpoints of the first section;
[0217] The construction module 430 is configured to construct a collision sphere with the first reference line where the section endpoints are located as the diameter;
[0218] The second determination module 440 is configured to determine the intersection boundary line between the obstacle and the collision sphere;
[0219] The update module 450 is configured to update the first movement path to a second movement path according to the boundary line.
[0220] In some embodiments, the first determination module 420 is further configured to group the first partial curves indicated in the first movement path into a first group; convert the first movement path into multiple line segments; extract the first line segments within the first group from the multiple line segments; set the first line segments to form a first curve and use it as the first section within the obstacle in the first movement path; and determine the section endpoints of the first section.
[0221] In some embodiments, the movement obstacle avoidance device 400 for the virtual object further includes a setting module, and the setting module is configured to set a first vector pointing from the first section endpoint to the edge line of the obstacle according to the position information of the section endpoints; set an offset point at a set distance from the first section endpoint along the first vector; and use the connection line of the first section endpoint, the second section endpoint, and the offset point as the first reference line.
[0222] In some embodiments, the moving obstacle avoidance device 400 of the virtual object further includes a segmentation module, which is used to determine the coincidence line that coincides with the edge line of the obstacle in the junction line; on the coincidence line, determine the first segmentation point at the first position of the end point of the first section; according to the first segmentation point, determine the first part of the coincidence line; according to the first part, update the first moving path to the second moving path.
[0223] In some embodiments, the segmentation module is further used to determine the first segmentation line where the first end point and the first segmentation point of the coincidence line are located, and determine the second segmentation line where the second end point and the first segmentation point of the coincidence line are located; determine the first included angle between the first segmentation line and the set second reference line, and determine the second included angle between the second segmentation line and the second reference line; determine the minimum included angle among the first included angle and the second included angle; according to the minimum included angle, determine the first part of the coincidence line.
[0224] In some embodiments, when the first included angle is the minimum included angle, the segmentation module is used to determine the part of the coincidence line with the first segmentation point and the first end point as the end points as the first part; when the second included angle is the minimum included angle, determine the part of the coincidence line with the second segmentation point and the first end point as the end points as the first part.
[0225] In some embodiments, the update module 450 is further used to combine the second part curve not indicated in the first moving path with the first part to obtain the second moving path.
[0226] <Device Embodiment>
[0227] Figure 6 The hardware structure diagram of an electronic device according to some other embodiments is shown. As Figure 6 shown, the electronic device 500 includes a processor 510 and a memory 520. The memory 520 is used to store a computer program, and the computer program is used to control the processor 510 to operate so as to control the electronic device 500 to execute the moving obstacle avoidance method of the virtual object according to any embodiment of the present disclosure.
[0228] An embodiment of the present disclosure also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the moving obstacle avoidance method of the virtual object according to any embodiment of the present disclosure.
[0229] An embodiment of the present disclosure also provides a computer program product, which includes a computer program or instruction. When the computer program or instruction is executed by a processor, it implements the moving obstacle avoidance method of the virtual object according to any embodiment of the present disclosure.
[0230] The various embodiments in this specification are described in a progressive manner. For the same or similar parts among the various embodiments, reference can be made to each other, and the key point of each embodiment is to illustrate the differences from other embodiments. In particular, for device and equipment embodiments, since they are basically similar to method embodiments, the description is relatively simple, and reference can be made to the relevant parts of the method embodiments for the relevant content.
[0231] The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve the desired result. Additionally, the processes depicted in the figures do not necessarily require the specific order or sequential order shown to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0232] The embodiments of this specification can be devices, methods, and / or computer program products. A computer program product can include a computer-readable storage medium having thereon computer-readable program instructions for causing a processor to implement various aspects of the embodiments of this specification.
[0233] A computer-readable storage medium can be a tangible device that can hold and store instructions for use by an instruction execution device. A computer-readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples (non-exhaustive list) of a computer-readable storage medium include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disc (DVD), a memory stick, a floppy disk, a mechanically encoded device, such as a punched card or raised structures in a groove having instructions stored thereon, and any suitable combination of the foregoing. The computer-readable storage medium used herein is not to be construed as a transitory signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated through a waveguide or other transmission medium (e.g., an optical pulse through an optical fiber cable), or an electrical signal transmitted through a wire.
[0234] The computer-readable program instructions described herein can be downloaded to various computing / processing devices from a computer-readable storage medium or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in each computing / processing device.
[0235] The computer program instructions for performing the operations of the embodiments of this specification may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state-setting data, or source code or object code written in any combination of one or more programming languages. The programming languages include object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as the "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider). In some embodiments, by using the state information of the computer-readable program instructions to customize an electronic circuit, such as a programmable logic circuit, a field-programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit can execute the computer-readable program instructions to implement various aspects of the embodiments of this specification.
[0236] Aspects of the embodiments of this specification are described herein with reference to the flowcharts and / or block diagrams of methods, apparatuses (devices), and computer program products according to the embodiments of this specification. It should be understood that each block of the flowcharts and / or block diagrams, and the combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.
[0237] These computer-readable program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus to produce a machine such that the instructions, when executed by the processor of the computer or other programmable data processing apparatus, create means for implementing the functions / acts specified in one or more boxes of the flowchart and / or block diagram. These computer-readable program instructions may also be stored in a computer-readable storage medium that causes a computer, a programmable data processing apparatus, and / or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises a manufacture, the instructions comprising aspects for implementing the functions / acts specified in one or more boxes of the flowchart and / or block diagram.
[0238] The computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device, such that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, whereby the instructions executed on the computer, other programmable data processing apparatus, or other device implement the functions / acts specified in one or more boxes of the flowchart and / or block diagram.
[0239] The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present specification. In this regard, each box in the flowchart or block diagram may represent a module, a segment of a program, or a portion of an instruction, the module, segment of a program, or portion of an instruction containing one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions noted in the boxes may occur out of the order noted in the figures. For example, two consecutive boxes may in fact be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each box of the block diagrams and / or flowcharts, and combinations of boxes in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or acts, or by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that implementation by hardware, implementation by software, and implementation by a combination of software and hardware are equivalent.
[0240] The embodiments of this specification have been described above. The above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations are obvious to those of ordinary skill in the art without departing from the scope of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, the practical application, or the improvement of the technology in the market, or to enable other ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for moving and avoiding obstacles of a virtual object, the method comprising: Acquire a first moving path and obstacles of the virtual object in the virtual scene; Determine a first section within the obstacle and a section endpoint of the first section in the first moving path; Constructing a collision sphere using the first reference line where the endpoint of the road segment is located as the diameter; Determine a boundary line where the obstacle intersects the collision sphere; The first moving path is updated to a second moving path according to the boundary line.
2. The method according to claim 1, wherein: The determining of a first section within the obstacle in the first moving path and a section endpoint of the first section includes: Grouping the first portion of curves indicated in the first moving path into a first group; converting the first moving path into a plurality of line segments; Extracting a first line segment in the first group from among the plurality of line segments; Setting the first line segments to form a first curve as a first section of the first moving path within the obstacle; Determine a segment endpoint of the first segment.
3. The method according to claim 1, wherein: The segment endpoints include a first segment endpoint and a second segment endpoint, the distance from the first segment endpoint to the edge line of the obstacle is less than the distance from the second segment endpoint to the edge line of the obstacle, and the method further includes: According to the position information of the endpoint of the road segment, a first vector of the edge line of the obstacle is set from the endpoint of the first road segment; Setting an offset point along the first vector at a set distance from an endpoint of the first section; A line connecting the first road segment endpoint, the second road segment endpoint and the offset point is used as a first reference line.
4. The method according to claim 3, wherein: The updating of the first moving path to a second moving path according to the boundary line includes: Determine a coincidence line among the boundary lines that coincides with an edge line of the obstacle; Determine, on the coincidence line, a first dividing point at a first position of an end point of the first road section; Determine a first portion of the coincidence line according to the first segmentation point; The first moving path is updated to a second moving path according to the first part.
5. The method according to claim 4, wherein determining the first part of the coincidence line according to the first segmentation point comprises: Determine a first end point of the coincidence line and a first dividing line where the first dividing point is located, and determine a second end point of the coincidence line and a second dividing line where the first dividing point is located; Determine a first angle between the first dividing line and a set second reference line, and determine a second angle between the second dividing line and the second reference line; Determine a minimum angle between the first angle and the second angle; According to the minimum angle, a first portion of the coincidence line is determined.
6. The method according to claim 5, wherein: Determining the first part of the coincidence line according to the minimum angle includes: When the first angle is the minimum angle, determining a portion of the coincidence line having the first dividing point and the first endpoint as endpoints as a first portion; When the second angle is the minimum angle, a portion of the coincidence line having the second dividing point and the first endpoint as endpoints is determined as the first portion.
7. The method according to claim 4, wherein: The updating of the first moving path to a second moving path according to the first part includes: A second portion of the curve not indicated in the first moving path is combined with the first portion to obtain a second moving path.
8. A mobile obstacle avoidance device for a virtual object, wherein: include: An acquisition module, used to acquire a first moving path and obstacles of the virtual object in a virtual scene; A first determining module, configured to determine a first section within the obstacle in the first moving path and a section endpoint of the first section; A construction module, used to construct a collision sphere using the first reference line where the endpoint of the road segment is located as a diameter; A second determination module is used to determine the intersection line of the obstacle and the collision sphere; An updating module is used to update the first moving path to a second moving path according to the boundary line.
9. An electronic device, wherein: The method comprises a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the method steps according to any one of claims 1 to 7 under the control of the computer program.
10. A computer-readable storage medium, the computer-readable storage medium comprising a stored computer program, wherein: When the computer program is executed, the method steps of any one of claims 1 to 7 are performed.