CN112370788A - Navigation method of virtual object in game and electronic equipment - Google Patents

Navigation method of virtual object in game and electronic equipment Download PDF

Info

Publication number
CN112370788A
CN112370788A CN202011258658.4A CN202011258658A CN112370788A CN 112370788 A CN112370788 A CN 112370788A CN 202011258658 A CN202011258658 A CN 202011258658A CN 112370788 A CN112370788 A CN 112370788A
Authority
CN
China
Prior art keywords
node
virtual object
point
nodes
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011258658.4A
Other languages
Chinese (zh)
Inventor
唐健伦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN202011258658.4A priority Critical patent/CN112370788A/en
Publication of CN112370788A publication Critical patent/CN112370788A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/55Controlling game characters or game objects based on the game progress
    • A63F13/57Simulating properties, behaviour or motion of objects in the game world, e.g. computing tyre load in a car race game
    • A63F13/573Simulating properties, behaviour or motion of objects in the game world, e.g. computing tyre load in a car race game using trajectories of game objects, e.g. of a golf ball according to the point of impact
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F2300/00Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
    • A63F2300/60Methods for processing data by generating or executing the game program
    • A63F2300/64Methods for processing data by generating or executing the game program for computing dynamical parameters of game objects, e.g. motion determination or computation of frictional forces for a virtual car
    • A63F2300/646Methods for processing data by generating or executing the game program for computing dynamical parameters of game objects, e.g. motion determination or computation of frictional forces for a virtual car for calculating the trajectory of an object

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Processing Or Creating Images (AREA)

Abstract

The invention provides a navigation method of a virtual object in a game and electronic equipment, wherein the method comprises the following steps: responding to a target point setting operation aiming at a virtual object in a game scene, and determining a starting point and an end point corresponding to the virtual object; starting from a node where a starting point is located, executing a path-finding algorithm on grid nodes of a walkable area in a game scene to obtain a target node group from the starting point to a terminal point; determining a navigation path based on the target node group; and controlling the virtual object to move to the end point according to the navigation path. In the method, the grid size of the leaf node of the walkable area is large, the problem that the grid storage space corresponding to the wide walkable area is large in consumption is effectively solved, the grid size of the leaf node of the obstacle area is small, accurate positioning of the obstacle area is guaranteed, the searched navigation path can be guaranteed to be more optimal by means of determining the path point through the path searching operation, and the navigation effect of the virtual object is effectively improved.

Description

