Method, device, terminal and storage medium for determining the nearest waypoint
By obtaining the regional distance between the preset area and the target position in the game, determining the nearest area and finding waypoints in the area, the problem of large amount of calculation in the existing technology is solved and the real-time performance in the game is improved.
Patent Information
- Application Number
- CN202111138597.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-27
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2041-09-27
AI Technical Summary
In the existing technology, finding the nearest waypoint in the game requires a large amount of calculation, which makes it difficult to meet the real-time requirements of the game.
By obtaining the regional distance between the preset area in the target area set and the target location, determine the preset area closest to the target location, and find the nearest waypoint in the area, reducing the waypoint search space and amount of calculation.
The data calculation amount of the nearest waypoint is reduced, the search time is shortened, and the real-time performance of determining the nearest waypoint in the game is improved.
Smart Images

Figure CN113842641B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of game path finding, and in particular to a method, device, terminal and computer-readable storage medium for determining a nearest waypoint. Background Art
[0002] In games, a pathfinding function is provided to help players find the shortest path to a non-player character (NPC). However, the pathfinding algorithm needs to rely on the nearest waypoint to the current location of the game user and the nearest waypoint to the target location in order to accurately calculate the shortest path.
[0003] However, the current position or target position of the game user is not necessarily on a waypoint. Therefore, before calculating the shortest path, it is necessary to first determine the nearest waypoint to the current position of the game user and the nearest waypoint to the target position.
[0004] In the prior art, all waypoints in the game map are traversed, the distance between the current position and each waypoint is calculated, and the waypoint with the smallest distance is taken as the closest waypoint to the current position (the calculation method of the closest waypoint to the target position is similar). However, there are a large number of waypoints in the game map, and the method of calculating the distance between the current position and each waypoint to search for the closest waypoint to the current position requires a large amount of data calculation, so it takes a long time to search for the closest waypoint, which is difficult to meet the real-time determination requirements of the closest waypoint in the game. Summary of the invention
[0005] The embodiments of the present invention provide a method, device, terminal and computer-readable storage medium for determining the nearest waypoint, which can reduce the amount of data calculation for searching the nearest waypoint, so as to shorten the time spent on searching the nearest waypoint, thereby improving the real-time performance of determining the nearest waypoint in a game.
[0006] An embodiment of the present invention provides a method for determining a nearest waypoint, including:
[0007] In a first aspect, an embodiment of the present application provides a method for determining a nearest waypoint, including:
[0008] Obtaining the target position of the virtual game character in the target game scene;
[0009] Acquire the position information of each preset area in the target area set of the target game scene, wherein the target area set includes a plurality of preset areas;
[0010] Based on the location of the target and the location information of each preset area, obtaining the area distance between each preset area and the location of the target;
[0011] From the target area set, obtain a first target area having the smallest area distance to the target location;
[0012] Based on the waypoints in the first target area and the location of the target, a target nearest waypoint at the location of the target is determined.
[0013] In a second aspect, an embodiment of the present application further provides a device for determining a nearest waypoint, including:
[0014] A first acquisition unit, used to acquire a target position of a virtual game character in a target game scene;
[0015] A second acquisition unit is used to acquire the position information of each preset area in the target area set of the target game scene, wherein the target area set includes a plurality of preset areas;
[0016] A third acquisition unit, configured to acquire a regional distance between each preset area and the location of the target based on the location of the target and the location information of each preset area;
[0017] A fourth acquisition unit, configured to acquire, from the target area set, a first target area having the shortest area distance to the target location;
[0018] A determination unit is used to determine the nearest waypoint of the target location based on each waypoint in the first target area and the target location.
[0019] In some embodiments, the determining unit is specifically configured to:
[0020] Acquire, from each waypoint in the first target area, a preliminary target waypoint that is closest to the location of the target;
[0021] Obtaining a distance between the preliminary target waypoint and the target waypoint at the target location;
[0022] From the target area set, obtain a second target area having the second smallest area distance to the target location;
[0023] Acquire a target area distance between the second target area and the target location;
[0024] When the target waypoint distance is less than the target area distance, the preliminary target waypoint is used as the target closest waypoint.
[0025] In some embodiments, the determining unit is specifically configured to:
[0026] When the target waypoint distance is greater than or equal to the target area distance, acquiring an intermediate target waypoint closest to the target location from each waypoint in the second target area;
[0027] When the distance between the intermediate target waypoint and the target position is less than the target waypoint distance, filtering the first target area from the target area set to obtain a filtered area set;
[0028] Using the filtered area set as the target area set;
[0029] From the target area set, obtaining a first target area with the smallest area distance and a second target area with the second smallest area distance;
[0030] Acquire a distance between a preliminary target waypoint and a target waypoint at a location of the target, wherein the preliminary target waypoint is a waypoint that is closest to the location of the target among all the waypoints in the first target area;
[0031] Acquire a target area distance between the second target area and the target location;
[0032] When the target waypoint distance is less than the target area distance, the preliminary target waypoint is used as the target closest waypoint.
[0033] In some embodiments, the first target area includes a first area and a second area, the area distance between the first area and the location of the target is equal to the area distance between the second area and the location of the target, the preliminary target waypoint includes a first waypoint and a second waypoint, and the determining unit is specifically used to:
[0034] Acquire, from each waypoint in the first area, a first waypoint that is closest to the location of the target;
[0035] Acquire, from the waypoints in the second area, a second waypoint that is closest to the location of the target;
[0036] Obtaining a first waypoint distance between the first waypoint and the location of the target;
[0037] Obtaining a second waypoint distance between the second waypoint and the location of the target;
[0038] The minimum value between the first waypoint distance and the second waypoint distance is obtained as the target waypoint distance.
[0039] In some embodiments, the location information of each preset area is the diagonal corner point coordinates of the minimum enclosing rectangle of all waypoints in each preset area, and the diagonal corner point coordinates include the third coordinates of the diagonal corner points of the minimum enclosing rectangle in the first coordinate axis direction of the target game scene and the fourth coordinates in the second coordinate axis direction of the target game scene, and the third acquisition unit is specifically used to:
[0040] Acquire a first coordinate of the position of the target in the direction of the first coordinate axis and a second coordinate in the direction of the second coordinate axis;
[0041] When the first coordinate is within the interval of the third coordinate, obtaining a difference between the second coordinate and the fourth coordinate as a regional distance between each preset area and the location of the target;
[0042] In some embodiments, the third acquisition unit is specifically used to:
[0043] When the second coordinate is within the interval of the fourth coordinate, a difference between the first coordinate and the third coordinate is obtained as a regional distance between each preset area and the location of the target.
[0044] In some embodiments, the device for determining the nearest waypoint further includes a preprocessing unit, and before obtaining the area distance between each preset area and the location of the target based on the location of the target and the location information of each preset area, the preprocessing unit is specifically used to:
[0045] Determine all waypoints in each of the preset areas;
[0046] Determine the minimum enclosing rectangle of all the waypoints;
[0047] Get the coordinates of the diagonal corner points of the minimum enclosing rectangle.
[0048] In some embodiments, when the first coordinate is within the interval of the third coordinate, before obtaining the difference between the second coordinate and the fourth coordinate as the area distance between each preset area and the location of the target, the third obtaining unit is specifically used to:
[0049] Detecting whether the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area;
[0050] When the target location is outside the minimum enclosing rectangle of all waypoints in each preset area and the first coordinate is within the interval of the third coordinate, the difference between the second coordinate and the fourth coordinate is obtained as the area distance between each preset area and the target location.
[0051] In some embodiments, the location information of each preset area is the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in each preset area, and the third acquisition unit is specifically used to:
[0052] Detecting whether the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area;
[0053] When the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area, it is determined that the area distance between each preset area and the location of the target is 0.
[0054] In some embodiments, the device for determining the nearest waypoint further includes a pathfinding unit, the target location includes the starting location and the end location of the virtual game character, the target nearest waypoint includes the nearest waypoint of the starting location and the nearest waypoint of the end location, and the pathfinding unit is specifically used to:
[0055] Path finding is performed based on the nearest waypoint at the location of the starting point and the nearest waypoint at the location of the end point.
[0056] In a third aspect, an embodiment of the present application further provides a terminal, comprising a memory storing a plurality of instructions; the processor loads instructions from the memory to execute the steps in any one of the methods for determining the nearest waypoint provided in the embodiments of the present application.
[0057] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a plurality of instructions, wherein the instructions are suitable for a processor to load to execute the steps in any of the methods for determining the nearest waypoint provided in the embodiments of the present application.
[0058] The embodiment of the present application obtains the first target area with the smallest area distance from the target location from the target area set; determines the target nearest waypoint at the target location based on each waypoint in the first target area and the target location; it aims to first find out the area where the target nearest waypoint at the target location falls from a plurality of pre-divided preset areas; and then find out the target nearest waypoint at the target location from each waypoint in the area where the target nearest waypoint at the target location falls by calculating the distance between the target location and each waypoint. On the one hand, although the distance between the target location and each waypoint is still required, since only each waypoint in the area where the target nearest waypoint at the target location falls needs to be calculated for searching, the waypoint search space when searching for the target nearest waypoint is greatly reduced, the amount of data calculation for searching the nearest waypoint is reduced, and the time consumption for searching the nearest waypoint is shortened, thereby improving the search speed of the target nearest waypoint. On the other hand, although it is necessary to first find the area where the target's nearest waypoint falls from multiple preset areas, the number of preset areas in the target game scene is far less than the number of the target game scene waypoints. Therefore, the amount of data calculation for searching the target's nearest waypoint can be reduced to a certain extent, and the time spent searching for the nearest waypoint can be shortened, thereby improving the search speed of the target's nearest waypoint. It can be seen that the embodiment of the present application can reduce the amount of data calculation for searching the nearest waypoint, shorten the time spent searching for the nearest waypoint, and thus improve the real-time performance of determining the nearest waypoint in the game. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0060] Figure 1 This is a schematic diagram of an embodiment of a method for determining the nearest waypoint provided in an embodiment of the present application;
[0061] Figure 2 This is a schematic diagram for explaining the regional division of a target game scene in an embodiment of the present application;
[0062] Figure 3 is a schematic diagram for explaining the location information of each preset area provided in the embodiment of the present application;
[0063] Figure 4 for Figure 3 The schematic diagram of the minimum enclosing rectangle of area 1 and all waypoints in area 1 is shown;
[0064] Figure 5is a schematic diagram of a scene coordinate system of a target game scene provided in an embodiment of the present application;
[0065] Figure 6 is a schematic diagram for explaining a process of determining the nearest waypoint of a target provided in an embodiment of the present application;
[0066] Figure 7 is another schematic diagram for explaining the process of determining the nearest waypoint of a target provided in an embodiment of the present application;
[0067] Figure 8 is a schematic diagram for explaining determining the distance to a target waypoint provided in an embodiment of the present application;
[0068] Fig. 9 is a schematic diagram of the structure of a device for determining the nearest waypoint provided in an embodiment of the present application;
[0069] Fig.10 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0071] Embodiments of the present invention provide a method, device, terminal and computer-readable storage medium for determining a nearest waypoint.
[0072] The device for determining the nearest waypoint may be integrated in an electronic device, which may be a terminal, a server, or the like. The terminal may be a mobile phone, a tablet computer, a smart Bluetooth device, a notebook computer, or a personal computer (PC), etc. The server may be a single server or a server cluster consisting of multiple servers.
[0073] In some embodiments, the device for determining the closest waypoint may also be integrated into multiple electronic devices. For example, the device for determining the closest waypoint may be integrated into multiple servers, and the method for determining the closest waypoint of the present invention may be implemented by multiple servers.
[0074] For example, in some embodiments, the device for determining the nearest waypoint can be integrated into a terminal and a server cluster to realize cloud gaming; wherein the server can determine the nearest waypoint using the nearest waypoint determination method provided by the present solution, thereby reducing the amount of data calculation required by the terminal to search for the nearest waypoint, thereby shortening the time required to search for the nearest waypoint, and thereby improving the real-time performance of determining the nearest waypoint in the game.
[0075] In some embodiments, the server may also be implemented in the form of a terminal, for example, a personal computer may be configured as a server to integrate the nearest waypoint determination device.
[0076] For example, the electronic device may be a mobile terminal, which may obtain the target position of a virtual game character in a target game scene through a network; obtain the position information of each preset area in a target area set of the target game scene, wherein the target area set includes a plurality of preset areas; based on the target position and the position information of each preset area, obtain the area distance between each preset area and the target position; from the target area set, obtain the first target area having the smallest area distance to the target position; and based on each waypoint in the first target area and the target position, determine the target nearest waypoint to the target position.
[0077] It should be noted that the serial numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0078] Reference Figure 1 , Figure 1 1 is a flow chart of a method for determining the nearest waypoint provided in an embodiment of the present application. It should be noted that although a logical order is shown in the flow chart, in some cases, the steps shown or described may be performed in a different order than that shown here. In this embodiment, the method for determining the nearest waypoint includes steps 101 to 105, wherein:
[0079] 101. Obtain a target position of a virtual game character in a target game scene.
[0080] The target game scene is a virtual scene that simulates the real world, such as a room, grassland, etc.
[0081] A virtual game character is a character that can interact with other objects in a target game scene, such as a character controlled by a game player.
[0082] The target location is the location of the virtual game character, and the target location can be set according to specific business scenarios. For example, when determining the nearest waypoint of the current location of the virtual game character, the target location specifically refers to the current location of the virtual game character. For another example, when performing pathfinding, the target location specifically refers to the starting location or the end location of the virtual game character.
[0083] 102. Obtain location information of each preset area in the target area set of the target game scene.
[0084] The target area set includes multiple preset areas.
[0085] Exemplarily, before step 102, the method further includes: dividing the target game scene into regions to obtain a plurality of preset regions of the target game scene. Figure 2 As shown, the target game scene is as follows Figure 2 As shown in the middle left, after dividing the target game scene into regions, we get Figure 2 Multiple preset areas shown on the center right.
[0086] In step 102, there are multiple ways to obtain the location information of each preset area in the target area set of the target game scene, illustratively including:
[0087] (1) Calculated in real time. In some embodiments, the location information of each preset area refers to the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in each preset area; wherein the minimum enclosing rectangle refers to the minimum enclosing rectangle of all waypoints in the preset area. The diagonal corner point coordinates are the coordinates of at least one diagonal corner point of the minimum enclosing rectangle of all waypoints in the preset area; the diagonal corner point coordinates include the third coordinates of the diagonal corner points of the minimum enclosing rectangle in the direction of the first coordinate axis of the target game scene and the fourth coordinates in the direction of the second coordinate axis of the target game scene. Figure 3 As shown, Figure 3 is a schematic diagram for explaining the location information of each preset area provided in the embodiment of the present application. At this time, step 102 may specifically include: determining all waypoints of each preset area; determining the minimum enclosing rectangle of all waypoints; and obtaining the coordinates of the diagonal corner points of the minimum enclosing rectangle.
[0088] Among them, "determining the minimum enclosing rectangle of all waypoints in each preset area" can be specifically determined according to the coordinates of all waypoints in each preset area, with reference to some existing minimum enclosing rectangle determination methods, which will not be repeated here for simplicity.
[0089] For example, in some embodiments, the diagonal point coordinates of the minimum enclosing rectangle are the upper left corner coordinates and the lower right corner coordinates of the minimum enclosing rectangle, that is, the location information of each preset area refers to the upper left corner coordinates and the lower right corner coordinates of the minimum enclosing rectangle of all waypoints in each preset area. In this case, "obtaining the diagonal point coordinates of the minimum enclosing rectangle" may specifically include: obtaining the upper left corner coordinates and the lower right corner coordinates of the minimum enclosing rectangle. For example, Figure 3 In the multiple preset areas (areas 1, 2, 3, and 4) divided into the target game scene, the waypoints in area 1 are as follows: Figure 3 As shown by the black dot in the middle, the minimum enclosing rectangle of all waypoints in area 1 is as follows Figure 3 The location information of region 1 is the coordinates of the upper left corner (x1, y1) and the lower right corner (x4, y4) of the smallest enclosing rectangle, as shown in the dashed rectangle. Figure 4 As shown. Among them, Figure 4 for Figure 3 The minimum enclosing rectangle of area 1 and a schematic diagram of all waypoints in area 1 are shown.
[0090] In other embodiments, the diagonal point coordinates of the minimum enclosing rectangle are the lower left corner coordinates and the upper right corner coordinates of the minimum enclosing rectangle, that is, the location information of each preset area refers to the lower left corner coordinates and the upper right corner coordinates of the minimum enclosing rectangle of all waypoints in each preset area. In this case, "obtaining the diagonal point coordinates of the minimum enclosing rectangle" may specifically include: obtaining the lower left corner coordinates and the upper right corner coordinates of the minimum enclosing rectangle. For example, Figure 3 In the multiple preset areas (areas 1, 2, 3, and 4) divided into the target game scene, the waypoints in area 1 are as follows: Figure 3 As shown by the black dot in the middle, the minimum enclosing rectangle of all waypoints in area 1 is as follows Figure 3 The location information of area 1 is the coordinates of the lower left corner (x3, y3) and the upper right corner (x2, y2) of the minimum enclosing rectangle, as shown in the dashed rectangle. Figure 4 shown.
[0091] (2) Directly read from a preset database. The preset database stores the location information of each preset area in the target area set of the target game scene, and the location information is directly obtained from the preset database. Specifically, before step 102, the location information of each preset area in the target area set of the target game scene can be obtained by calculating the location information of each preset area in the target area set of the target game scene in real time in the above (1), first determine the location information of each preset area in the target area set of the target game scene, and save the location information of each preset area in the target area set of the target game scene to a preset database. In step 102, the location information of each preset area in the target area set of the target game scene can be directly read from the preset database.
[0092] For ease of understanding, in the following text, it is explained by taking the example that the location information of each preset area refers to the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in each preset area.
[0093] 103. Based on the location of the target and the location information of each preset area, obtain an area distance between each preset area and the location of the target.
[0094] The regional distance refers to the distance between each preset area and the target location. In different business scenarios, the specific definition of regional distance is different. For example, the regional distance can be the shortest distance between the minimum enclosing rectangle of all waypoints in each preset area and the target location, or the distance between the center point of each preset area and the target location, or the distance between the center point of the minimum enclosing rectangle of all waypoints in each preset area and the target location. The following examples are given to illustrate:
[0095] 1. The area distance is the shortest distance between the smallest enclosing rectangle of all waypoints in each preset area and the location of the target. At this time, step 103 may specifically include the following steps 1031A to 1033A.
[0096] For easier understanding, please refer to Figure 5 , Figure 5 It is a schematic diagram of the scene coordinate system of the target game scene provided in the embodiment of the present application. Correspondingly, the position information of each preset area in step 102 can specifically be the diagonal corner point coordinates of the minimum enclosing rectangle of all road points in each preset area. Among them, the diagonal corner point coordinates are the coordinates of at least one diagonal corner point of the minimum enclosing rectangle of all road points in the preset area. The diagonal corner point coordinates include the third coordinates of the diagonal corner points of the minimum enclosing rectangle in the first coordinate axis direction of the target game scene and the fourth coordinates in the second coordinate axis direction of the target game scene.
[0097] 1031A. Obtain a first coordinate of the target position in the direction of a first coordinate axis of the target game scene, and a second coordinate in the direction of a second coordinate axis of the target game scene.
[0098] Generally speaking, every point in the target game scene can be represented by the scene coordinate system of the target game scene, where the scene coordinate system can be two-dimensional or three-dimensional. In the embodiment of the present application, the scene coordinate system of the target game scene is a two-dimensional coordinate system as an example.
[0099] The first coordinate axis refers to one of the coordinate axes in the scene coordinate system of the target game scene, and the second coordinate axis refers to another coordinate axis in the scene coordinate system of the target game scene that is different from the first coordinate axis.
[0100] The first coordinate refers to the coordinate value of the target position in the direction of the first coordinate axis of the target game scene. The second coordinate refers to the coordinate value of the target position in the direction of the second coordinate axis of the target game scene.
[0101] For example, Figure 5 As shown, assuming that the first coordinate axis is the x-axis, the second coordinate axis is the y-axis, and the target position is O (x0, y0), it can be determined that the first coordinate of the target position O in the direction of the first coordinate axis (i.e., the x-axis) of the target game scene is "x0", and the second coordinate of the target position O in the direction of the second coordinate axis (i.e., the y-axis) of the target game scene is "y0".
[0102] 1032A. When the first coordinate is in the third coordinate interval, obtain the difference between the second coordinate and the fourth coordinate as the area distance between each preset area and the location of the target.
[0103] The third coordinate refers to the coordinate value of the diagonal corner point of the minimum enclosing rectangle in the direction of the first coordinate axis of the target game scene. Since the diagonal corner point coordinates refer to the coordinates of at least one diagonal corner point of the minimum enclosing rectangle of all road points in the preset area, the third coordinate includes the coordinate values of at least two corner points of the minimum enclosing rectangle in the direction of the first coordinate axis of the target game scene. Figure 5 As shown, the third coordinate is the coordinate values x1 and x4 of the diagonal corner points (such as the upper left corner and the lower right corner) of the minimum enclosing rectangle in the direction of the first coordinate axis (such as the x-axis) of the target game scene.
[0104] The fourth coordinate refers to the coordinate value of the diagonal corner point of the minimum enclosing rectangle in the direction of the second coordinate axis of the target game scene.
[0105] The first coordinate is within the interval of the third coordinate means that the first coordinate is greater than or equal to the minimum value of the third coordinate and less than or equal to the maximum value of the third coordinate. Figure 5 As shown, the third coordinate is the coordinate value x1, x4 of the diagonal corner point (such as the upper left corner and the lower right corner) of the minimum enclosing rectangle in the direction of the first coordinate axis (such as the x-axis) of the target game scene, and the first coordinate is the coordinate value x0 of the target position in the direction of the first coordinate axis (i.e., the x-axis) of the target game scene; wherein, x1<x4. If x1≤x0≤x4, it is determined that the first coordinate (i.e., x0) is within the interval of the third coordinate (i.e., x1~x4). If x1>x0, or x0>x4, it is determined that the first coordinate (i.e., x0) is not within the interval of the third coordinate (i.e., x1~x4).
[0106] Exemplarily, in step 1032A, "obtaining the difference between the second coordinate and the fourth coordinate as the regional distance between each preset area and the target location" may specifically include: obtaining the minimum value of the difference between the second coordinate and the fourth coordinate as the regional distance between each preset area and the target location.
[0107] The following uses the case where the diagonal corner point coordinates are the upper left corner coordinates and lower right corner coordinates of the minimum enclosing rectangle and the case where the diagonal corner point coordinates are the lower left corner coordinates and upper right corner coordinates of the minimum enclosing rectangle as examples to illustrate how to determine the area distance between each preset area and the target location in steps 1031A to 1032A.
[0108] (1) The coordinates of the diagonal corner points are the coordinates of the upper left corner and the lower right corner of the minimum enclosing rectangle. Figure 5 As shown, the third coordinate specifically refers to the coordinate value (i.e., x1) of the upper left corner of the minimum enclosing rectangle in the direction of the first coordinate axis (e.g., x-axis) of the target game scene, and the coordinate value (i.e., x4) of the lower right corner in the direction of the first coordinate axis (i.e., x-axis) of the target game scene. After obtaining the first coordinate (i.e., x0) of the target position in the direction of the first coordinate axis (i.e., x-axis) of the target game scene, and the second coordinate (i.e., y0) in the direction of the second coordinate axis (i.e., y-axis) of the target game scene in step 1031A, when the first coordinate is in the third coordinate interval (i.e., when x1≤x0≤x4), in step 1032A, the minimum value (i.e., |y0-y4|) of the difference between the second coordinate and the fourth coordinate (i.e., |y0-y1|, |y0-y4|) is obtained as the area distance between each preset area (i.e., area 1) and the target position.
[0109] (2) The diagonal corner point coordinates are the lower left corner coordinates and upper right corner coordinates of the minimum enclosing rectangle of all waypoints in the preset area. Figure 5 As shown, the third coordinate specifically refers to the coordinate value (i.e., x3) of the lower left corner of the minimum enclosing rectangle in the direction of the first coordinate axis (e.g., x-axis) of the target game scene, and the coordinate value (i.e., x2) of the upper right corner in the direction of the first coordinate axis (i.e., x-axis) of the target game scene. After obtaining the first coordinate (i.e., x0) of the target position in the direction of the first coordinate axis (i.e., x-axis) of the target game scene, and the second coordinate (i.e., y0) in the direction of the second coordinate axis (i.e., y-axis) of the target game scene in step 1031A, when the first coordinate is in the third coordinate interval (i.e., when x3≤x0≤x2), in step 1032A, the minimum value (i.e., |y0-y3|) of the difference between the second coordinate and the fourth coordinate (i.e., |y0-y3|, |y0-y2|) is obtained as the area distance between each preset area (i.e., area 1) and the target position.
[0110] From the above content, it can be seen that when the first coordinate is within the interval of the third coordinate, by obtaining the difference between the second coordinate and the fourth coordinate as the regional distance between each preset area and the target location, on the one hand, since there is no need to calculate each point of the minimum enclosing rectangle and the target location, the shortest distance between the minimum enclosing rectangle and the target location can be calculated, thereby shortening the calculation time of the regional distance between the preset area and the target location, thereby improving the speed of determining the nearest waypoint. On the other hand, since the regional distance between the preset area and the target location can be obtained by subtracting the second coordinate from the fourth coordinate (such as y0-y), compared with the distance calculation formula between two points (such as ) has a smaller amount of calculation, therefore, it can also reduce the amount of calculation of the regional distance between the preset area and the target location to a certain extent, shorten the calculation time of the regional distance between the preset area and the target location, and thus improve the speed of determining the nearest waypoint.
[0111] 1033A. When the second coordinate is within the interval of the fourth coordinate, obtain the difference between the first coordinate and the third coordinate as the area distance between each preset area and the location of the target.
[0112] The second coordinate is within the interval of the fourth coordinate means that the second coordinate is greater than or equal to the minimum value of the fourth coordinate and less than or equal to the maximum value of the fourth coordinate. Figure 5 As shown, the fourth coordinate is the coordinate value y1, y4 of the diagonal corner point (such as the upper left corner and the lower right corner) of the minimum enclosing rectangle in the direction of the second coordinate axis (such as the y axis) of the target game scene, and the second coordinate is the coordinate value y0 of the target position in the direction of the second coordinate axis (i.e., the y axis) of the target game scene; wherein, y1<y4. If y1≤y0≤y4, it is determined that the second coordinate (i.e., y0) is within the interval of the fourth coordinate (i.e., y1~y4). If y1>y0, or y0>y4, it is determined that the second coordinate (i.e., y0) is not within the interval of the fourth coordinate (i.e., y1~y4).
[0113] Exemplarily, in step 1033A, "obtaining the difference between the first coordinate and the third coordinate as the regional distance between each preset area and the target location" may specifically include: obtaining the minimum value of the difference between the first coordinate and the third coordinate as the regional distance between each preset area and the target location.
[0114] The following uses the case where the diagonal corner point coordinates are the upper left corner coordinates and lower right corner coordinates of the minimum enclosing rectangle and the diagonal corner point coordinates are the lower left corner coordinates and upper right corner coordinates of the minimum enclosing rectangle as examples to illustrate how to determine the area distance between each preset area and the target location in steps 1031A to 1033A.
[0115] (1) The coordinates of the diagonal corner points are the coordinates of the upper left corner and the lower right corner of the minimum enclosing rectangle. Figure 5 As shown, the fourth coordinate specifically refers to the coordinate value (i.e., y1) of the upper left corner of the minimum enclosing rectangle in the direction of the second coordinate axis (e.g., y axis) of the target game scene, and the coordinate value (i.e., y4) of the lower right corner in the direction of the second coordinate axis (i.e., y axis) of the target game scene. After obtaining the first coordinate (i.e., x0) of the target position in the direction of the first coordinate axis (i.e., x axis) of the target game scene, and the second coordinate (i.e., y0) in the direction of the second coordinate axis (i.e., y axis) of the target game scene in step 1031A, when the second coordinate is in the fourth coordinate interval (i.e., y1≤y0≤y4), in step 1033A, the minimum value (i.e., |x0-x4|) of the difference between the first coordinate and the third coordinate (i.e., |x0-x1|, |x0-x4|) is obtained as the area distance between each preset area (i.e., area 1) and the target position.
[0116] (2) The diagonal corner point coordinates are the lower left corner coordinates and upper right corner coordinates of the minimum enclosing rectangle of all waypoints in the preset area. Figure 5 As shown, the fourth coordinate specifically refers to the coordinate value (i.e., y3) of the lower left corner of the minimum enclosing rectangle in the direction of the second coordinate axis (e.g., y axis) of the target game scene, and the coordinate value (i.e., y2) of the upper right corner in the direction of the second coordinate axis (i.e., y axis) of the target game scene. After obtaining the first coordinate (i.e., x0) of the target position in the direction of the first coordinate axis (i.e., x axis) of the target game scene, and the second coordinate (i.e., y0) in the direction of the second coordinate axis (i.e., y axis) of the target game scene in step 1031A, when the second coordinate is in the fourth coordinate interval (i.e., y3≤y0≤y2), in step 1033A, the minimum value (i.e., |x0-x3|) of the difference between the first coordinate and the third coordinate (i.e., |x0-x3|, |x0-x2|) is obtained as the area distance between each preset area (i.e., area 1) and the target position.
[0117] From the above content, it can be seen that when the second coordinate is within the interval of the fourth coordinate, by obtaining the difference between the first coordinate and the third coordinate as the regional distance between each preset area and the target location, on the one hand, since there is no need to calculate each point of the minimum enclosing rectangle and the target location, the shortest distance between the minimum enclosing rectangle and the target location can be calculated, thereby shortening the calculation time of the regional distance between the preset area and the target location, thereby improving the speed of determining the nearest waypoint. On the other hand, since the regional distance between the preset area and the target location can be obtained by subtracting the first coordinate from the third coordinate (such as x0-x), compared with the distance calculation formula between two points (such as ) has a smaller amount of calculation, therefore, it can also reduce the amount of calculation of the regional distance between the preset area and the target location to a certain extent, shorten the calculation time of the regional distance between the preset area and the target location, and thus improve the speed of determining the nearest waypoint.
[0118] Furthermore, in order to improve the accuracy of determining the area with the smallest regional distance from the target location, so as to improve the accuracy of determining the subsequent nearest waypoint, if the target location falls within the minimum enclosing rectangle of the preset area, the regional distance between the preset area and the target location is determined to be 0. At this time, in step 1032A or 1033A, the difference between the second coordinate and the fourth coordinate is used as the regional distance between the preset area and the target location only when the target location is outside the minimum enclosing rectangle of all waypoints in the preset area.
[0119] That is, in some embodiments, before step 1032A, it also includes: detecting whether the position of the target is within the minimum enclosing rectangle of all waypoints in each preset area. When the position of the target is within the minimum enclosing rectangle of all waypoints in each preset area, determining that the regional distance between each preset area and the position of the target is 0. Step 1032A specifically includes: when the position of the target is outside the minimum enclosing rectangle of all waypoints in each preset area, and the first coordinate is within the interval of the third coordinate, obtaining the difference between the second coordinate and the fourth coordinate as the regional distance between each preset area and the position of the target.
[0120] In some embodiments, before step 1033A, it also includes: detecting whether the target location is within the minimum enclosing rectangle of all waypoints in each preset area. When the target location is within the minimum enclosing rectangle of all waypoints in each preset area, determining that the area distance between each preset area and the target location is 0. Step 1033A specifically includes: when the target location is outside the minimum enclosing rectangle of all waypoints in each preset area, and the second coordinate is within the interval of the fourth coordinate, obtaining the difference between the first coordinate and the third coordinate as the area distance between each preset area and the target location.
[0121] In some other embodiments, it is also possible to detect whether the target position is within the minimum enclosing rectangle of all waypoints in each preset area before step 1031A. When the target position is within the minimum enclosing rectangle of all waypoints in each preset area, the regional distance between each preset area and the target position is determined to be 0. When the target position is outside the minimum enclosing rectangle of all waypoints in each preset area, steps 1031A to 1033A are continued to be performed to determine the regional distance between each preset area and the target position. This avoids the invalid calculation process of performing steps 1031A to 1033A when "the target position is within the minimum enclosing rectangle of all waypoints in each preset area", thereby reducing the amount of computational data when calculating the regional distance between each preset area and the target position, and improving the speed of determining the nearest waypoint.
[0122] It can be seen that by first detecting whether the target location is within the minimum enclosing rectangle of all waypoints in each preset area, and then selecting the regional distance calculation method corresponding to step 1032A or 1033A to calculate the regional distance between each preset area and the target location, on the one hand, the amount of computational data when calculating the regional distance between each preset area and the target location can be reduced, thereby improving the speed of determining the nearest waypoint; on the other hand, the accuracy of determining the area with the smallest regional distance to the target location can be improved, thereby improving the accuracy of determining the subsequent nearest waypoint to a certain extent.
[0123] Second, the area distance is the distance between the center point of each preset area and the location of the target. At this time, step 103 may specifically include the following steps 1031B to 1033B:
[0124] 1031B. Based on the position information of each preset area, obtain the coordinates of the center point of each preset area.
[0125] 1032B. Obtain the coordinates of the target location.
[0126] 1033B. Based on the coordinates of the center point of each preset area and the coordinates of the target location, calculate the distance between the center point of each preset area and the target location as the area distance between each preset area and the target location.
[0127] 104. Acquire, from the target area set, a first target area having the shortest area distance from the target location.
[0128] The first target area refers to a preset area in the target area set, which has the shortest distance from the target location.
[0129] For example, after determining the area distance between each preset area in the target area set and the target location in step 103, the preset areas can be sorted in order from small to large according to the area distance between each preset area and the target location to obtain a sorted target area set. In step 104, the first-ranked preset area can be directly obtained from the sorted target area set as the first target area.
[0130] For example, the target area set includes multiple preset areas {area0, area1, area2, area3, ..., area n}, and the preset areas are sorted in order from small to large according to the area distance between each preset area and the target location, so that the sorted target area set is {area0, area1, area2, area3, ..., area n}. Then, from the sorted target area set {area0, area1, area2, area3, ..., area n}, the first-ranked preset area "area0" is obtained as the first target area.
[0131] 105. Determine a target closest waypoint to the target location based on each waypoint in the first target area and the target location.
[0132] Among them, waypoints refer to locations with specific meanings or goals in the target game scene, such as the locations of NPCs such as buildings, monsters, characters, plants, rivers, etc.; for example, the locations where a certain plot will be triggered when a virtual game character arrives.
[0133] The target nearest waypoint refers to the waypoint closest to the target position of the virtual game character.
[0134] In step 105, there are multiple ways to determine the nearest waypoint of the target at the target location, illustratively including:
[0135] (1) In some embodiments, a waypoint closest to the target location may be obtained from the waypoints in the first target area as the closest waypoint to the target.
[0136] (2) Furthermore, in some other embodiments, in order to improve the accuracy of determining the nearest waypoint of the target location, the preliminary target waypoint in the first target area that is closest to the target location and the second target area in the target area set that has the second smallest regional distance to the target location can be first determined, and then the waypoint distance between the preliminary target waypoint and the target location and the regional distance between the second target area and the target location are compared. When the regional distance refers to the shortest distance between the minimum enclosing rectangle of all waypoints in the preset area and the target location, since the distance between each waypoint in the second target area and the target location is greater than or equal to the regional distance between the second target area and the target location, when the waypoint distance between the preliminary target waypoint and the target location is less than the regional distance between the second target area and the target location, the preliminary target waypoint can be determined as the nearest waypoint of the target. Please refer to Figure 5 , Figure 6 and Figure 7 At this time, step 105 may specifically include the following steps 1051 to 1058:
[0137] 1051. Acquire, from each waypoint in the first target area, a preliminary target waypoint that is closest to the location of the target.
[0138] The preliminary target waypoint refers to the waypoint closest to the target location among the waypoints in the first target area.
[0139] Specifically, first, the distances between the target position (denoted as O) and each waypoint in the first target area (denoted as area_n) are calculated respectively; then, from each waypoint in the first target area, the waypoint closest to the target position is obtained as the preliminary target waypoint (denoted as A).
[0140] For example, Figure 5 As shown, the target position is O, the first target area includes waypoints A, B, C, D, E, F, and G, and the distances between the target position O and waypoints A, B, C, D, E, F, and G are 4m, 3m, 4m, 5m, 6m, 4.5m, and 5m respectively. It can be determined that the preliminary target waypoint closest to the target position O is waypoint A.
[0141] 1052. Obtain a distance between the preliminary target waypoint and the target waypoint at the target location.
[0142] The target waypoint distance (denoted as S1) refers to the distance between the initial target waypoint and the target location.
[0143] For example, the distance to the target waypoint can be determined based on the following formula (1) according to the coordinates of the preliminary target waypoint and the coordinates of the target location.
[0144]
[0145] In formula (1), S0 represents the distance to the target waypoint, (x0, y0) represents the coordinates of the target location, and (x, y) represents the coordinates of the preliminary target waypoint.
[0146] 1053. Acquire, from the target area set, a second target area having the second smallest distance to the target location.
[0147] The second target area (denoted as area_n+1) refers to a preset area in the target area set, which has the second smallest distance to the target location.
[0148] For example, after determining the area distance between each preset area in the target area set and the target location in step 103, the preset areas can be sorted in order from small to large according to the area distance between each preset area and the target location to obtain a sorted target area set. In step 1053, the second-ranked preset area can be directly obtained from the sorted target area set as the second target area.
[0149] For example, the target area set includes multiple preset areas {area0, area1, area2, area3, ..., area n}, and the preset areas are sorted in order from small to large according to the area distance between each preset area and the target location, and the sorted target area set is obtained as {area0, area1, area2, area3, ..., area n}. Then, from the sorted target area set {area0, area1, area2, area3, ..., area n}, the second-ranked preset area "area1" is obtained as the second target area.
[0150] 1054. Obtain a target area distance between the second target area and the target location.
[0151] The target area distance (denoted as S0) refers to the distance between the second target area and the target location.
[0152] In step 1054, there are also multiple ways to obtain the distance of the target area, illustratively including:
[0153] (1) Referring to the method of step 103 above, the area distance between the second target area and the position of the target is obtained in real time as the target area distance.
[0154] (2) After the above step 103 is executed, the regional distance between each preset area and the target location (including the regional distance between the second target area and the target location) can be determined. In this case, the regional distance between the second target area and the target location can be directly obtained from the regional distance between each preset area and the target location determined in the above step 103 as the target regional distance.
[0155] 1055. When the target waypoint distance is less than the target area distance, use the preliminary target waypoint as the target closest waypoint.
[0156] like Figure 7 As shown, illustratively, the target waypoint distance determined in step 1052 is compared with the target area distance determined in step 1054. Figure 7 The distance between each waypoint in area_n+1) and the target location is greater than or equal to the area distance between the second target area and the target location, and the target area distance refers to the first target area (such as Figure 7 The shortest distance between the minimum enclosing rectangle of all waypoints in the area area_n in the target location. Therefore, when the target waypoint distance (such as Figure 7 When the initial target waypoint (S1 in FIG. 7 ) is less than the target area distance (S0 in FIG. 7 ), it is proved that the initial target waypoint (A in FIG. 7 ) is the waypoint closest to the target location, and the initial target waypoint can be used as the target closest waypoint.
[0157] 1056. When the target waypoint distance is greater than or equal to the target area distance, obtain, from each waypoint in the second target area, an intermediate target waypoint that is closest to the location of the target.
[0158] The intermediate target waypoint (denoted as B) refers to the waypoint closest to the target location among the waypoints in the second target area. The method of obtaining the intermediate target waypoint in step 1056 is similar to the method of obtaining the preliminary target waypoint in step 1051, and can be referred to the description of step 1051, which will not be repeated here.
[0159] For example, Figure 6 and Figure 7 As shown, when the target waypoint distance (S1) is greater than or equal to the target area distance (S0), it is proved that the preliminary target waypoint (A in FIG. 7) is not necessarily the waypoint closest to the target location. It is necessary to further verify whether the target closest waypoint is within the second target area. Therefore, in step 1056, it is necessary to obtain the intermediate target waypoint closest to the target location from each waypoint in the second target area (area_n+1).
[0160] 1057. When the distance between the intermediate target waypoint and the target location is less than the target waypoint distance, the first target area is filtered out from the target area set to obtain a filtered area set. Alternatively, when the distance between the intermediate target waypoint and the target location is greater than or equal to the target waypoint distance, the second target area is filtered out from the target area set to obtain a filtered area set.
[0161] Specifically, Figure 6 and Figure 7 As shown, first obtain the distance between the intermediate target waypoint and the target position (recorded as S2). Then, compare the distance between the intermediate target waypoint and the target position (S2) with the target waypoint distance (S2).
[0162] When the distance (S2) between the intermediate target waypoint and the target position is less than the target waypoint distance (S1), it proves that the preliminary target waypoint (A in Figure 7) is not the waypoint closest to the target position, and the intermediate target waypoint (B in Figure 7) may be the waypoint closest to the target position; at this time, the first target area (area_n) can be filtered out from the target area set to obtain a filtered area set, so as to continue to find the area where the target nearest waypoint is located from the filtered area set, and then find the target nearest waypoint.
[0163] When the distance (S2) between the intermediate target waypoint and the target position is greater than or equal to the target waypoint distance (S1), it is proved that the preliminary target waypoint (A in Figure 7) may be the waypoint closest to the target position, but the intermediate target waypoint (B in Figure 7) is not the waypoint closest to the target position; at this time, the second target area (area_n+1) can be filtered out from the target area set to obtain a filtered area set, so as to continue to find the area where the target nearest waypoint is located from the filtered area set, and then find the target nearest waypoint.
[0164] 1058. Use the filtered area set as the target area set, and repeat step 104 and step 1051 to step 1057 as above until the nearest waypoint of the target location is determined.
[0165] It can be seen from the above steps 1051 to 1058 that the embodiment of the present application is to first find out the area where the target nearest waypoint of the target position falls from the pre-divided multiple preset areas; then find out the target nearest waypoint of the target position from each waypoint in the area where the target nearest waypoint of the target position falls by calculating the distance between the target position and each waypoint. On the one hand, although the distance between the target position and each waypoint is still required, since only the waypoints in the area where the target nearest waypoint of the target position falls need to be calculated for search, the waypoint search space when searching for the target nearest waypoint is greatly reduced, the amount of data calculation for searching the nearest waypoint is reduced, and the time consumption for searching the nearest waypoint is shortened, thereby improving the search speed of the target nearest waypoint. On the other hand, although it is necessary to first find out the area where the target nearest waypoint falls from multiple preset areas, the number of preset areas in the target game scene is far less than the number of waypoints in the target game scene. Therefore, the amount of data calculation for searching the target nearest waypoint can be reduced to a certain extent, and the time consumption for searching the nearest waypoint can be shortened, thereby improving the search speed of the target nearest waypoint. It can be seen that the embodiments of the present application can reduce the amount of data calculation for searching the nearest waypoint, so as to shorten the time spent searching the nearest waypoint, thereby improving the real-time performance of determining the nearest waypoint in the game.
[0166] like Figure 8 As shown, in some scenarios, when determining the preliminary target waypoint, the target location may be far away from the area of the two preset areas (such as Figure 8 In the case where area 2 and area 3 are equal, in order to more quickly determine the area where the nearest waypoint of the target falls, in the embodiment of the present application, when determining the preliminary target waypoint, the first waypoint in area 2 that is closest to the location of the target (such as Figure 8 A), and the second waypoint closest to the target in area 3 (such as Figure 8 The minimum value in B) is taken as the target waypoint distance.
[0167] At this time, the first target area includes the first area and the second area, the area distance between the first area and the target location is equal to the area distance between the second area and the target location, and the preliminary target waypoint includes the first waypoint and the second waypoint. Step 1051 may specifically include the following steps A1 to A2:
[0168] A1. From each waypoint in the first area, obtain a first waypoint that is closest to the location of the target.
[0169] The first waypoint refers to a waypoint that is closest to the location of the target among the waypoints in the first area.
[0170] For example, Figure 8As shown, the first area is area 2, and the first waypoint "A" closest to the target location can be obtained from area 2.
[0171] A2. Acquire, from the waypoints in the second area, a second waypoint that is closest to the location of the target.
[0172] The second waypoint refers to a waypoint that is closest to the location of the target among the waypoints in the second area.
[0173] For example, Figure 8 As shown, the second area is area 3, and the second waypoint "B" closest to the target location can be obtained from area 3.
[0174] Specifically, the way of obtaining the first waypoint in step A1 and the way of obtaining the second waypoint in step A2 are similar to the way of obtaining the preliminary target waypoint in the above step 1051, and the description of the above step 1051 may be referred to, which will not be repeated here.
[0175] Step 1052 may specifically include the following steps B1 to B3:
[0176] B1. Obtain a first waypoint distance between the first waypoint and the location of the target.
[0177] The first waypoint distance refers to the distance between the first waypoint and the target location.
[0178] For example, Figure 8 As shown, the first waypoint distance is the distance S2 between the first waypoint A and the target position O.
[0179] B2. Obtain a second waypoint distance between the second waypoint and the target location.
[0180] The second waypoint distance refers to the distance between the second waypoint and the target location.
[0181] For example, Figure 8 As shown, the second waypoint distance is the distance S3 between the second waypoint B and the target position O.
[0182] Specifically, the way in which the first waypoint distance is obtained in step B1 and the way in which the second waypoint distance is obtained in step B2 are similar to the way in which the target waypoint distance is obtained in the above step 1052. The description of the above step 1052 may be referred to and will not be repeated here.
[0183] B3. Obtain a minimum value between the first waypoint distance and the second waypoint distance as the target waypoint distance.
[0184] For example, Figure 8As shown, if the first waypoint distance S2 is less than the second waypoint distance S3, the first waypoint distance S2 is used as the target waypoint distance.
[0185] It can be seen that by obtaining the first waypoint closest to the target location from each waypoint in the first area, obtaining the second waypoint closest to the target location from each waypoint in the second area, and taking the minimum value of the first waypoint distance and the second waypoint distance as the target waypoint distance, the area corresponding to the target waypoint distance can be quickly determined, so that the area where the nearest waypoint of the target may fall can be quickly located, thereby improving the speed of determining the nearest waypoint of the target.
[0186] From the above content, it can be seen that in the embodiment of the present application, by obtaining the first target area with the smallest area distance from the target location from the target area set; based on each waypoint in the first target area and the target location, determining the target nearest waypoint at the target location; it aims to first find out the area where the target nearest waypoint at the target location falls from a plurality of pre-divided preset areas; and then find out the target nearest waypoint at the target location from each waypoint in the area where the target nearest waypoint at the target location falls by calculating the distance between the target location and each waypoint. On the one hand, although the distance between the target location and each waypoint is still required, since only the waypoints in the area where the target nearest waypoint at the target location falls need to be calculated for searching, the waypoint search space when searching for the target nearest waypoint is greatly reduced, the amount of data calculation for searching the nearest waypoint is reduced, and the time consumption for searching the nearest waypoint is shortened, thereby improving the search speed of the target nearest waypoint. On the other hand, although it is necessary to first find the area where the target's nearest waypoint falls from multiple preset areas, the number of preset areas in the target game scene is far less than the number of the target game scene waypoints. Therefore, the amount of data calculation for searching the target's nearest waypoint can be reduced to a certain extent, and the time spent searching for the nearest waypoint can be shortened, thereby improving the search speed of the target's nearest waypoint. It can be seen that the embodiment of the present application can reduce the amount of data calculation for searching the nearest waypoint, shorten the time spent searching for the nearest waypoint, and thus improve the real-time performance of determining the nearest waypoint in the game.
[0187] In addition, if the distance between the player's position (i.e. the target's position) and each waypoint within the preset distance range is directly calculated to find the nearest waypoint, the waypoints are irregularly distributed, sparse in some places and dense in others. If the preset distance is set too small, the nearest waypoint cannot be calculated normally in sparse places; if the preset distance is set too large, the number of waypoints to be calculated in dense places will still be large.
[0188] In the embodiment of the present application, the distance between the player's position (i.e., the target's position) and each waypoint within the preset distance range is not directly calculated to find the nearest waypoint. Therefore, the following two problems caused by using waypoints within the preset distance range to find the nearest waypoint can be avoided: first, it is difficult to ensure the normal calculation of the nearest waypoint on the basis of reducing the number of waypoint calculations; second, because the amount of data calculated for the distance between the player's position and the waypoint is much larger than the amount of data calculated for the distance between the player's position and the area, the waypoint calculation method within the preset distance range does not significantly reduce the amount of calculation.
[0189] In the prior art, when determining the nearest waypoint of the current position of the game user or the nearest waypoint of the target position, the amount of calculation is large and the time is long, resulting in a slow pathfinding speed, which is difficult to meet the real-time pathfinding requirements of the game. The method of determining the nearest waypoint of the target in the above steps 101 to 105 in the embodiment of the present application can also be applied to determine the nearest waypoint of the starting position and the nearest waypoint of the end position of the virtual game character during pathfinding. Furthermore, after determining the nearest waypoint of the starting position and the nearest waypoint of the end position of the virtual game character, pathfinding can also be performed based on the nearest waypoint of the starting position and the nearest waypoint of the end position.
[0190] Among them, the method of finding the path based on the nearest waypoint at the starting point and the nearest waypoint at the end point can refer to some existing path finding methods, and the specific path finding method is not limited here.
[0191] Through the above-mentioned steps 101 to 105 in the embodiment of the present application, the nearest waypoint of the starting point and the nearest waypoint of the end point of the virtual game character are determined during path finding, and then path finding is performed. Since the amount of data calculation when searching for the nearest waypoint can be reduced, the search speed of the nearest waypoint can be increased, thereby improving the real-time performance of path finding in the game.
[0192] In order to better implement the above method, an embodiment of the present invention further provides a device for determining a nearest waypoint, which can be integrated into an electronic device, such as a computer device, which can be a terminal, a server, or other device.
[0193] Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop computer, a personal computer and other devices; the server can be a single server or a server cluster composed of multiple servers.
[0194] For example, in this embodiment, the method of the embodiment of the present invention is described in detail by taking the device for determining the nearest waypoint as specifically integrated into a smart phone as an example.
[0195] For example, Fig. 9As shown, the device for determining the nearest waypoint may include:
[0196] A first acquisition unit 901 is used to acquire a target position of a virtual game character in a target game scene;
[0197] A second acquisition unit 902 is used to acquire the position information of each preset area in the target area set of the target game scene, wherein the target area set includes multiple preset areas;
[0198] A third acquisition unit 903 is used to acquire an area distance between each preset area and the location of the target based on the location of the target and the location information of each preset area;
[0199] A fourth acquisition unit 904 is configured to acquire, from the target area set, a first target area having the smallest area distance to the target location;
[0200] The determining unit 905 is configured to determine the nearest waypoint of the target location based on the waypoints in the first target area and the target location.
[0201] In some embodiments, the determining unit 905 is specifically configured to:
[0202] Acquire, from each waypoint in the first target area, a preliminary target waypoint that is closest to the location of the target;
[0203] Obtaining a distance between the preliminary target waypoint and the target waypoint at the target location;
[0204] From the target area set, obtain a second target area having the second smallest area distance to the target location;
[0205] Acquire a target area distance between the second target area and the target location;
[0206] When the target waypoint distance is less than the target area distance, the preliminary target waypoint is used as the target closest waypoint.
[0207] In some embodiments, the determining unit 905 is specifically configured to:
[0208] When the target waypoint distance is greater than or equal to the target area distance, acquiring an intermediate target waypoint closest to the target location from each waypoint in the second target area;
[0209] When the distance between the intermediate target waypoint and the target position is less than the target waypoint distance, filtering the first target area from the target area set to obtain a filtered area set;
[0210] Using the filtered area set as the target area set;
[0211] From the target area set, obtaining a first target area with the smallest area distance and a second target area with the second smallest area distance;
[0212] Acquire a distance between a preliminary target waypoint and a target waypoint at a location of the target, wherein the preliminary target waypoint is a waypoint that is closest to the location of the target among all the waypoints in the first target area;
[0213] Acquire a target area distance between the second target area and the target location;
[0214] When the target waypoint distance is less than the target area distance, the preliminary target waypoint is used as the target closest waypoint.
[0215] In some embodiments, the first target area includes a first area and a second area, the area distance between the first area and the location of the target is equal to the area distance between the second area and the location of the target, the preliminary target waypoint includes a first waypoint and a second waypoint, and the determining unit 905 is specifically used to:
[0216] Acquire, from each waypoint in the first area, a first waypoint that is closest to the location of the target;
[0217] Acquire, from the waypoints in the second area, a second waypoint that is closest to the location of the target;
[0218] Obtaining a first waypoint distance between the first waypoint and the location of the target;
[0219] Obtaining a second waypoint distance between the second waypoint and the location of the target;
[0220] The minimum value between the first waypoint distance and the second waypoint distance is obtained as the target waypoint distance.
[0221] In some embodiments, the location information of each preset area is the diagonal corner point coordinates of the minimum enclosing rectangle of all waypoints in each preset area, and the diagonal corner point coordinates include the third coordinates of the diagonal corner points of the minimum enclosing rectangle in the first coordinate axis direction of the target game scene and the fourth coordinates in the second coordinate axis direction of the target game scene. The third acquisition unit 903 is specifically used to:
[0222] Acquire a first coordinate of the position of the target in the direction of the first coordinate axis and a second coordinate in the direction of the second coordinate axis;
[0223] When the first coordinate is within the interval of the third coordinate, obtaining a difference between the second coordinate and the fourth coordinate as a regional distance between each preset area and the location of the target;
[0224] In some embodiments, the third acquisition unit 903 is specifically used to:
[0225] When the second coordinate is within the interval of the fourth coordinate, a difference between the first coordinate and the third coordinate is obtained as a regional distance between each preset area and the location of the target.
[0226] In some embodiments, the device for determining the nearest waypoint further includes a preprocessing unit (not shown in the figure), and before obtaining the area distance between each preset area and the location of the target based on the location of the target and the location information of each preset area, the preprocessing unit is specifically used to:
[0227] Determine all waypoints in each of the preset areas;
[0228] Determine the minimum enclosing rectangle of all the waypoints;
[0229] Get the coordinates of the diagonal corner points of the minimum enclosing rectangle.
[0230] In some embodiments, when the first coordinate is within the interval of the third coordinate, before obtaining the difference between the second coordinate and the fourth coordinate as the area distance between each preset area and the location of the target, the third obtaining unit 903 is specifically used to:
[0231] Detecting whether the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area;
[0232] When the target location is outside the minimum enclosing rectangle of all waypoints in each preset area and the first coordinate is within the interval of the third coordinate, the difference between the second coordinate and the fourth coordinate is obtained as the area distance between each preset area and the target location.
[0233] In some embodiments, the location information of each preset area is the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in each preset area, and the third acquisition unit 903 is specifically used to:
[0234] Detecting whether the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area;
[0235] When the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area, it is determined that the area distance between each preset area and the location of the target is 0.
[0236] In some embodiments, the device for determining the nearest waypoint further includes a pathfinding unit (not shown in the figure), the target position includes the starting position and the end position of the virtual game character, the target nearest waypoint includes the nearest waypoint of the starting position and the nearest waypoint of the end position, and the pathfinding unit is specifically used to:
[0237] Path finding is performed based on the nearest waypoint at the location of the starting point and the nearest waypoint at the location of the end point.
[0238] As can be seen from the above, the device for determining the nearest waypoint of this embodiment can obtain the target position of the virtual game character in the target game scene by the first acquisition unit 901; obtain the position information of each preset area in the target area set of the target game scene by the second acquisition unit 902, wherein the target area set includes multiple preset areas; obtain the area distance between each preset area and the target location based on the target location and the position information of each preset area by the third acquisition unit 903; obtain the first target area with the smallest area distance from the target location from the target area set by the fourth acquisition unit 904; determine the target nearest waypoint of the target location based on each waypoint in the first target area and the target location by the determination unit 905. Therefore, the embodiment of the present invention can reduce the amount of data calculation for searching the nearest waypoint, so as to shorten the time consumption for searching the nearest waypoint, thereby improving the real-time performance of determining the nearest waypoint in the game.
[0239] Accordingly, the embodiment of the present application also provides a computer device, which may be a terminal, and the terminal may be a smart phone, a tablet computer, a laptop computer, a touch screen, a game console, a personal computer (PC, Personal Computer), a personal digital assistant (Personal Digital Assistant, PDA) and other terminal devices. Fig.10 As shown, Fig.10A schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device 1000 includes a processor 1001 having one or more processing cores, a memory 1002 having one or more computer-readable storage media, and a computer program stored in the memory 1002 and executable on the processor. The processor 1001 is electrically connected to the memory 1002. Those skilled in the art will appreciate that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange components differently.
[0240] Processor 1001 is the control center of computer device 1000. It uses various interfaces and lines to connect various parts of the entire computer device 1000, executes various functions of computer device 1000 and processes data by running or loading software programs and / or modules stored in memory 1002, and calling data stored in memory 1002, thereby monitoring computer device 1000 as a whole.
[0241] In the embodiment of the present application, the processor 1001 in the computer device 1000 will load instructions corresponding to the processes of one or more application programs into the memory 1002 according to the following steps, and the processor 1001 will run the application programs stored in the memory 1002 to implement various functions:
[0242] Obtaining the target position of the virtual game character in the target game scene;
[0243] Acquire the position information of each preset area in the target area set of the target game scene, wherein the target area set includes a plurality of preset areas;
[0244] Based on the location of the target and the location information of each preset area, obtaining the area distance between each preset area and the location of the target;
[0245] From the target area set, obtain a first target area having the smallest area distance to the target location;
[0246] Based on the waypoints in the first target area and the location of the target, a target nearest waypoint at the location of the target is determined.
[0247] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0248] Optional, such as Fig.10As shown, the computer device 1000 further includes: a touch screen 1003, a radio frequency circuit 1004, an audio circuit 1005, an input unit 1006, and a power supply 1007. The processor 1001 is electrically connected to the touch screen 1003, the radio frequency circuit 1004, the audio circuit 1005, the input unit 1006, and the power supply 1007, respectively. Those skilled in the art can understand that Fig.10 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0249] The touch display screen 1003 can be used to display a graphical user interface and receive operation instructions generated by the user acting on the graphical user interface. The touch display screen 1003 may include a display panel and a touch panel. Among them, the display panel may be used to display information input by the user or information provided to the user and various graphical user interfaces of a computer device, and these graphical user interfaces may be composed of graphics, text, icons, videos and any combination thereof. Optionally, the display panel may be configured in the form of a liquid crystal display (LCD, Liquid Crystal Display), an organic light emitting diode (OLED, Organic Light-Emitting Diode) and the like. The touch panel may be used to collect the user's touch operation on or near it (such as the user using any suitable object or attachment such as a finger, a stylus, etc. on the touch panel or near the touch panel), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel may include two parts, a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 1001, and can receive the command sent by the processor 1001 and execute it. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it is transmitted to the processor 1001 to determine the type of touch event, and then the processor 1001 provides a corresponding visual output on the display panel according to the type of touch event. In an embodiment of the present application, the touch panel and the display panel can be integrated into the touch display screen 1003 to realize the input and output functions. However, in some embodiments, the touch panel and the touch panel can be used as two independent components to realize the input and output functions. That is, the touch display screen 1003 can also be used as a part of the input unit 1006 to realize the input function.
[0250] The radio frequency circuit 1004 may be used to send and receive radio frequency signals, so as to establish wireless communication with a network device or other computer devices through wireless communication, and to send and receive signals between the network device or other computer devices.
[0251] The audio circuit 1005 can be used to provide an audio interface between the user and the computer device through a speaker and a microphone. The audio circuit 1005 can transmit the electrical signal converted from the received audio data to the speaker, which is converted into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 1005 and converted into audio data, and then the audio data is output to the processor 1001 for processing, and then sent to another computer device through the radio frequency circuit 1004, or the audio data is output to the memory 1002 for further processing. The audio circuit 1005 may also include an earphone jack to provide communication between an external headset and the computer device.
[0252] The input unit 1006 may be used to receive input numbers, character information or user feature information (such as fingerprint, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0253] The power supply 1007 is used to supply power to various components of the computer device 1000. Optionally, the power supply 1007 can be logically connected to the processor 1001 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 1007 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0254] although Fig.10 Not shown, the computer device 1000 may also include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which will not be described in detail here.
[0255] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0256] As can be seen from the above, the computer device provided in this embodiment can obtain the first target area with the smallest area distance from the target location from the target area set; determine the target nearest waypoint at the target location based on each waypoint in the first target area and the target location; it aims to first find out the area where the target nearest waypoint at the target location falls from a plurality of pre-divided preset areas; and then find out the target nearest waypoint at the target location from each waypoint in the area where the target nearest waypoint at the target location falls by calculating the distance between the target location and each waypoint. On the one hand, although the distance between the target location and each waypoint is still required, since only the waypoints in the area where the target nearest waypoint at the target location falls need to be calculated for searching, the waypoint search space when searching for the target nearest waypoint is greatly reduced, the amount of data calculation for searching the nearest waypoint is reduced, and the time consumption for searching the nearest waypoint is shortened, thereby improving the search speed of the target nearest waypoint. On the other hand, although it is necessary to first find the area where the target nearest waypoint falls from multiple preset areas, the number of preset areas in the target game scene is far less than the number of waypoints in the target game scene. Therefore, the amount of data calculation for searching the target nearest waypoint can be reduced to a certain extent, and the time spent searching the nearest waypoint can be shortened, thereby improving the search speed of the target nearest waypoint. The computer device provided in this embodiment can reduce the amount of data calculation for searching the nearest waypoint, shorten the time spent searching the nearest waypoint, and thereby improve the real-time performance of determining the nearest waypoint in the game.
[0257] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0258] To this end, an embodiment of the present application provides a computer-readable storage medium, in which a plurality of computer programs are stored, and the computer program can be loaded by a processor to execute the steps in any of the methods for determining the closest waypoint provided in the embodiments of the present application. For example, the computer program can execute the following steps:
[0259] Obtaining the target position of the virtual game character in the target game scene;
[0260] Acquire the position information of each preset area in the target area set of the target game scene, wherein the target area set includes a plurality of preset areas;
[0261] Based on the location of the target and the location information of each preset area, obtaining the area distance between each preset area and the location of the target;
[0262] From the target area set, obtain a first target area having the smallest area distance to the target location;
[0263] Based on the waypoints in the first target area and the location of the target, a target nearest waypoint at the location of the target is determined.
[0264] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0265] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0266] Since the computer program stored in the computer-readable storage medium can execute the steps in any of the methods for determining the nearest waypoint provided in the embodiments of the present application, the beneficial effects that can be achieved by any of the methods for determining the nearest waypoint provided in the embodiments of the present application can be achieved. For details, please refer to the previous embodiments and will not be repeated here.
[0267] The above is a detailed introduction to a method, device, computer-readable storage medium and computer equipment for determining the closest waypoint provided in an embodiment of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for determining the nearest waypoint, characterized in that: include: Obtaining the target position of the virtual game character in the target game scene; Obtaining the position information of each preset area in the target area set of the target game scene, wherein the target area set includes a plurality of preset areas; the position information of the preset area is the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in the preset area; Based on the location of the target and the location information of each preset area, obtaining the area distance between each preset area and the location of the target; From the target area set, obtain a first target area having the smallest area distance to the target location; Determining a target nearest waypoint at the target location based on each waypoint in the first target area and the target location; The step of determining the nearest waypoint of the target location based on the waypoints in the first target area and the target location includes: From each waypoint in the first target area, a waypoint closest to the target location is obtained as the target closest waypoint at the target location.
2. The method for determining the nearest waypoint according to claim 1, characterized in that: The determining, based on the information of each waypoint in the first target area and the location of the target, the nearest waypoint of the target at the location of the target comprises: Acquire, from each waypoint in the first target area, a preliminary target waypoint that is closest to the location of the target; Obtaining a distance between the preliminary target waypoint and the target waypoint at the target location; From the target area set, obtain a second target area having the second smallest area distance to the target location; Acquire a target area distance between the second target area and the target location; When the target waypoint distance is less than the target area distance, the preliminary target waypoint is used as the target closest waypoint.
3. The method for determining the nearest waypoint according to claim 2, characterized in that: The method further comprises: When the target waypoint distance is greater than or equal to the target area distance, acquiring an intermediate target waypoint closest to the target location from each waypoint in the second target area; When the distance between the intermediate target waypoint and the target position is less than the target waypoint distance, filtering the first target area from the target area set to obtain a filtered area set; Using the filtered area set as the target area set; From the target area set, obtaining a first target area with the smallest area distance and a second target area with the second smallest area distance; Acquire a distance between a preliminary target waypoint and a target waypoint at a location of the target, wherein the preliminary target waypoint is a waypoint that is closest to the location of the target among all the waypoints in the first target area; Acquire a target area distance between the second target area and the target location; When the target waypoint distance is less than the target area distance, the preliminary target waypoint is used as the target closest waypoint.
4. The method for determining the nearest waypoint according to claim 2, characterized in that: The first target area includes a first area and a second area, the area distance between the first area and the location of the target is equal to the area distance between the second area and the location of the target, and the preliminary target waypoint includes a first waypoint and a second waypoint; The step of acquiring, from the first target area, a preliminary target waypoint that is closest to the location of the target includes: Acquire, from each waypoint in the first area, a first waypoint that is closest to the location of the target; Acquire, from the waypoints in the second area, a second waypoint that is closest to the location of the target; The step of obtaining the distance between the preliminary target waypoint and the target waypoint at the target location includes: Obtaining a first waypoint distance between the first waypoint and the location of the target; Obtaining a second waypoint distance between the second waypoint and the location of the target; The minimum value between the first waypoint distance and the second waypoint distance is obtained as the target waypoint distance.
5. The method for determining the nearest waypoint according to claim 1, characterized in that: The diagonal corner point coordinates include the third coordinates of the diagonal corner points of the minimum enclosing rectangle in the direction of the first coordinate axis of the target game scene and the fourth coordinates in the direction of the second coordinate axis of the target game scene; The acquiring, based on the location of the target and the location information of each preset area, the area distance between each preset area and the location of the target includes: Acquire a first coordinate of the position of the target in the direction of the first coordinate axis and a second coordinate in the direction of the second coordinate axis; When the first coordinate is within the interval of the third coordinate, a difference between the second coordinate and the fourth coordinate is obtained as a regional distance between each preset area and the position of the target.
6. The method for determining the nearest waypoint according to claim 5, characterized in that: The method further comprises: When the second coordinate is within the interval of the fourth coordinate, a difference between the first coordinate and the third coordinate is obtained as a regional distance between each preset area and the location of the target.
7. The method for determining the nearest waypoint according to claim 5, characterized in that: Before acquiring the area distance between each preset area and the location of the target based on the location of the target and the location information of each preset area, the method further includes: Determine all waypoints in each of the preset areas; Determine the minimum enclosing rectangle of all the waypoints; Get the coordinates of the diagonal corner points of the minimum enclosing rectangle.
8. The method for determining the nearest waypoint according to claim 5, characterized in that: Before obtaining the difference between the second coordinate and the fourth coordinate as the area distance between each preset area and the location of the target when the first coordinate is within the interval of the third coordinate, the method further includes: Detecting whether the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area; When the first coordinate is within the interval of the third coordinate, obtaining the difference between the second coordinate and the fourth coordinate as the area distance between each preset area and the location of the target includes: When the target location is outside the minimum enclosing rectangle of all waypoints in each preset area and the first coordinate is within the interval of the third coordinate, the difference between the second coordinate and the fourth coordinate is obtained as the area distance between each preset area and the target location.
9. The method for determining the nearest waypoint according to claim 1, characterized in that: The location information of each preset area is the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in each preset area; The acquiring, based on the location of the target and the location information of each preset area, the area distance between each preset area and the location of the target includes: Detecting whether the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area; When the location of the target is within the minimum enclosing rectangle of all waypoints in each preset area, it is determined that the area distance between each preset area and the location of the target is 0.
10. The method for determining the nearest waypoint according to any one of claims 1 to 9, characterized in that: The target location includes the starting location and the end location of the virtual game character, the target nearest waypoint includes the nearest waypoint of the starting location and the nearest waypoint of the end location, and the method further includes: Path finding is performed based on the nearest waypoint at the location of the starting point and the nearest waypoint at the location of the end point.
11. A device for determining the nearest waypoint, characterized in that: include: A first acquisition unit, used to acquire a target position of a virtual game character in a target game scene; A second acquisition unit is used to acquire the position information of each preset area in the target area set of the target game scene, wherein the target area set includes multiple preset areas; the position information of the preset area is the coordinates of the diagonal corner points of the minimum enclosing rectangle of all waypoints in the preset area; A third acquisition unit, configured to acquire a regional distance between each preset area and the location of the target based on the location of the target and the location information of each preset area; A fourth acquisition unit, configured to acquire, from the target area set, a first target area having the smallest area distance to the target location; A determination unit, configured to determine a target nearest waypoint at the location of the target based on each waypoint in the first target area and the location of the target; The step of determining the nearest waypoint of the target location based on the waypoints in the first target area and the target location includes: From each waypoint in the first target area, a waypoint closest to the target location is obtained as the target closest waypoint at the target location.
12. A terminal, characterized in that: The method comprises a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in the method for determining the nearest waypoint according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the method for determining the closest waypoint according to any one of claims 1 to 10.