Navigation method of virtual object in game and electronic equipment
Technical Field
The present invention relates to the field of game technologies, and in particular, to a method for navigating a virtual object in a game and an electronic device.
Background
Routing in a game is to let a character autonomously move from one location in a scene to another location according to an appropriate path. In general, the way-finding algorithm can be divided into two steps: scene map representation and path search. The scene map representation is used for abstracting an actual game scene into a specific mathematical model and is used for representing a scene structure, obstacle information and feasible region information; the path search is to execute a search algorithm on the mathematical model to obtain a final path-finding path.
The scene map representation method is various, and there are a two-dimensional grid method, a waypoint method, a navigation grid method, and the like. The two-dimensional grid method divides a scene into two-dimensional grids with equal size, each grid can be marked as whether an obstacle exists, and a path finding path takes the grid as a unit and bypasses the grid marked as the obstacle. The path point method is to abstract a scene into a series of path points, the positions and the communication relations of the path points can be artificially designed, and the roles can move according to the ideas of designers when finding paths. The navigation grid method (Navmesh) uses convex polygon sets with different shapes to represent the whole scene, and uses polygons to cover walkable areas in the scene.
The path search algorithm is a search algorithm based on a scene map, and common algorithms include depth-first search, breadth-first search, Dijkstra algorithm, a-x algorithm and the like.
There is a kind of open game scene in the game scene, the walkable area in the game scene is much wider than the barrier area, and the barrier area is dynamically changed, that is, the position of the barrier is random when the game scene is created. Taking a sea area game scene as an example, the scene is a wide sea area with a plurality of islands, the sea area is wide, and the islands are randomly positioned.
For the way finding in the open game scene, the navigation grid can not be prepared in advance based on the navigation grid method due to the randomness of the obstacles, and the memory overhead of calculating the navigation grid is large due to the very wide walkable area in the open game scene, so that the way finding calculation efficiency is influenced.
Disclosure of Invention
In view of the above, the present invention provides a method for navigating a virtual object in a game and an electronic device, so as to alleviate the above problem.
In a first aspect, an embodiment of the present invention provides a method for navigating a virtual object in a game, where a game scene is displayed by an electronic device, the method including: responding to a target point setting operation aiming at a virtual object in the game scene, and determining a starting point and an end point corresponding to the virtual object; starting from a node where a starting point is located, executing a path-finding algorithm on grid nodes of a walkable area in a game scene to obtain a target node group from the starting point to a terminal point, wherein the grid nodes are nodes in a quadtree formed by dividing the game scene according to parameter information of obstacles in the game scene, and the grid size of leaf nodes of the obstacle area in the game scene is smaller than that of partial leaf nodes of the walkable area; determining a navigation path from a starting point to an end point based on the target node group; the navigation path consists of path points corresponding to target nodes in the target node group; and controlling the virtual object to move to the end point according to the navigation path.
The grid nodes are nodes in a quadtree formed by dividing the game scene according to parameter information of obstacles in the game scene, and the method comprises the following steps of: responding to the grid creating operation aiming at the game scene, and carrying out quad-tree grid division on the barrier region of the barrier in the game scene by taking the preset maximum grid size as the side length of a root node until the side length of the barrier region divided to a leaf node is equal to the preset minimum grid size.
Further, in response to the mesh creation operation for the game scene, with a preset maximum mesh size as a side length of a root node, performing quadtree mesh partitioning on the obstacle region of the obstacle in the game scene until the side length of the obstacle region partitioned to a leaf node is equal to a preset minimum mesh size includes: responding to the mesh creating operation aiming at the game scene in the initial state, and carrying out quad-tree mesh division on the game scene by taking the preset maximum mesh size as the side length of a root node until the game scene is divided into a reference mesh of a quad-tree; wherein the game scenes in the initial state are all walkable areas; responding to an obstacle creating operation aiming at the game scene, creating an obstacle in the game scene, and carrying out quad-tree meshing on a reference grid of an obstacle area of the obstacle until the side length of a leaf node is equal to a preset minimum grid size; wherein the size of the reference grid is between the preset maximum grid size and the preset minimum grid size.
Further, the method further comprises: checking whether leaf nodes with side lengths equal to a preset minimum grid size are located in the obstacle area; if so, marking the leaf node as the leaf node of the barrier area; if not, and the brother nodes of the leaf nodes are not in the obstacle area, deleting the leaf nodes and the brother nodes of the leaf nodes.
Further, the step of checking whether leaf nodes with side lengths equal to a preset minimum grid size are located in the obstacle area includes: checking whether the central point of a leaf node with a preset minimum grid size is in an obstacle area; if so, determining that the leaf node is within the obstacle area; if not, performing quadtree division on the leaf node to obtain child nodes of the leaf node, and if the central points of the child nodes of the leaf node are not in the obstacle area, determining that the leaf node is not in the obstacle area; determining that the leaf node is within the obstacle area if the center point of at least one child node of the leaf node is within the obstacle area.
Further, the step of determining the start point and the end point corresponding to the virtual object includes: respectively dividing the node of the current position of the virtual object and the node of the position of the target point set by the target point setting operation to the minimum mesh size; determining a leaf node containing the central point of the virtual object as a starting point corresponding to the virtual object; determining a leaf node containing the central point of the target point as a terminal point corresponding to the virtual object; the method further comprises the following steps: and when the navigation path is determined, restoring the node of the current position of the virtual object to the grid node before the grid node is divided to the minimum grid size, and restoring the node of the position of the target point to the grid node before the grid node is divided to the minimum grid size.
Further, the routing algorithm is an a-search algorithm, and the a-search algorithm determines neighboring nodes of the current node by the following method: based on the quad-tree grid nodes in the walkable area in the game scene, searching nodes with the grid size larger than or equal to that of the current node in the direction of the adjacent position of the current node to obtain a node group to be determined; taking a non-leaf node in the node group to be determined as an intermediate node, and searching a leaf node adjacent to the current node from the intermediate node; and taking the searched leaf nodes and nodes except the intermediate node in the pending node group as the adjacent nodes of the current node.
Further, the electronic device stores the parent-child relationship of each node; the step of searching for a node with a mesh size larger than or equal to the mesh size of the current node in the direction of the neighboring position of the current node to obtain a node group to be determined includes: acquiring a father node of a current node and azimuth information of the current node in the father node; for each pre-designated neighboring direction, determining a node to be determined by performing the following operations: if the direction corresponding to the azimuth information is opposite to the direction of the adjacent position, determining a node to be determined from brother nodes of the current node; the grid size of the brother node is equal to the grid size of the current node; if the direction corresponding to the azimuth information is the same as the adjacent position direction, taking the adjacent node positioned in the adjacent position direction of the father node as the undetermined node of the current node; the grid size of the adjacent node is larger than that of the current node; and forming the undetermined nodes corresponding to the adjacent direction into an undetermined node group of the current node.
Further, the step of searching for a leaf node adjacent to the current node from the intermediate node includes: recursively traversing child nodes in the middle node in the direction opposite to the direction of the adjacent positions in each preassigned adjacent position direction according to a preset depth-first traversal principle until leaf nodes in the direction opposite to the direction of the adjacent positions are traversed; and determining leaf nodes adjacent to the current node from the traversed leaf nodes.
Further, the step of controlling the virtual object to move to the end point according to the navigation path includes: in response to a path point event that the virtual object reaches the navigation path, reading the next path point from the navigation path, taking the read path point as the current path point, and executing the following operations: determining the relative relation between the current path point and the current position of the virtual object; and adjusting the advancing direction and the advancing speed of the virtual object according to the relative relation so as to enable the virtual object to advance towards the current path point.
Further, the step of determining the relative relationship between the current waypoint and the current position of the virtual object includes: determining the interval frame number according to the advancing speed of the virtual object; correcting the relative relation between the current path point and the current position of the virtual object according to the determined interval frame number; the step of adjusting the advancing direction and the advancing speed of the virtual object according to the relative relationship comprises the following steps: and adjusting the advancing direction and the advancing speed of the virtual object according to the corrected relative relation.
Further, the method further comprises: determining a waypoint radius based on the forward speed of the virtual object; and if the distance between the current position of the virtual object and the current path point is less than or equal to the radius of the path point, determining that the virtual object reaches the current path point.
Further, the step of determining the radius of the waypoint based on the forward speed of the virtual object comprises: and calculating the radius R of the path point, which is R + k × s, wherein R is a preset base radius, k is a preset correction coefficient, and s is the advancing speed of the virtual object.
Further, the game scene is a sea scene, and the virtual object is a virtual ship; the mesh size of each node is an integer power of 2.
In a second aspect, an embodiment of the present invention further provides an electronic device, including a processor and a memory, where the memory stores computer-executable instructions capable of being executed by the processor, and the processor executes the computer-executable instructions to implement the method for navigating a virtual object in a game according to any one of the first aspect.
In a third aspect, embodiments of the present invention also provide a computer-readable storage medium storing computer-executable instructions that, when invoked and executed by a processor, cause the processor to implement a method of navigating a virtual object in a game according to any one of the first aspect.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention provides a navigation method and electronic equipment of a virtual object in a game, which respond to the setting operation of a target point of a virtual object in a game scene and determine a starting point and an end point corresponding to the virtual object; starting from a node where a starting point is located, executing a path-finding algorithm on grid nodes of a walkable area in a game scene to obtain a target node group from the starting point to a terminal point; determining a navigation path from a starting point to an end point based on the target node group; the navigation path consists of path points corresponding to target nodes in the target node group; and controlling the virtual object to move to the end point according to the navigation path. In the method, the grid nodes are nodes in a quadtree formed by dividing a game scene according to parameter information of obstacles in the game scene, the grid size of leaf nodes of an obstacle area in the game scene is smaller than that of partial leaf nodes of a walkable area, and the division mode with larger grid size of the leaf nodes of the walkable area can effectively relieve the problem of larger consumption of grid storage space corresponding to the wide walkable area; in the process of searching the path, a path searching algorithm is executed on the quad-tree grid nodes of the walkable area in the game scene to obtain a target node group from the starting point to the end point; the navigation path is determined based on the target node group, so that the searched navigation path can be ensured to be more preferable, and the navigation effect of the virtual object is effectively improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and drawings.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
FIG. 1 is a schematic diagram of a quad-tree according to an embodiment of the present invention;
FIG. 2 is a quad-tree logic diagram according to an embodiment of the present invention;
FIG. 3 is a flowchart of a method for navigating a virtual object in a game according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a neighboring node according to an embodiment of the present invention;
fig. 5 is a schematic diagram of another neighboring node according to an embodiment of the present invention;
fig. 6 is a schematic diagram of a parent node according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of a node grid size according to an embodiment of the present invention;
fig. 8 is a schematic diagram illustrating an effect of reference grid division according to an embodiment of the present invention;
FIG. 9 is a diagram illustrating an initial game scene partitioning into reference grids according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of a node according to an embodiment of the present invention;
fig. 11 is a schematic diagram of a partition result for creating an obstacle according to an embodiment of the present invention;
FIG. 12 is a flow chart of another method for navigating a virtual object in a game according to an embodiment of the present invention;
FIG. 13 is a schematic diagram illustrating a division of a start point and an end point of a virtual object into minimum levels according to an embodiment of the present invention;
FIG. 14 is a flowchart of searching for a north neighbor according to an embodiment of the present invention;
fig. 15 is a schematic diagram of a node according to an embodiment of the present invention;
fig. 16 is a schematic diagram of another node according to an embodiment of the present invention;
FIG. 17 is a flow chart illustrating a method for navigating a virtual object in a game according to an embodiment of the present invention;
FIG. 18 is a schematic diagram of a modification mechanism according to an embodiment of the present invention;
FIG. 19 is a diagram illustrating the result of controlling the movement of a virtual object according to an embodiment of the present invention;
FIG. 20 is a schematic diagram of an ocean scene provided by an embodiment of the present invention;
fig. 21 is a flowchart of a navigation method for a virtual ship in an ocean scene according to an embodiment of the present invention;
FIG. 22 is a diagram illustrating a navigation device for virtual objects in a game according to an embodiment of the present invention;
fig. 23 is a schematic view of an electronic device according to an embodiment of the present invention.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The way finding is a common requirement in the game industry, and has wide application in many games, such as monster AI (Artificial Intelligence), player automatic mode, and scene of a scene cut animation. However, with the development of open-world games and the improvement of requirements of players on game contents, the existing way-finding method cannot provide efficient support for large-world randomly-generated terrain scenes. How to find an efficient method to organize scene information and give a way finding result is a problem concerned by the game industry.
For example, for a game scene, which is a wide sea area with a plurality of islands, the sea area is wide, and the islands are randomly located, the scene has the following characteristics: firstly, the walkable area is much wider than the barrier area; secondly, the obstacle area is dynamically changed, that is, the position of the obstacle is random when the game scene is created, so that the existing way-finding method has some problems for the game scene, such as low efficiency and inflexibility of scene map representation.
Specifically, for the above game scene, if the navigation grid method is used, it is not feasible to prepare the navigation grid of the entire scene in advance due to the randomness of the island positions; although the problem of randomness of the obstacles can be solved by adopting the Tile-Navmesh-based navigation grid, the path-finding grid is paved in the whole scene, which causes serious memory waste, and because the obstacles are sparse, a plurality of navigation grids do not contribute to avoiding the obstacles, which further means the waste of computing resources. If a two-dimensional grid method is used, the size of a two-dimensional grid is difficult to grasp, the smaller the grid size is, the more accurate the path finding is, but the higher the calculation overhead is; the larger the grid size is, the more resources can be saved, but the path-finding precision is greatly reduced, so that the feasibility of the two-dimensional grid method is lower. If the waypoint method is used, the feasibility of the waypoint method is extremely low because it is difficult for the artificially placed waypoints to fully cover all the possibilities of seeking a way over a wide sea surface.
Therefore, for the way searching in the open game scene, most of the existing way searching methods have the defects of insufficient support for random obstacles, low calculation efficiency and large resource occupation, thereby reducing the game experience of users. Based on this, the embodiment of the invention provides a navigation method and device for a virtual object in a game and an electronic device, and the technology can be applied to various game scenes, particularly to an open game scene with a walkable area which is much wider than an obstacle area and a dynamically-changing obstacle area.
To facilitate understanding of the embodiment, first, a detailed description is given below of a navigation method for a virtual object in a game according to an embodiment of the present invention, where the method is applicable to an electronic device, and a graphical user interface is provided by the electronic device, where the graphical user interface at least includes a game scene and a virtual object; the virtual object can also be called a virtual character or a game character; the game scene is an open game scene, such as a sea scene with a wide area, random obstacle positions and sparse density, a grassland scene with sparse tree density, an air scene with other warplane obstacles and the like.
The electronic equipment controls the virtual object to move in the open game scene; the electronic equipment can be mobile phones, computers, notebooks, tablet computers and other equipment; the graphical user interface is a scene currently displayed in a game, and comprises an open game scene, virtual objects, various obstacles and the like, wherein the various obstacles can be static obstacles, namely island obstacles with sparse density established during the creation of the game scene, or dynamic obstacles, namely other virtual objects meeting the requirement of avoiding collision during the movement of the virtual object in the virtual scene. In practical applications, the electronic device may control the virtual object to move in the game scene through a processor in the electronic device, and may also control the virtual object to move in the game scene through a movement control in the graphical user interface.
In addition, the game scene displayed by the electronic device is subjected to grid division in a quadtree grid division manner, wherein the quadtree is a tree-shaped data structure commonly used for two-dimensional space division, and is represented in a grid form, each grid is a node regardless of size, as shown in fig. 1, each node of the quadtree is a square, the node with the largest size, i.e., the grid with the largest outside, is called a root node, as shown in a root node a in fig. 1, the node is continuously divided, a plurality of child nodes can be obtained, and when a certain node is subdivided to have no child node, the node is called a leaf node, i.e., there is no other square in the square corresponding to the leaf node, as shown in a leaf node a1 in fig. 1. Furthermore, for ease of understanding, the logical diagram is shown in FIG. 2, where the root node A is the highest node in the logical diagram and the leaf node A1 is the node in the logical diagram without an arrow below. Obviously, if a large square is divided into four small squares, the sides of the small squares must be half that of the large square. Corresponding to the logic diagram, i.e. for each further layer, the side length is divided by 2.
For convenience of illustration, the game scene is divided into an obstacle area and a walkable area, where the walkable area is an area where the electronic device controls the virtual object to move, for example, for a marine scene, the obstacle area includes all island obstacles at random positions in the marine scene, and the walkable area is an area where the virtual ship (virtual object) can move to avoid the island obstacles. The barrier area and the walkable area are respectively subjected to grid division through a quad-tree grid division mode until leaf nodes of the barrier area and leaf nodes of the walkable area are obtained, and the leaf nodes of the walkable area except the leaf nodes where the virtual object starting point and the virtual object finishing point are located, the grid size of the rest leaf nodes is larger than or equal to that of the leaf nodes of the barrier area, so that the problem of large consumption of grid storage space corresponding to a wide walkable area can be effectively solved through a mode that the grid size of the leaf nodes of the walkable area is large, meanwhile, the accurate positioning of the barrier area can be guaranteed through a mode that the grid size of the leaf nodes of the barrier area is small, and a reliable data base is provided for road searching operation. In addition, the quadtree is flexibly divided, so that the dynamic obstacle which is a randomly generated obstacle can be well supported.
As shown in fig. 3, a flowchart of a navigation method for virtual objects in a game is provided, where an execution subject of the method is an electronic device, and a game scene is displayed by the electronic device, and the method includes the following steps:
step S302, responding to the target point setting operation aiming at a virtual object in the game scene, and determining a starting point and an end point corresponding to the virtual object.
In practical application, a user can set a target point of a virtual object in a graphical user interface provided by electronic equipment, and if the interface is a touch screen, the user can complete the setting of the target point through pressing operation; if the interface is a touchless screen, the user can also complete the target point setting through the clicking operation of a mouse and/or a keyboard. At this time, the start point and the end point of the virtual object may be determined according to the current position of the virtual object and the set target point. For convenience of understanding, it is illustrated here that, for a marine scene, after a player controls a virtual ship to enter a game scene, the player can determine a start point and an end point of the virtual ship according to a current position and a target point of the virtual ship by pressing or clicking a certain position, i.e., a target point, in the marine scene.
And step S304, starting from the node where the starting point is located, executing a routing algorithm on the grid nodes of the walkable area in the game scene to obtain a target node group from the starting point to the end point.
The mesh nodes in the embodiment of the application are nodes in a quadtree formed by dividing a game scene according to parameter information of obstacles in the game scene, and the mesh size of leaf nodes of an obstacle area in the game scene is smaller than that of partial leaf nodes of a walkable area.
For the game scene divided by the quadtree, after the starting point and the end point of the virtual object are determined, the path searching operation is further executed through a preset path searching algorithm, wherein the path searching algorithm can be a k neighbor algorithm, an a-x algorithm, an breadth-first searching algorithm and the like based on the quadtree grid, or an algorithm improved by a corresponding algorithm. Taking the a-algorithm as an example, the conventional a-algorithm mainly simplifies the area to be searched into small squares, for example, in a conventional two-dimensional grid, the size of the grid is consistent, the grid is often organized by a two-dimensional array, all reachable nodes of the current node are obtained by searching all adjacent grids of the current grid (current node), a group of child nodes is generated until the end point is found, and a node group from the start point to the end point is obtained, as shown in fig. 4, which is a schematic diagram of adjacent nodes, where all adjacent grids of grid a include: grids in eight directions, namely East (East, abbreviated as E), West (West, abbreviated as W), South (South), North (North, abbreviated as N), Southeast (Southeast, abbreviated as SE), Northeast (North, abbreviated as NE), Southwest (SW) and Northwest (North, abbreviated as NW) adjacent to the grid A, and the size of each grid is the same as that of the grid A.
In the embodiment of the present invention, because the game scene after the quadtree division is adopted, the mesh sizes of the nodes adjacent to the current node may be the same or different, as shown in fig. 5, for all the adjacent nodes of the node a, the mesh sizes of the N node in the north direction and the E node in the east direction are obviously larger than the mesh size of the node a, and in this embodiment, the determination mode of the reachable neighbor node of the current node is modified on the basis of the conventional a-x algorithm to adapt to the game scene after the quadtree division. As a possible implementation manner, in the process of determining the neighboring nodes of the current node, the routing algorithm determines the neighboring nodes of the current node based on the parent-child relationship between the grid nodes of the walkable area in the game scene, so that the determined neighboring nodes are leaf nodes as much as possible, and the storage space occupied by the target node group is smaller and the navigation path determined based on the target node group is more reasonable.
Step S306, determining a navigation path from a starting point to a terminal point based on the target node group; the navigation path is composed of path points corresponding to the target nodes in the target node group.
The target node group is a node list with a sequence formed by target nodes, and considering that each node corresponds to a grid region and has a larger area, each target node is converted into a point position, namely a path point, in the process of determining the navigation path, so that the navigation path can be more favorably and accurately represented. As a possible implementation manner, the central point of the target node may be used as the path point corresponding to the target node. Of course, other points in the target node may also be taken as the path points corresponding to the target node, which is not limited in this embodiment of the present invention.
The navigation path corresponding to the path point is an ordered connection line of the path points, and the specific mode of the connection line can be a straight line connection mode or a curve fitting mode and the like.
And step S308, controlling the virtual object to move to the end point according to the navigation path.
In practical applications, the moving process of a virtual object such as a virtual ship is different from the moving process of a character, and the virtual ship cannot stop, walk or turn quickly due to the resistance of water, wind speed, wind power and the like. Therefore, when controlling the virtual ship to move along the navigation path, the position and speed thereof may not be directly set, but a player or user operation may be simulated. Based on this, an instruction control for the virtual object may be displayed in the graphical user interface, for example, when the user triggers a steering instruction, the virtual object is controlled by the server or the processor in the electronic device to perform a steering operation; when a user triggers a start instruction or a stop instruction, the virtual object is controlled to perform start operation or stop operation, so that the virtual object is natural and not hard when moving along the navigation path, and the game experience of the user is improved.
The embodiment of the invention provides a navigation method of a virtual object in a game, which responds to the setting operation of a target point of a virtual object in a game scene and determines a starting point and an end point corresponding to the virtual object; starting from a node where a starting point is located, executing a path-finding algorithm on grid nodes of a walkable area in a game scene to obtain a target node group from the starting point to a terminal point; determining a navigation path from a starting point to an end point based on the target node group; and controlling the virtual object to move to the end point according to the navigation path. In the method, the grid nodes are nodes in a quadtree formed by dividing a game scene according to parameter information of obstacles in the game scene, the grid size of leaf nodes of an obstacle area in the game scene is smaller than that of partial leaf nodes of a walkable area, and the division mode with larger grid size of the leaf nodes of the walkable area can effectively relieve the problem of larger consumption of grid storage space corresponding to the wide walkable area; in the process of searching the path, a path searching algorithm is executed on the quad-tree grid nodes of the walkable area in the game scene to obtain a target node group from the starting point to the end point; the navigation path is determined based on the target node group, so that the searched navigation path can be ensured to be more preferable, and the navigation effect of the virtual object is effectively improved.
In one possible embodiment, the method further includes a game scene dividing process, that is, the mesh nodes are nodes in a quadtree formed by dividing the game scene according to parameter information of obstacles in the game scene, and the method includes the following steps: responding to the grid creating operation aiming at the game scene, and carrying out quad-tree grid division on the barrier region of the barrier in the game scene by taking the preset maximum grid size as the side length of a root node until the side length of the barrier region divided to a leaf node is equal to the preset minimum grid size. By the method, the grid size of the barrier area can be ensured to be smaller, and the subsequently determined barrier area is more accurate.
The process of dividing the game scene may further include: (1) responding to the mesh creating operation aiming at the game scene in the initial state, and carrying out quad-tree mesh division on the game scene by taking the preset maximum mesh size as the side length of a root node until the game scene is divided into a reference mesh of a quad-tree; wherein, the game scenes in the initial state are all walkable areas; (2) responding to an obstacle creating operation aiming at a game scene, creating an obstacle in the game scene, and carrying out quad-tree grid division on a reference grid of an obstacle area of the obstacle until the side length of a leaf node is equal to a preset minimum grid size; the size of the reference grid is between a preset maximum grid size and a preset minimum grid size.
The mesh creating process is carried out in two steps, firstly, mesh division is carried out on a game scene without a created barrier, namely the game scene in an initial state, all areas in the game scene in the initial state are walkable areas, therefore, the mesh division in the stage adopts the side length with the preset maximum mesh size as a root node, and the game scene is subjected to quad-tree mesh division until the game scene is divided into reference meshes of the quad-tree. The number of levels from the maximum grid to the reference grid can be determined according to the size of the game scene.
After the mesh division in the game scene in the initial state is completed, if an obstacle is created in the game scene, for example, one or more islands are created as an obstacle in a sea game scene. And continuing to perform quadtree meshing on the obstacle region at the position of the obstacle, namely performing quadtree meshing on the reference grid in the obstacle region until the side length of the leaf node is equal to the preset minimum grid size. The number of levels between the reference grid and the predetermined minimum grid may be determined according to the size of the obstacle area.
The number of levels between the grids is used for representing the dividing times of the grids, and the more the dividing times are, the more the difference of the number of levels between the two types of grids is. For example, if the side length of the maximum grid is a, the side length of the next level grid is a/2, the side length of the next level grid is a/2/2, and the next level of the corresponding logic diagram is divided by 2. Then for computational convenience (in order to expect to remain an integer regardless of how divided by 2), a is set to a power of 2, based on which the preset maximum mesh size in this embodiment is set to 2maxLThe maxLevel is a preset maximum level number, that is, the level number of the logic diagram; the next level is then 2maxLThe next level is 2maxL. Then the side length can be written as 2 no matter which level down tomIn the form of (1). This m is the hierarchy. For the largest square, m is maxLevel.
In theory, a quadtree can be divided infinitely downwards, and the side length of the lowermost square is smaller the more the tree is divided. To control this minimum side length, a minimum level minLevel is introduced. For the smallest square that is allowed to be divided, m minLevel. The minimum mesh size may be a size corresponding to the minimum level minLevel, or may be larger than the size corresponding to the minimum level minLevel.
The reference grid corresponds to a reference level baseLevel, and the reference grid is a grid which is obtained by dividing all squares into baselevels in advance before dividing the obstacles to obtain a two-dimensional uniform grid, but has a quadtree actual structure. In other words, all small squares are recursively divided until all leaf nodes have a side length equal to 2 before dividing the obstaclebaseL. Such as the meshing process described in (1) above. Through the reference grid, the storage space occupied by the grid nodes can be reduced, and meanwhile, the path searching precision is guaranteed, so that the path searching path is more natural.
Since each node of the quadtree is a square, for the sake of descriptionConveniently, as shown in fig. 6, the four child nodes of a parent node can be divided into four nodes of northeast, southeast, northwest and southwest according to their spatially divided regions, wherein the four nodes of northeast, southeast, northwest and southwest are called sibling nodes, i.e. the same child nodes of the parent node are called sibling nodes with each other. Therefore, the partition of the quadtree nodes is a process of generating child nodes by one node, the two-dimensional space contained in the parent node is divided into four parts by four child nodes, obviously, the side length of the square of the child node is half of that of the square of the parent node, for example, if the side length of the root node a is L in fig. 7, after one partition, the obtained side lengths of the child node a2 and the leaf node a1 are both L/2, and after the child node a2 is continuously divided, the obtained side length of the child node a21 is L/2/2, namely L/22Therefore, for the sake of convenience of calculation, the mesh size of each node in the embodiment of the present invention is an integer power of 2, i.e., L is 2levelWherein level represents power.
For example, for a certain game scene with the size of 16384 × 16384, 16384 is 2 ═ 214Therefore, when the game scene is divided into grids through the quadtree, in order to ensure that the square corresponding to the maximum level maxlevel covers the whole game scene, the maxlevel is 14; assume a minimum allowable partition to 64, i.e. 26Therefore, minlevel should be set to 6. The size of the reference grid may be chosen to be between 214And 26Other integer powers of 2 in between, for example: 27、28、29、210And the like.
This is illustrated here for ease of understanding. As shown in fig. 8, a grid in which oblique lines are overlaid represents an obstacle H. In fig. 8, the size of the grid where the points 8-a, B and C are located is larger, and if the navigation path is a-C-B, it can be seen that the connecting line of the navigation path is steeper at the point C and the turning angle is larger. If the user travels along the navigation path, the virtual object obviously travels in a less natural and more rigid way. 8-B in FIG. 8 is the result of further gridding based on 8-a, and the same obstacle H, point C in the navigation path A-C-B obtained based on the 8-B gridding mode is closer to the obstacle side, so that the navigation of 8-B is performedThe path A-C-B is more gradual and shorter in distance than the navigation path in 8-a. Thus, the path of the virtual object in 8-b is clearly natural compared to 8-a. In addition, 8-C in fig. 8 is further subjected to mesh division on the basis of 8-B, the size of leaf nodes in a walkable region is the same as the size of a leaf node in a region where the obstacle H is located, the mesh obtained based on the quad-tree mesh division mode is degraded into a conventional two-dimensional mesh, at this time, a preset a route searching algorithm is used for searching for the nodes, and the navigation path of the virtual object is obtained as a-C13-C2-C3-B, and compared with 8-B, 8-C improves the mesh division accuracy, but increases the calculation amount. Therefore, in the mesh division, it is necessary to divide the mesh reasonably according to the accuracy requirement of the practical application. As shown in FIG. 9, the walkable area is initially 2 mesh sizemaxLevelStarting to divide until the mesh size of 2 is finally obtainedbaseLevelThe reference grid of (2).
If the obstacle is a dynamic obstacle, the division and restoration of the grid are required to be performed after the position of the dynamic obstacle is changed, and the method specifically comprises the following steps: dividing the grid where the current position of the dynamic obstacle is located to the minimum grid size, and restoring the grid where the position of the dynamic obstacle is located before changing to the size before dividing, such as restoring to the size of a reference grid.
The method for dividing the quadtree grid in the game scene can further divide the quadtree grid into the reference grid of the obstacle area according to the position and the shape of the created obstacle after the obstacle is created in the game scene, namely, the reference grid in the obstacle area is divided into the leaf nodes in a recursion mode, and the side length of each leaf node is 2 which is the preset minimum grid sizeminlevelThereby improving the dividing precision of the barrier area.
After the obstacle area is divided, in order to ensure the accuracy of grid division in the obstacle area as much as possible, after the step (2) is performed, grid nodes corresponding to the obstacle area may be checked, and whether the grid nodes are actually in the obstacle area is checked, based on which the method further includes: checking whether leaf nodes with preset minimum grid sizes are in the area of the obstacle; if so, marking the leaf node as the leaf node of the barrier area; if not, and the brother nodes of the leaf node are not in the obstacle area, deleting the brother nodes of the leaf node and the leaf node, and only keeping the brother nodes to the father node of the leaf node.
As a possible implementation, the step of checking whether a leaf node of a preset minimum grid size is within an obstacle area includes: checking whether the central point of a leaf node with a preset minimum grid size is in an obstacle area; if so, determining that the leaf node is within the obstacle area; if not, performing quadtree division on the leaf node to obtain child nodes of the leaf node, and if the central points of the child nodes of the leaf node are not in the obstacle region, determining that the leaf node is not in the obstacle region; determining that the leaf node is within the obstacle area if the center point of at least one child node of the leaf node is within the obstacle area.
As shown in fig. 10, for a certain leaf node as an example, if the central point O of the leaf node is within the obstacle area, the leaf node is labeled as the leaf node of the obstacle area, and the leaf node is defaulted to cover the obstacle in the obstacle area; if the central point O of the leaf node is not in the obstacle area, then further performing quadtree partitioning on the leaf node at this time to obtain four child nodes of the leaf node, determining whether the four central points X1, X2, X3, and X4 of the four child nodes are in the obstacle area, and if X1, X2, X3, and X4 are not in the obstacle area, that is, if the central point O of the leaf node and the central points X1, X2, X3, and X4 of the four child nodes are not in the obstacle area, determining that the leaf node is not in the obstacle area, that is, the leaf node does not cover the obstacle; conversely, if one of X1, X2, X3, and X4 is within the obstacle area, e.g., point X1 is within the obstacle area, and none of center point O, point X2, point X3, and point X4 is within the obstacle area, then the leaf node is still determined to be within the obstacle area, i.e., the leaf node covers the obstacle. As shown in fig. 11, a schematic diagram of a process of performing quadtree grid division on a reference grid of an obstacle area is shown, by dividing the obstacle area, the size of the grid in the obstacle area is smaller, the position of the obstacle can be more accurately located, and a reliable data base is provided for a road searching operation.
On the basis of fig. 3, another navigation method for virtual objects in a game is provided in the embodiment of the present invention, the execution subject of the method is an electronic device, and the process of determining the start point and the end point of a virtual object is described in detail. As shown in fig. 12, the method includes the steps of:
step S1202, in response to the target point setting operation for a virtual object in the game scene, divides the node at the current position of the virtual object and the node at the position of the target point set by the target point setting operation to the minimum mesh size, respectively. The minimum grid size is a predetermined size, and may be any value between smaller than the reference grid size and larger than the corresponding size of the minimum level.
Specifically, if the node at the current position of the virtual object is a node with a larger grid size, when performing the route searching operation, the center of the node at the current position of the virtual object is taken as a first path point, and at this time, the error between the first path point (starting point) and the actual position of the virtual object is possibly larger; similarly, for the target point (that is, the end point set by the target point setting operation), if the mesh size of the node at the position of the target point is large, if the center of the node is used as the end point, there may be a certain error with the target point setting operation, so that the accuracy of the navigation path obtained by the route searching operation is reduced, and when the virtual object is controlled to move along the navigation path, the virtual object may move unnaturally, which affects the user experience.
Therefore, in step S1202, the node at the current position of the virtual object and the node at the position of the target point set by the target point setting operation are respectively divided into the minimum mesh sizes, so as to improve the precision of the start point and the end point. For example: for a node with a size of 1024x1024, no matter where the virtual ship is located in the node of the current location, the first waypoint is the center of the node, and it is likely that the actual location of the virtual ship is far from the center of the node, which results in a large error between the first waypoint and the location of the virtual ship, when the node with the size of 1024x1024 is divided into the preset minimum mesh size, so the size of the node is 8x8, it is obvious that the error between the center of the node and the location of the virtual ship is obviously reduced for the first waypoint, and the leaf nodes of the current location of the virtual object and the leaf nodes of the location of the target point are respectively divided into the nodes with the preset minimum mesh size by the above steps.
This is illustrated here for ease of understanding. As shown in fig. 13, the current position of the virtual object in the left graph of the arrow in fig. 13 is point a, and the target point set by the target point setting operation is point B, where the positions of point a and point B are both a node with a larger grid size. When searching the road, the first path point is the center O of the node where the point A is located1The last path point is the center O of the node at which the point B is located2When the virtual object is controlled to move according to the navigation path, the virtual object may turn around from the point a and go back to the center O of the node where the point a is located1Then, the central point O of the node at the position of the point B is moved forward2Thereby resulting in a poor game experience for the user. Before the route searching operation, the node at the position of the point a and the node at the position of the point B are respectively divided into nodes with a preset minimum grid size (for example, the size corresponding to the minimum level), as shown in the right-side graph of the arrow in fig. 13, at this time, the center O of the leaf node at the position of the point a is set11As a first path point, i.e. a starting point, and a center point O in the left side of the arrow1In contrast, the first waypoint O at this time11The error from the actual position of the virtual object, point A, is small, and likewise, the center of the target point, point B, point O21Setting an actual position corresponding to the operation to further cater to the target point, wherein when the virtual object is controlled to travel from the point A to the point B, the point A at which the virtual object is currently located is at the point O11With the point as the centre of a circle, radius r (e.g. of a leaf node)Half of the side length) and is therefore considered to be a point and O11The superposition of the points can control the virtual object to directly move from the current position A point to the center O of the target point B point21Point driving without turning back to O11After the point, when the virtual object is driven to the point B, the distance O is used21The point is smaller than the radius r, and the target point is also considered to be reached, and the running is stopped. Therefore, the navigation path obtained in the diagram on the right side of the arrow has little or no error, is natural and not hard, improves the navigation precision of the virtual object, and further improves the game experience of the user.
Step S1204, determining a leaf node containing the central point of the virtual object as a starting point corresponding to the virtual object; and determining a leaf node containing the central point of the target point as a terminal point corresponding to the virtual object.
Step S1206, starting from the node where the starting point is located, performs a preset a-way search algorithm on the quad-tree grid nodes in the walkable area in the game scene to obtain a target node group from the starting point to the end point.
The preset A route searching algorithm determines the adjacent nodes of the current node in the following mode: (1) based on the quad-tree grid nodes in the walkable area in the game scene, searching nodes with grid size larger than or equal to that of the current node in the adjacent direction (which can include eight directions shown in fig. 4) of the current node to obtain a node group to be determined; (2) taking a non-leaf node in the node group to be determined as an intermediate node, and searching a leaf node adjacent to the current node from the intermediate node; (3) and (3) repeating the steps (1) to (3) in each adjacent position direction, thereby obtaining all adjacent nodes of the current node.
It should be noted that, in the preset a search algorithm, the nodes with the grid size larger than or equal to the grid size of the current node are searched in the neighboring position of the current node to obtain all the adjacent leaf nodes performed by the current node, so that the preset a search algorithm is different from the conventional a search algorithm, and compared with the conventional a search algorithm, the adjacent nodes searched by the preset a search algorithm are more accurate, so that the navigation path determined based on the target node group is more accurate, and the accuracy of the virtual object for avoiding the obstacle is improved.
In practical application, the electronic device stores the parent-child relationship of each node, and for a current node where a current path point is located, the electronic device can acquire the parent node of the current node. Based on this, the step of searching for the node with the grid size larger than or equal to the grid size of the current node in the direction of the adjacent position of the current node to obtain the node group to be determined includes: acquiring a father node of a current node and azimuth information of the current node in the father node; for each pre-designated neighboring direction of the current node, determining a node to be determined by performing the following operations: if the direction corresponding to the azimuth information of the current node is opposite to the direction of the adjacent position, determining the node to be determined from the brother nodes of the current node, wherein the mesh size of the brother nodes is equal to that of the current node due to the same father node; if the direction corresponding to the azimuth information of the current node is the same as the adjacent position direction, the adjacent node in the adjacent position direction of the parent node of the current node is taken as the undetermined node of the current node, and the adjacent node is the adjacent node of the parent node, so that the grid size of the adjacent node is larger than that of the current node, and the process is repeated for each adjacent position direction. And finally, forming the undetermined nodes corresponding to the adjacent direction into an undetermined node group of the current node. For ease of understanding, the search for a north neighbor node having a size greater than or equal to the current node is described herein as an example. As shown in fig. 14, the search process is as follows:
step S142, judging whether the current node has a father node, if no father node exists, the current node is a root node, and if no north side adjacent node exists in the current node, ending the searching process; if the current node has a parent node, step S144 is performed.
Step S144, judging whether the current node is a southwest direction or southeast direction child node of the father node, if not, executing step S146; if so, the adjacent node in the north of the current node is the brother node of the current node, and the child nodes in the northwest direction or the northeast direction of the father node are respectively obtained according to the corresponding relation, and the searching process is ended. For example, as shown in fig. 6, if the current node is a south-east child node of the parent node, the north-side neighboring node is a north-east child node, and the current node can be directly obtained through the sibling relationship of the same parent node.
Step S146, a recursion method is adopted to obtain the node adjacent to the north side of the father node of the current node.
Step S148, judging whether the node does not exist or whether the node does not have a child node, if the node exists and the child node exists, executing step S1410; if the node does not exist, the current node does not have a north side adjacent node, the searched node is empty, if the node exists and has no child node, the node is the adjacent node of the current node, namely the node is obtained by searching, and the searching process is finished. As shown in fig. 15, the current node N is a northeast child node of its parent node, at this time, the parent node of the current node N is obtained by an upper stage, and then a north-side neighboring node of the obtained parent node is searched for, and if the node has no child node, the node is the north-side neighboring node of the current node N.
Step S1410, judging whether the current node is a northwest direction or northeast direction child node of the father node, if not, the north side neighbor node does not exist, and ending the searching process; if so, step S1412 is performed.
In step S1412, a southwest or southeast child node of the node is obtained. Specifically, if the current node is a northwest direction or northeast direction child node of the parent node, as shown in fig. 6, the southwest direction or southeast direction child node of the node is the north-side neighbor node of the current node. This is illustrated here for ease of understanding. As shown in fig. 16, where there is a child node in the node 16-a in fig. 16, a north-side neighboring node of the current node is not a node, but is certainly within the node range, because the current node is a northeast-direction child node of its parent node, and then the southeast-direction child node M of the node is searched, here, the current node N is used to search for its parent node by one stage up to the previous stage, and the node N is used to search for its southeast-direction child node M by one stage down to the next stage, therefore, the idea of the recursive method in the embodiment of the present invention is that: if the searching father node searches upwards for n times, the north side adjacent node searches downwards for n times for the child node, if the depth of the child node is not enough for n, the child node of the north side adjacent node searched for the last time is used as the north side adjacent node of the current node, and if the depth of the child node exceeds n, the child node is searched downwards for n times, so that the size of the obtained adjacent node is larger than or equal to the size of the current node. As shown in fig. 16-b, although the node M may be further divided into four sub-nodes, the north-side neighboring node of the current node should be the south-east direction sub-node M of the node, and since the north-side neighboring node of the current node N is searched at this time, all south-side sub-nodes in the south-side sub-nodes of the node M should be found at this time, that is, the final result should be as shown in fig. 16-c.
For the non-leaf nodes in the undetermined node group, namely the intermediate nodes, the intermediate nodes also have child nodes inside, and the intermediate nodes need to continuously search for the adjacent nodes of the current node. The specific searching mode comprises the following steps: and recursively traversing child nodes in the intermediate nodes in the direction opposite to the adjacent position direction in each pre-designated adjacent position direction according to a preset depth-first traversal principle until leaf nodes in the direction opposite to the adjacent position direction are traversed, and determining leaf nodes adjacent to the current node from the traversed leaf nodes. For example, for the above found neighboring nodes on the north side of the current node, depth-first traversal is performed on each neighboring node, and child nodes in the southwest and southeast directions of each neighboring node are recursively accessed until a leaf node is accessed. Because the sizes of the nodes may be different, a plurality of leaf nodes satisfying the condition may be accessed in the traversal process, the leaf nodes are all neighboring nodes on the north side of the given node, and the next path point corresponding to the current node in the direction of the adjacent position, namely the target node, is determined from the plurality of leaf nodes satisfying the condition.
Step S1208, determining a navigation path from the starting point to the end point based on the target node group; the navigation path is composed of path points corresponding to the target nodes in the target node group.
In step S1210, the node at the current position of the virtual object is restored to the mesh node before being divided into the minimum mesh size, and the node at the position of the restoration target point is the mesh node before being divided into the minimum mesh size.
Specifically, after the navigation path is determined, the node where the center point of the virtual object is located and the node where the center point of the target point is located are respectively restored, the node where the current position of the virtual object is obtained is the mesh node divided to the minimum mesh size, and the leaf node where the position of the target point is the mesh node divided to the minimum mesh size.
In step S1212, the virtual object is controlled to move to the end point according to the navigation path. According to the navigation method of the virtual object in the game, the node of the current position of the virtual object and the node of the position of the target point set by the target point setting operation are respectively divided into the minimum grid size, so that the errors of the starting point and the end point corresponding to the virtual object are reduced, and the accurate positioning of the starting point and the end point of the virtual object is improved; after the route searching operation is finished and the navigation path is obtained, the node of the current position of the virtual object and the node of the position of the target point are respectively restored to the grid node before the minimum grid size, so that the influence of the route searching operation on the grid structure is avoided, and the problem of large consumption of grid storage space corresponding to a wide walkable area is effectively solved in a mode that the grid size of leaf nodes of the walkable area is large.
On the basis of fig. 3, another method for navigating a virtual object in a game is further provided in the embodiments of the present invention, which focuses on describing a process of controlling the virtual object to move to an end point according to a navigation path. As shown in fig. 17, the method includes the steps of:
in step S1702, a start point and an end point corresponding to a virtual object in a game scene are determined in response to a target point setting operation for the virtual object.
Step S1704, starting from the node where the starting point is located, executing a routing algorithm on the grid nodes of the walkable area in the game scene to obtain a target node group from the starting point to the end point.
Step 1706, determining a navigation path from the start point to the end point based on the target node group; the navigation path is composed of path points corresponding to the target nodes in the target node group.
In the above steps S1702 to S1706, reference may be made to the foregoing method embodiment, and details of the embodiment of the present invention are not repeated herein.
Step S1708, in response to the virtual object reaching the waypoint event on the navigation path, reading the next waypoint from the navigation path, taking the read waypoint as the current waypoint, and executing steps S1710 to S1712.
Through the aforementioned route searching operation, a navigation path of the virtual object from the starting point to the end point can be obtained, and the navigation path is composed of a series of path points (i.e. target nodes). When the virtual object is controlled to move according to the navigation path, because the relative positions of each path point and the virtual object are different, when the virtual object moves to each path point, a path point event corresponding to the path point needs to be generated, so that when the virtual object reaches the path point, the actual position is attached to the position of the path point as much as possible, and the virtual object is ensured to be natural and not hard in the moving process.
The path point event is different from a conventional set position and speed parameter, where the path point event simulates a player (user) operation, for example, for a first path point, at this time, the virtual object needs to be controlled to start according to a preset direction, therefore, the first path point event needs to include a start instruction and a preset direction in which the first path point points to a second path point, and in the moving process, the read second path point is taken as a current path point, and at this time, the current path point event includes: the acceleration instruction is used for controlling the virtual object to move to the current path point in an accelerated mode; a deceleration instruction for decelerating and moving when the virtual object is close to the current path point; and a steering instruction for controlling the rotating movement direction of the virtual object to move the virtual object toward the current path point when the movement direction of the virtual object deviates from the current path point. If the virtual object is a virtual ship, the moving direction is the direction of the bow, namely the current actual position of the ship is taken as a starting point, rays are taken according to the advancing direction of the virtual ship, and whether the moving direction of the virtual ship is towards the current path point is judged by judging whether the current path point is measured on the rays or not, so that when the virtual ship reaches the current path point, the actual position is attached to the current path point as far as possible.
Step S1710, determining the relative relationship between the current waypoint and the current position of the virtual object.
In practical application, the actual position of the virtual object may be far from the read current path point (i.e., the next path point), and then the error distance between the virtual object and the current path point is relatively large, so that the virtual object cannot actually move to the current path point.
Specifically, in the process that the virtual object moves towards the current path point, the interval frame number is determined according to the advancing speed of the virtual object; and correcting the relative relation between the current path point and the current position of the virtual object according to the determined interval frame number. Wherein the number of interval frames of the virtual object is determined according to the following formula:
Figure BDA0002773855150000251
where N denotes the number of interval frames, and speed denotes the forward speed of the virtual object. Therefore, the higher the moving speed of the virtual object, the smaller the number of interval frames, the more frequent the correction is, and the more accurate the moving direction of the virtual object is. As shown in fig. 18, if no correction is performed, a large error distance exists between the actual position of the virtual object and the target position, which is the position of the path point; after the virtual object is corrected for many times, the actual position of the virtual object is as close as possible to the target position, namely the path point, so that the virtual object is natural and not hard in the moving process, the navigation precision is improved, and the game experience of a user is improved.
Step S1712, the advancing direction and the advancing speed of the virtual object are adjusted according to the relative relationship so that the virtual object advances toward the current path point.
Specifically, the relative relationship is corrected by the above-mentioned number of interval frames, and the advancing direction and the advancing speed of the virtual object are adjusted based on the corrected relative relationship, so that the advancing direction of the virtual object is always towards the current path point, the advancing speed is controlled within a preferred speed range, thereby avoiding the virtual object from causing an accident due to the advancing speed, such as a case of turning the virtual object, if the advancing speed and the advancing direction are not corrected, the virtual object may have a situation of unsatisfactory turning effect due to the advancing direction and the advancing speed, even if the advancing direction can be changed, but a situation of unsatisfactory turning may occur due to too fast advancing speed, therefore, the advancing direction and the advancing speed of the virtual object need to be adjusted by the corrected relative relationship, thereby ensuring that the virtual object reaches each path point in a natural and non-hard state, and, the reached actual position is attached to the corresponding path point as much as possible, and the navigation precision of the virtual object is further improved.
In a possible embodiment, the method further includes: determining a waypoint radius based on the forward speed of the virtual object; and if the distance between the current position of the virtual object and the current path point is less than or equal to the radius of the path point, determining that the virtual object reaches the current path point.
Specifically, considering that a virtual object such as a virtual ship cannot change the advancing direction on site, that is, the virtual ship still advances for a certain distance in the steering process, and the navigation accuracy of the virtual ship on the sea surface does not need to be very accurate, the actual position of the virtual object only needs to be fitted to the position of the path point as much as possible, and does not need to be completely overlapped, so that the radius of the current path point can be determined according to the advancing speed of the virtual object, and when the distance between the actual position of the virtual object and the current path point is smaller than or equal to the radius of the path point, that is, the default virtual object reaches the current path point, that is, the actual position of the virtual object is perfectly fitted to.
Wherein the waypoint radii are calculated according to the following formula:
R=r+k×s (2)
where r is a preset base radius (e.g., half of the current node side length), k is a preset correction coefficient, and s is the forward speed of the virtual object. It should be noted that, the path point radius R is a reserved distance for turning the virtual object, so that the actual position and the path point position are as close as possible, the path point radius R is minimum greater than 0, and s can be half of the forward speed of the virtual object, therefore, the larger the forward speed of the virtual object, the larger the path point radius is, and the larger the reserved distance for turning the virtual object is, as shown in fig. 19, the left diagram is a schematic driving diagram for controlling the virtual object based on the preset base radius R, the right diagram is a schematic driving diagram for controlling the virtual object based on the path point radius R, in the right diagram, the distance from the path point of the virtual object during driving is within R, that is, the center of the virtual object is in the area of the dotted circle, that is, the virtual object is considered to pass through the path point, and the next path point can be continuously driven, which can ensure that the virtual object turns in a better state, and the actual position reached fits the position of the waypoint as closely as possible.
For ease of understanding, a virtual ship is used as an example for illustration. As shown in fig. 20, a certain part of sea area in an ocean scene is divided into grids by a quadtree, wherein a diagonal line coverage area is an area where an island is located, point patterns are filled based on leaf nodes related to the edge position of the area where the island is located, the nodes filled with the point patterns and the area where the island is located form a barrier area, the barrier area cannot walk in the area, and the area outside the barrier area is a walkable area. The navigation path of the virtual ship is composed of a series of path points from a starting point to a terminal point, a grid containing the path points is a target node in the navigation path, the path points are represented by mesh circles in a walkable area, and the virtual ship can move by being attached to each path point in the process of controlling the movement of the virtual ship, so that the virtual ship is naturally not hard in the process of sailing movement, and the game experience of a user is improved, wherein as shown in fig. 21, the specific control movement process of the virtual ship is as follows:
in step S2102, a navigation path of the virtual ship is obtained through a road searching operation, where the navigation path is a path point list in which a series of path points from a start point to an end point of the virtual ship are stored.
In the moving process, each path point in the path point list is read, and a corresponding path point event is executed to control the virtual ship to move to the path point in a natural driving state, so that in the driving process, after the virtual ship reaches the current path point, the next path point in the path list needs to be read until the last path point, namely the terminal point, is read, and the virtual ship is controlled to stop, so that the navigation process is finished.
Step S2104, judging whether a next path point exists in the navigation path; if yes, go to step S2106; if not, the virtual ship is considered to reach the terminal, and the virtual ship executes the stopping operation according to the path point event of the terminal.
And step S2106, reading the next path point from the navigation path, taking the read path point as the current path point, executing a path point event corresponding to the current path point, and controlling the virtual ship to turn so that the advancing direction of the virtual ship is aligned with the current path point.
And step S2108, after the virtual ship turns, stopping turning, and controlling the virtual ship to move to the current path point according to the advancing direction and the advancing speed.
In the process, the interval frame number is determined according to the advancing speed of the virtual ship, the relative relation between the current path point and the current position of the virtual object is corrected according to the determined interval frame number, namely the advancing direction of the virtual ship is corrected, so that the virtual ship can correctly travel to the current path point, the reached actual position is close to the position of the current path point as far as possible, and the navigation precision of the virtual ship is improved.
In addition, determining the path point radius according to the advancing speed of the virtual ship; and when the distance between the actual position of the virtual ship and the current path point is smaller than or equal to the radius of the path point, judging that the virtual ship reaches the current path point at the moment, reading the next path point of the current path point in the path point list, and repeating the control process until the virtual ship reaches the last path point, namely the terminal point.
Step S2110, after the virtual ship reaches the current path point, deleting the current path point from the path point list of the navigation path, and repeating the steps S2104 to S2110 until the virtual ship reaches the last path point, controlling the virtual ship to stop, and ending the navigation process.
Therefore, according to the navigation method of the virtual object in the game, the direction correction mechanism is added in the moving process of the virtual object, so that the virtual object is ensured to move along the navigation path, the moving error is reduced, the virtual object is ensured not to be rigid naturally in the moving process, and the game experience of a user is improved. In addition, in the method, because the quadtree is a common data structure for scene management, the AOI (Area of Interest) function can be further expanded, the cost for re-developing the function is saved, and the method is convenient to popularize and implement in practical application.
Corresponding to the method embodiment, the embodiment of the invention also provides a navigation device of the virtual object in the game, and the game scene is displayed through the electronic equipment. As shown in fig. 22, the apparatus comprises, connected in sequence: a starting point and end point determining module 221, a target node group determining module 222, a navigation path determining module 223 and a moving module 224, wherein the functions of the modules are as follows:
a starting point and end point determining module 221, configured to determine a starting point and an end point corresponding to a virtual object in a game scene in response to a target point setting operation for the virtual object; the grid nodes are nodes in a quadtree formed by dividing the game scene according to parameter information of obstacles in the game scene, and the grid size of leaf nodes of an obstacle area in the game scene is smaller than that of partial leaf nodes of a walkable area.
A target node group determining module 222, configured to execute a routing algorithm on the quadtree grid nodes in the walkable area in the game scene from the node where the starting point is located, to obtain a target node group from the starting point to the end point;
a navigation path determining module 223, configured to determine a navigation path from a starting point to an end point based on the target node group; the navigation path consists of path points corresponding to target nodes in the target node group;
and a moving module 224, configured to control the virtual object to move to the end point according to the navigation path.
The embodiment of the invention provides a navigation device of a virtual object in a game, which responds to the setting operation of a target point of the virtual object in a game scene and determines a starting point and an end point corresponding to the virtual object; starting from a node where a starting point is located, executing a routing algorithm on the quad-tree grid nodes of a walkable area in a game scene to obtain a target node group from the starting point to a terminal point; determining a navigation path from a starting point to an end point based on the target node group; and controlling the virtual object to move to the end point according to the navigation path. In the method, the grid nodes are nodes in a quadtree formed by dividing a game scene according to parameter information of obstacles in the game scene, the grid size of leaf nodes of an obstacle area in the game scene is smaller than that of partial leaf nodes of a walkable area, and the division mode with larger grid size of the leaf nodes of the walkable area can effectively relieve the problem of larger consumption of grid storage space corresponding to the wide walkable area; and in the process of searching the route, because the grid size of the leaf node is smaller than that of the father node, the searched navigation route can be ensured to be more preferable by searching the leaf node in the neighbor direction and then determining the route point, and the navigation effect of the virtual object is effectively improved.
Further, the starting point and end point determining module 221 is further configured to: respectively dividing the node of the current position of the virtual object and the node of the position of the target point set by the target point setting operation to the minimum mesh size; determining a leaf node containing the central point of the virtual object as a starting point corresponding to the virtual object; determining a leaf node containing the central point of the target point as a terminal point corresponding to the virtual object; the apparatus is also configured to: and when the navigation path is determined, restoring the node of the current position of the virtual object to the grid node before the grid node is divided to the minimum grid size, and restoring the node of the position of the target point to the grid node before the grid node is divided to the minimum grid size.
Further, taking the routing algorithm as an a-search algorithm as an example, the a-search algorithm determines the neighboring nodes of the current node by the following method: based on the quad-tree grid nodes in the walkable area in the game scene, searching nodes with the grid size larger than or equal to that of the current node in the direction of the adjacent position of the current node to obtain a node group to be determined; taking a non-leaf node in the node group to be determined as an intermediate node, and searching a leaf node adjacent to the current node from the intermediate node; and taking the searched leaf nodes and nodes except the intermediate node in the pending node group as the adjacent nodes of the current node.
Further, the electronic device stores the parent-child relationship of each node, and the searching for the node with the grid size larger than or equal to the grid size of the current node in the direction of the adjacent position of the current node to obtain the node group to be determined includes: acquiring a father node of a current node and azimuth information of the current node in the father node; for each pre-designated neighboring direction, determining a node to be determined by performing the following operations: if the direction corresponding to the azimuth information is opposite to the direction of the adjacent position, determining a node to be determined from brother nodes of the current node; the grid size of the brother node is equal to the grid size of the current node; if the direction corresponding to the azimuth information is the same as the adjacent position direction, taking the adjacent node positioned in the adjacent position direction of the father node as the undetermined node of the current node; the grid size of the adjacent node is larger than that of the current node; and forming the undetermined nodes corresponding to the adjacent direction into an undetermined node group of the current node.
Further, the searching for the leaf node adjacent to the current node from the intermediate node includes: recursively traversing child nodes in the middle node in the direction opposite to the direction of the adjacent positions in each preassigned adjacent position direction according to a preset depth-first traversal principle until leaf nodes in the direction opposite to the direction of the adjacent positions are traversed; and determining leaf nodes adjacent to the current node from the traversed leaf nodes.
Further, the apparatus further includes a mesh dividing module, connected to the starting point and end point determining module 221, configured to: responding to the grid creating operation aiming at the game scene, and carrying out quad-tree grid division on the barrier region of the barrier in the game scene by taking the preset maximum grid size as the side length of a root node until the side length of the barrier region divided to a leaf node is equal to the preset minimum grid size. Further, the mesh division module is also used for responding to mesh creation operation aiming at the game scene in the initial state, taking the preset maximum mesh size as the side length of a root node, and carrying out quad-tree mesh division on the game scene until the game scene is divided into reference meshes of the quad-tree; wherein, the game scenes in the initial state are all walkable areas; responding to an obstacle creating operation aiming at a game scene, creating an obstacle in the game scene, and carrying out quad-tree grid division on a reference grid of an obstacle area of the obstacle until the side length of a leaf node is equal to a preset minimum grid size; the size of the reference grid is between a preset maximum grid size and a preset minimum grid size.
Further, the mesh division module is further configured to: checking whether leaf nodes with preset minimum grid sizes are in the area of the obstacle; if so, marking the leaf node as the leaf node of the barrier area; if not, and the brother nodes of the leaf nodes are not in the obstacle area, deleting the leaf nodes and the brother nodes of the leaf nodes.
Further, the mesh division module is further configured to: checking whether the central point of a leaf node with a preset minimum grid size is in an obstacle area; if so, determining that the leaf node is within the obstacle area; if not, performing quadtree division on the leaf node to obtain child nodes of the leaf node, and if the central points of the child nodes of the leaf node are not in the obstacle region, determining that the leaf node is not in the obstacle region; determining that the leaf node is within the obstacle area if the center point of at least one child node of the leaf node is within the obstacle area.
Further, the moving module 224 is further configured to: in response to a path point event that the virtual object reaches the navigation path, reading the next path point from the navigation path, taking the read path point as the current path point, and executing the following operations: determining the relative relation between the current path point and the current position of the virtual object; and adjusting the advancing direction and the advancing speed of the virtual object according to the relative relation so as to enable the virtual object to advance towards the current path point.
Further, the moving module 224 is further configured to: determining the interval frame number according to the advancing speed of the virtual object; correcting the relative relation between the current path point and the current position of the virtual object according to the determined interval frame number; and adjusting the advancing direction and the advancing speed of the virtual object according to the corrected relative relation.
Further, the above apparatus is further configured to: determining a waypoint radius based on the forward speed of the virtual object; and if the distance between the current position of the virtual object and the current path point is less than or equal to the radius of the path point, determining that the virtual object reaches the current path point.
Further, the above apparatus is further configured to: and calculating the radius R of the path point, which is R + k × s, wherein R is a preset base radius, k is a preset correction coefficient, and s is the advancing speed of the virtual object.
Further, the game scene is a sea scene, and the virtual object is a virtual ship; the mesh size of each node is an integer power of 2.
The navigation device for the virtual object in the game provided by the embodiment of the invention has the same technical characteristics as the navigation method for the virtual object in the game provided by the embodiment, so that the same technical problems can be solved, and the same technical effects can be achieved.
The embodiment of the invention also provides electronic equipment which comprises a processor and a memory, wherein the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to realize the navigation method of the virtual object in the game.
Referring to fig. 23, the electronic device includes a processor 230 and a memory 231, the memory 231 stores machine executable instructions capable of being executed by the processor 230, and the processor 230 executes the machine executable instructions to implement the navigation method of the virtual object in the game.
Further, the electronic device shown in fig. 23 further includes a bus 232 and a communication interface 233, and the processor 230, the communication interface 233, and the memory 231 are connected through the bus 232.
The Memory 231 may include a high-speed Random Access Memory (RAM) and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 233 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus 232 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Enhanced Industry Standard Architecture) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 23, but that does not indicate only one bus or one type of bus.
Processor 230 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 230. The Processor 230 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 231, and the processor 230 reads the information in the memory 231 and completes the steps of the method of the foregoing embodiment in combination with the hardware thereof.
The present embodiments also provide a machine-readable storage medium having stored thereon machine-executable instructions that, when invoked and executed by a processor, cause the processor to implement the method of navigating virtual objects in a game described above.
The method and apparatus for navigating a virtual object in a game and the computer program product of an electronic device provided in the embodiments of the present invention include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method described in the foregoing method embodiments, and specific implementation may refer to the method embodiments, and will not be described herein again. The above-mentioned techniques involve the concepts of "reaching", "directing at a certain point", and the like. Conversion to a mathematical model, arrival means that two points coincide (identical in position), and direction alignment to a point means that the point is on a ray. However, in computer practice, these mathematical models are too ideal, for example, two points are identical, and since the positions are stored as floating point numbers, the positions of a (0,0.00001) and B (0,0.0000002) are not the same. But such small differences can be considered the same. Therefore, in order to avoid this, the coincidence of a and B is often regarded as a being within a circle having a radius r and having B as a center.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In addition, in the description of the embodiments of the present invention, unless otherwise explicitly specified or limited, the terms "mounted," "connected," and "connected" are to be construed broadly, e.g., as meaning either a fixed connection, a removable connection, or an integral connection; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meanings of the above terms in the present invention can be understood in specific cases to those skilled in the art.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (17)

1. A method for navigating a virtual object in a game, wherein a game scene is displayed through an electronic device, the method comprising:
responding to a target point setting operation aiming at a virtual object in the game scene, and determining a starting point and an end point corresponding to the virtual object;
starting from a node where the starting point is located, executing a routing algorithm on grid nodes of a walkable area in the game scene to obtain a target node group from the starting point to the terminal point, wherein the grid nodes are nodes in a quadtree formed by dividing the game scene according to parameter information of obstacles in the game scene, and the grid size of leaf nodes of the obstacle area in the game scene is smaller than that of partial leaf nodes of the walkable area;
determining a navigation path from the starting point to the end point based on the target node group; the navigation path consists of path points corresponding to target nodes in the target node group;
and controlling the virtual object to move to the end point according to the navigation path.
2. The method of claim 1, wherein the mesh nodes are nodes in a quadtree formed by dividing the game scene according to parameter information of obstacles in the game scene, and the method comprises the following steps:
responding to the grid creating operation aiming at the game scene, and carrying out quad-tree grid division on the barrier region of the barrier in the game scene by taking the preset maximum grid size as the side length of a root node until the side length of the barrier region divided to a leaf node is equal to the preset minimum grid size.
3. The method for navigating the virtual object in the game according to claim 2, wherein in response to the mesh creation operation for the game scene, the method for performing the quadtree meshing on the barrier area of the barrier in the game scene with a preset maximum mesh size as a side length of a root node until the side length for dividing the barrier area to a leaf node is equal to a preset minimum mesh size comprises:
responding to the mesh creating operation aiming at the game scene in the initial state, and carrying out quad-tree mesh division on the game scene by taking the preset maximum mesh size as the side length of a root node until the game scene is divided into a reference mesh of a quad-tree; wherein the game scenes in the initial state are all walkable areas;
responding to an obstacle creating operation aiming at the game scene, creating an obstacle in the game scene, and carrying out quad-tree meshing on a reference grid of an obstacle area of the obstacle until the side length of a leaf node is equal to a preset minimum grid size;
wherein the size of the reference grid is between the preset maximum grid size and the preset minimum grid size.
4. The method of navigating a virtual object in a game of claim 2, wherein the method further comprises:
checking whether the leaf node of a preset minimum grid size is within the obstacle area;
if so, marking the leaf node as the leaf node of the barrier area;
and if not, deleting the leaf node and the brother nodes of the leaf node, wherein the brother nodes of the leaf node are not in the obstacle area.
5. The method for navigating a virtual object in a game according to claim 4, wherein the step of checking whether the leaf node of a preset minimum grid size is within the obstacle area comprises:
checking whether a center point of the leaf node of a preset minimum grid size is within the obstacle area;
if so, determining that the leaf node is within the obstacle area;
if not, performing quadtree division on the leaf node to obtain a child node of the leaf node, and if the central point of the child node of the leaf node is not in the obstacle region, determining that the leaf node is not in the obstacle region; determining that the leaf node is within the obstacle area if a center point of at least one child node of the leaf node is within the obstacle area.
6. The method of claim 1, wherein the step of determining the start and end points of the virtual object comprises:
dividing the node of the current position of the virtual object and the node of the position of the target point set by the target point setting operation to the minimum mesh size respectively;
determining a leaf node containing the central point of the virtual object as a starting point corresponding to the virtual object; and determining a leaf node containing the central point of the target point as a terminal point corresponding to the virtual object.
7. The method of navigating a virtual object in a game of claim 6, wherein the method further comprises: and when the navigation path is determined, restoring the node of the current position of the virtual object to the grid node before the minimum grid size, and restoring the node of the position of the target point to the grid node before the minimum grid size.
8. The method of navigating a virtual object in a game of claim 1, wherein the routing algorithm is an a-search algorithm that determines the neighbor nodes of the current node by:
based on the quad-tree grid nodes in the walkable area in the game scene, searching nodes with grid size larger than or equal to that of the current node in the direction of the adjacent position of the current node to obtain a node group to be determined;
taking a non-leaf node in the undetermined node group as an intermediate node, and searching a leaf node adjacent to the current node from the intermediate node;
and taking the searched leaf nodes and the nodes except the intermediate node in the pending node group as the adjacent nodes of the current node.
9. The method of navigating a virtual object in a game of claim 8, wherein the electronic device maintains a parent-child relationship of each node; searching nodes with the grid size larger than or equal to the grid size of the current node in the direction of the adjacent position of the current node to obtain a node group to be determined, wherein the step comprises the following steps:
acquiring a father node of the current node and azimuth information of the current node in the father node;
for each pre-designated neighboring direction, determining a node to be determined by performing the following operations: if the direction corresponding to the azimuth information is opposite to the direction of the adjacent position, determining a node to be determined from the brother node of the current node; the grid size of the brother node is equal to the grid size of the current node; if the direction corresponding to the azimuth information is the same as the adjacent position direction, taking the adjacent node in the adjacent position direction of the father node as the undetermined node of the current node; the grid size of the adjacent node is larger than that of the current node;
and forming the undetermined nodes corresponding to the adjacent direction into an undetermined node group of the current node.
10. The method of navigating a virtual object in a game of claim 8, wherein the step of searching for leaf nodes adjacent to the current node from the intermediate node comprises:
recursively traversing child nodes in the intermediate nodes in the direction opposite to the direction of the adjacent positions in each preassigned adjacent position direction according to a preset depth-first traversal principle until leaf nodes in the direction opposite to the adjacent position direction are traversed;
and determining leaf nodes adjacent to the current node from the traversed leaf nodes.
11. The method for navigating a virtual object in a game according to claim 1, wherein the step of controlling the virtual object to move to the end point according to the navigation path comprises:
in response to a path point event that the virtual object reaches the navigation path, reading the next path point from the navigation path, taking the read path point as the current path point, and executing the following operations:
determining the relative relationship between the current path point and the current position of the virtual object;
and adjusting the advancing direction and the advancing speed of the virtual object according to the relative relationship so as to advance the virtual object towards the current path point.
12. The method of navigating a virtual object in a game of claim 11, wherein the step of determining the relative relationship of the current waypoint to the current location of the virtual object comprises: determining the interval frame number according to the advancing speed of the virtual object; correcting the relative relation between the current path point and the current position of the virtual object according to the determined number of the interval frames;
adjusting the advancing direction and the advancing speed of the virtual object according to the relative relationship, comprising: and adjusting the advancing direction and the advancing speed of the virtual object according to the corrected relative relation.
13. The method of navigating a virtual object in a game of claim 11, wherein the method further comprises:
determining a waypoint radius based on the forward speed of the virtual object;
and if the distance between the current position of the virtual object and the current path point is smaller than or equal to the radius of the path point, determining that the virtual object reaches the current path point.
14. The method of navigating a virtual object in a game of claim 13, wherein the step of determining a waypoint radius based on the speed of advance of the virtual object comprises:
and calculating the radius R of the path point, which is R + k × s, wherein R is a preset base radius, k is a preset correction coefficient, and s is the advancing speed of the virtual object.
15. The method of navigating a virtual object in a game according to any one of claims 1 to 14, wherein the game scene is a sea scene and the virtual object is a virtual ship; the mesh size of each node is an integer power of 2.
16. An electronic device comprising a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement the method of navigating a virtual object in a game according to any one of claims 1 to 15.
17. A computer-readable storage medium having stored thereon computer-executable instructions which, when invoked and executed by a processor, cause the processor to implement a method of navigating a virtual object in a game as claimed in any one of claims 1 to 15.
CN202011258658.4A 2020-11-11 2020-11-11 Navigation method of virtual object in game and electronic equipment Pending CN112370788A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011258658.4A CN112370788A (en) 2020-11-11 2020-11-11 Navigation method of virtual object in game and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011258658.4A CN112370788A (en) 2020-11-11 2020-11-11 Navigation method of virtual object in game and electronic equipment

Publications (1)

Publication Number Publication Date
CN112370788A true CN112370788A (en) 2021-02-19

Family

ID=74582951

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011258658.4A Pending CN112370788A (en) 2020-11-11 2020-11-11 Navigation method of virtual object in game and electronic equipment

Country Status (1)

Country Link
CN (1) CN112370788A (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112957736A (en) * 2021-03-03 2021-06-15 网易(杭州)网络有限公司 Method and device for controlling virtual object in game and electronic equipment
CN113144607A (en) * 2021-04-21 2021-07-23 网易(杭州)网络有限公司 Path finding method and device for virtual object in game and electronic equipment
CN113413601A (en) * 2021-07-16 2021-09-21 上海幻电信息科技有限公司 Path finding method and device
CN113476848A (en) * 2021-07-08 2021-10-08 网易(杭州)网络有限公司 Method and device for generating tree chain map, storage medium and electronic equipment
CN114152260A (en) * 2021-12-15 2022-03-08 杨银 Virtual path navigation method and system applied to virtual reality
CN115860304A (en) * 2023-02-27 2023-03-28 江西少科智能建造科技有限公司 Ground warehouse evacuation route planning method, system, storage medium and equipment
CN116036601A (en) * 2023-01-28 2023-05-02 腾讯科技(深圳)有限公司 Game processing method and device, computer equipment and storage medium
CN116036603A (en) * 2023-01-28 2023-05-02 腾讯科技(深圳)有限公司 Data processing method, device, computer and readable storage medium
WO2023109326A1 (en) * 2021-12-14 2023-06-22 腾讯科技(深圳)有限公司 Method and apparatus for determining navigation path, and device, storage medium and program product
CN116603239A (en) * 2023-07-20 2023-08-18 腾讯科技(深圳)有限公司 Data processing method and device and related equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080220862A1 (en) * 2007-03-06 2008-09-11 Aiseek Ltd. System and method for the generation of navigation graphs in real-time
US20140334713A1 (en) * 2013-05-07 2014-11-13 Samsung Techwin Co., Ltd. Method and apparatus for constructing map for mobile robot
CN106964156A (en) * 2017-03-24 2017-07-21 腾讯科技(深圳)有限公司 A kind of method for searching and device
CN111013146A (en) * 2019-12-25 2020-04-17 北京像素软件科技股份有限公司 Dynamically modifiable way-finding navigation method and device for ultra-large map
CN111111172A (en) * 2019-12-02 2020-05-08 网易(杭州)网络有限公司 Method and device for processing ground surface of game scene, processor and electronic device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080220862A1 (en) * 2007-03-06 2008-09-11 Aiseek Ltd. System and method for the generation of navigation graphs in real-time
US20140334713A1 (en) * 2013-05-07 2014-11-13 Samsung Techwin Co., Ltd. Method and apparatus for constructing map for mobile robot
CN106964156A (en) * 2017-03-24 2017-07-21 腾讯科技(深圳)有限公司 A kind of method for searching and device
CN111111172A (en) * 2019-12-02 2020-05-08 网易(杭州)网络有限公司 Method and device for processing ground surface of game scene, processor and electronic device
CN111013146A (en) * 2019-12-25 2020-04-17 北京像素软件科技股份有限公司 Dynamically modifiable way-finding navigation method and device for ultra-large map

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112957736A (en) * 2021-03-03 2021-06-15 网易(杭州)网络有限公司 Method and device for controlling virtual object in game and electronic equipment
CN113144607A (en) * 2021-04-21 2021-07-23 网易(杭州)网络有限公司 Path finding method and device for virtual object in game and electronic equipment
CN113476848A (en) * 2021-07-08 2021-10-08 网易(杭州)网络有限公司 Method and device for generating tree chain map, storage medium and electronic equipment
CN113476848B (en) * 2021-07-08 2023-11-17 网易(杭州)网络有限公司 Tree chain map generation method and device, storage medium and electronic equipment
CN113413601A (en) * 2021-07-16 2021-09-21 上海幻电信息科技有限公司 Path finding method and device
CN113413601B (en) * 2021-07-16 2024-01-02 上海幻电信息科技有限公司 Road searching method and device
WO2023109326A1 (en) * 2021-12-14 2023-06-22 腾讯科技(深圳)有限公司 Method and apparatus for determining navigation path, and device, storage medium and program product
CN114152260A (en) * 2021-12-15 2022-03-08 杨银 Virtual path navigation method and system applied to virtual reality
CN116036603A (en) * 2023-01-28 2023-05-02 腾讯科技(深圳)有限公司 Data processing method, device, computer and readable storage medium
CN116036603B (en) * 2023-01-28 2023-05-30 腾讯科技(深圳)有限公司 Data processing method, device, computer and readable storage medium
CN116036601A (en) * 2023-01-28 2023-05-02 腾讯科技(深圳)有限公司 Game processing method and device, computer equipment and storage medium
CN115860304A (en) * 2023-02-27 2023-03-28 江西少科智能建造科技有限公司 Ground warehouse evacuation route planning method, system, storage medium and equipment
CN116603239A (en) * 2023-07-20 2023-08-18 腾讯科技(深圳)有限公司 Data processing method and device and related equipment
CN116603239B (en) * 2023-07-20 2023-10-03 腾讯科技(深圳)有限公司 Data processing method and device and related equipment

Similar Documents

Publication Publication Date Title
CN112370788A (en) Navigation method of virtual object in game and electronic equipment
CN110108284A (en) A kind of quick planing method of no-manned plane three-dimensional track for taking complex environment constraint into account
CN107744663B (en) Path finding method and device for artificial intelligence AI unit
CN108444490B (en) Robot path planning method based on depth fusion of visible view and A-x algorithm
CN109737965B (en) Method for optimally selecting navigation path in three-dimensional virtual scene
CN116036604B (en) Data processing method, device, computer and readable storage medium
Huber Computing straight skeletons and motorcycle graphs: theory and practice
CN113144607A (en) Path finding method and device for virtual object in game and electronic equipment
CN102306106A (en) Method and system for automatically generating navigation chart in virtual space, and pathfinding method and system
CN114404984A (en) Data processing method and device for game scene, computer equipment and medium
CN113244619B (en) Data processing method, device, equipment and storage medium
CN112965500B (en) Path planning method and device with must-pass point set and additional hard constraints
CN115779424B (en) Navigation grid path finding method, device, equipment and medium
CN116664793A (en) Three-dimensional modeling method and device for hydraulic building excavation slope release and electronic equipment
CN116839609A (en) Full coverage path planning method, device and computer readable storage medium
CN116109773A (en) Three-dimensional slag field modeling method, system, terminal and medium
CN116167235A (en) Road network model generation method, device and equipment
CN115957505A (en) Path finding method and device in game, computer equipment and readable storage medium
CN112272354B (en) Cloud mobile phone equipment distribution method and device
CN114283148A (en) Road element extraction method and device, storage medium and electronic equipment
CN115170747A (en) Path planning method and device, electronic equipment and computer storage medium
CN111494958A (en) Method and device for randomly generating maze map
CN117557585B (en) Land parcel segmentation method, system, electronic equipment and storage medium
CN117128974B (en) Navigation route searching method and device
CN115601521B (en) Path processing method, electronic device, storage medium and program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination