Non-player character control methods, devices, electronic devices and storage media

By acquiring the path to be moved and adjusting the speed and direction, and combining offset speed and acceleration to optimize the movement of non-player characters in the game scene, the problem of overly rigid movement in existing technologies is solved, achieving a more natural movement effect, adapting to complex game logic and avoiding conflicts with the physics engine.

CN115920400BActive Publication Date: 2026-05-05NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NETEASE (HANGZHOU) NETWORK CO LTD
Filing Date
2022-12-19
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In existing technologies, the movement of non-player characters in game scenes is too rigid and cannot adapt to the complex game logic requirements. Furthermore, traditional control methods conflict with physics engines, resulting in unnatural movement.

Method used

By acquiring the movement path of non-player characters in the game scene, and adjusting the speed direction using offset speed and preset acceleration, the non-player characters can move more naturally when changing paths. This includes smoothing out sub-path and obstacle information, and optimizing the movement path by combining displacement triggers and movement strategies.

Benefits of technology

It enables non-player characters to move more naturally and realistically in the game scene, improving the gaming experience, adapting to the needs of complex game logic, and avoiding the shortcomings of traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115920400B_ABST
    Figure CN115920400B_ABST
Patent Text Reader

Abstract

This application discloses a method, device, electronic device, and storage medium for controlling a non-player character. This application can obtain a movement path for a non-player character in a game scene, the path including multiple sub-paths; determine an offset speed based on the speed of the non-player character in a first direction at the end of a first sub-path and the speed along a second sub-path; predict the offset distance of the non-player character based on the offset speed and a preset acceleration; and adjust the speed of the non-player character in the first direction at the end of the first sub-path based on the offset distance, so that the non-player character moves along a second sub-path by using the adjusted speed in the first direction and the speed in the second direction corresponding to the starting point of a preset second sub-path, where the second direction is the direction along the second sub-path. This application improves the movement of the non-player character in the game scene, making its movement more natural.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computers, and more specifically to a method, apparatus, electronic device, and storage medium for controlling a non-player character. Background Technology

[0002] The game features various non-player characters (NPCs), allowing users to control virtual avatars and interact with them for a sense of participation. To enrich the game's storyline, some NPCs can move freely within the game environment.

[0003] However, currently, when controlling NPC movement, the path of the NPC's movement is first obtained, and the position of the NPC on the path is preset at a fixed time. In this way, the position change of the NPC corresponding to a continuous period of time can be obtained, thereby realizing the control of the NPC's movement in the game scene. However, the above method makes the NPC have a fixed speed when moving, which makes the movement of the NPC in the game scene rather rigid. Summary of the Invention

[0004] This application provides a method, device, electronic device, and storage medium for controlling non-player characters, which can improve the movement of non-player characters in game scenes to make their movement more natural.

[0005] This application provides a method for controlling a non-player character, including:

[0006] Obtain the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in any two adjacent sub-paths.

[0007] The offset speed is determined based on the speed of the non-player character in the first direction when the character is at the end of the first sub-path and the speed of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the multiple sub-paths except the last one. The second sub-path is the sub-path after the first sub-path.

[0008] Based on the offset velocity and preset acceleration, predict the offset distance of non-player characters. The preset acceleration is the acceleration set in the game scene.

[0009] Based on the offset distance, the speed of the non-player character at the end of the first sub-path in the first direction is adjusted. By using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path, the non-player character is controlled to move along the second sub-path. The second direction is the direction along the second sub-path.

[0010] This application embodiment also provides a control device for a non-player character, including:

[0011] The acquisition unit is used to acquire the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in two adjacent sub-paths.

[0012] A speed determination unit is used to determine an offset speed based on the speed of the non-player character in a first direction when the character is at the end of the first sub-path and the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the plurality of sub-paths except the last sub-path. The second sub-path is the sub-path following the first sub-path.

[0013] The offset determination unit is used to predict the offset distance of non-player characters based on the offset velocity and the preset acceleration, which is the acceleration set in the game scene.

[0014] The adjustment unit is used to adjust the speed of the non-player character in the first direction at the end of the first sub-path based on the offset distance, so as to control the non-player character to move along the second sub-path by using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path. The second direction is the direction along the second sub-path.

[0015] In some embodiments, the velocity in the first direction includes a non-offset velocity, the direction of which is the same as the second direction. Based on the offset distance, the velocity in the first direction of the non-player character at the end of the first sub-path is adjusted so that the non-player character can be controlled to move along the second sub-path by using the adjusted velocity in the first direction and the velocity in the second direction corresponding to the preset start point of the second sub-path. This includes:

[0016] If the offset distance is outside the preset range, the offset speed is eliminated;

[0017] Based on the non-player character's non-offset velocity at the end of the first sub-path and the velocity in the second direction corresponding to the preset start point of the second sub-path, control the non-player character to move along the second sub-path;

[0018] If the offset distance is within the preset range, the non-player character is controlled to move along the second sub-path based on the speed of the non-player character in the first direction and the speed of the second direction at the end of the first sub-path.

[0019] In some embodiments, the second sub-path carries at least one movement information, including the movement type of the non-player character, and the starting point and ending point corresponding to the movement type. After adjusting the speed of the non-player character in a first direction at the end of the first sub-path based on the offset distance, and controlling the non-player character to move along the second sub-path using the adjusted speed in the first direction and the speed in a second direction corresponding to the preset starting point of the second sub-path, the method further includes:

[0020] Obtain the real-time position of a non-player character moving along the second sub-path, and at least one piece of movement information containing target movement information corresponding to the real-time position;

[0021] Based on the movement type in the target movement information, control the non-player character to move from the target starting point to the target ending point. The target starting point and target ending point are the starting point and ending point corresponding to the movement type in the target movement information.

[0022] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0023] When the movement type in the target movement information is jump type, calculate the free fall time corresponding to the vertical height. The vertical height is the height difference between the real-time position and the target endpoint. The target endpoint is the endpoint corresponding to the movement type in the target movement information.

[0024] Based on the free fall time and the real-time velocity of the non-player character at its real-time position, determine the horizontal displacement distance of the non-player character during the free fall time.

[0025] Based on the displacement distance, adjust the target start point and target end point located on the second sub-path so that the horizontal distance between the adjusted target start point and target end point is equal to the displacement distance. The target start point is the start point corresponding to the movement type in the target movement information.

[0026] Based on the real-time speed of the non-player character at the adjusted target starting point, control the non-player character to jump from the adjusted target starting point to the adjusted target endpoint.

[0027] In some embodiments, the velocity in the first direction includes a non-offset velocity, and before determining the displacement distance of the non-player character in the horizontal direction during the free fall time based on the free fall time and the real-time velocity of the non-player character at the real-time position, it further includes:

[0028] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the first real-time non-offset velocity of the non-player character at the real-time position;

[0029] Based on the first real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the real-time position;

[0030] Before controlling the non-player character to jump from the adjusted target starting point to the adjusted target endpoint based on the non-player character's real-time speed at the adjusted target starting point, the following is also included:

[0031] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the second real-time non-offset velocity of the non-player character at the adjusted target starting point;

[0032] Based on the second real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the adjusted target starting point.

[0033] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0034] If the movement type in the target movement information is the target movement type, obtain the real-time target movement position of the non-player character moving from the target starting point to the target ending point. The target movement type is the movement type corresponding to climbing over obstacles.

[0035] Determine the real-time distance between the target's current location and the second sub-path;

[0036] If the real-time distance is outside the preset range, adjust the movement direction of the non-player character at the real-time target movement position so that the non-player character moves towards the target endpoint.

[0037] In some embodiments, after adjusting the movement direction of the non-player character at the real-time target movement position if the real-time distance is outside a preset range, the method further includes:

[0038] Get the number of adjustments. The number of adjustments is the number of times a non-player character adjusts the movement direction when moving from the target starting point to the target ending point.

[0039] If the number of adjustments exceeds the preset number, the route to be moved is updated. The updated route is the path between the target starting point and the end point of the original route.

[0040] In some embodiments, after obtaining the number of adjustments, the method further includes:

[0041] If the number of adjustments exceeds the preset number, the weight corresponding to the target path is determined. The target path is the path between the target start point and the target end point in the second sub-path. The weight represents the difficulty of controlling the non-player character to move along the target path.

[0042] If the number of adjustments exceeds the preset limit, update the route to be moved, including:

[0043] Update the route to be moved based on the weights. The updated route does not include the target path.

[0044] In some embodiments, the game scene includes a displacement trigger, which carries a triggering condition and a displacement strategy, and further includes:

[0045] Get the location of non-player characters in the game scene;

[0046] If the position meets the triggering conditions, the non-player character will be controlled to move within the area controlled by the displacement trigger according to the displacement strategy.

[0047] In some embodiments, the displacement strategy includes a displacement direction. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including:

[0048] If the position meets the triggering conditions, the non-player character is controlled to move in the direction of displacement according to the displacement strategy until the non-player character leaves the area controlled by the displacement trigger.

[0049] In some embodiments, the area controlled by the displacement trigger includes a control path, which facilitates the non-player character's escape from the area controlled by the displacement trigger. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to a displacement strategy, including:

[0050] If the location meets the triggering conditions, determine the opening status of the control path;

[0051] Depending on the activation status, non-player characters are controlled to move along the controlled path according to the displacement strategy.

[0052] In some embodiments, before obtaining the movement route of a non-player character in the game scene, the process includes:

[0053] Obtain the starting point and ending point of movement for non-player characters in the game scene, as well as the midpoint between the starting point and the ending point;

[0054] Based on the starting point, intermediate point, and ending point of the movement, a sub-path is determined. A sub-path is a path between two adjacent points, which are any two adjacent points among the starting point, intermediate point, and ending point of the movement.

[0055] Determine the route to be moved based on all sub-paths.

[0056] In some embodiments, determining the route to be moved based on all sub-paths includes:

[0057] Obtain information about obstacles between the target sub-path, the next sub-path of the target sub-path, the start point of the target sub-path, and the end point of the next sub-path. The target sub-path is any sub-path among all sub-paths.

[0058] Based on the starting point of the target sub-path, the ending point of the next sub-path, and obstacle information, the target sub-path and the next sub-path are smoothed to obtain the smoothed sub-path.

[0059] Determine the route to be moved based on all the smoothed sub-paths.

[0060] This application also provides an electronic device, including a memory storing multiple instructions; the processor loads the instructions from the memory to execute the steps in any of the non-player character control methods provided in this application.

[0061] This application also provides a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute steps in any of the non-player character control methods provided in this application.

[0062] This application embodiment can obtain the movement route of a non-player character in a game scene. The movement route includes multiple sub-paths, where the endpoint of the preceding sub-path is connected to the starting point of the following sub-path in any two adjacent sub-paths. An offset speed is determined based on the non-player character's velocity in a first direction at the endpoint of the first sub-path and the second sub-path. The offset speed is perpendicular to the second sub-path, and the first direction is along the first sub-path. The first sub-path is any sub-path other than the last one among the multiple sub-paths, and the second sub-path is the sub-path following the first sub-path. The offset distance of the non-player character is predicted based on the offset speed and a preset acceleration, where the preset acceleration is the acceleration set in the game scene. Based on the offset distance, the velocity in the first direction of the non-player character at the endpoint of the first sub-path is adjusted. The adjusted velocity in the first direction and the velocity in the second direction corresponding to the preset starting point of the second sub-path are used to control the non-player character's movement along the second sub-path, where the second direction is along the second sub-path.

[0063] In this application, the non-player character has a velocity in a first direction when it moves to the end of the first sub-path. That is, the non-player character in the game scene has inertia. Since the first sub-path and the second sub-path may not be in the same direction, the velocity in the first direction has an offset velocity that deviates from the second sub-path. The offset distance of the non-player character under the action of the offset velocity and the preset acceleration is predicted. The velocity in the first direction and the velocity in the second direction are adjusted according to the offset distance so that the non-player character moves along the second sub-path. In this way, the movement of the non-player character in the game scene can be made to fit the movement of objects in the real scene, which improves the movement of the non-player character in the game scene and makes its movement more natural. Attached Figure Description

[0064] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0065] Figure 1a This is a schematic diagram of a scenario illustrating the control method for a non-player character provided in an embodiment of this application;

[0066] Figure 1b This is a flowchart illustrating the control method for a non-player character provided in an embodiment of this application;

[0067] Figure 2a This is a flowchart illustrating the application of the non-player character control method provided in this application embodiment in a game scene;

[0068] Figure 2b This is a schematic diagram of a smoothing method for a route to be moved provided in an embodiment of this application;

[0069] Figure 2c The non-player character provided in this application embodiment is from P i+1 To P i+2 A diagram illustrating the movement;

[0070] Figure 2d This is a schematic diagram of a non-player character jumping from the starting point S to the ending point E, provided in an embodiment of this application.

[0071] Figure 2e This is a schematic diagram illustrating the control of a non-player character's turning direction during movement, provided in an embodiment of this application.

[0072] Figure 2f This is a schematic diagram illustrating the distance between a non-player character and a line segment, provided in an embodiment of this application.

[0073] Figure 2gThe method for determining a non-player character from P is provided in the embodiments of this application. i Arrival at P i+1 A schematic diagram;

[0074] Figure 3 This is a schematic diagram of the structure of the control device for a non-player character provided in an embodiment of this application;

[0075] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0076] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0077] This application provides a method, apparatus, electronic device, and storage medium for controlling a non-player character.

[0078] Specifically, the control device for the non-player character can be integrated into an electronic device, such as a terminal or server. The terminal can be a mobile phone, tablet, smart Bluetooth device, laptop, or personal computer (PC); the server can be a single server or a server cluster consisting of multiple servers.

[0079] In some embodiments, the control device for the non-player character can also be integrated into multiple electronic devices. For example, the control device for the non-player character can be integrated into multiple servers, and the control method for the non-player character of this application can be implemented by multiple servers.

[0080] In some embodiments, the server may also be implemented as a terminal.

[0081] Currently, NPC movement is controlled using an interpolation-based movement algorithm. This algorithm relies on a movement system to control the NPC's position. However, if the game requires NPCs to be affected by a physics engine, the interpolation-based algorithm will conflict with the physics engine, making it unsuitable for games using physics engines. Furthermore, some games control NPC movement through an animation system, which also prevents the use of interpolation-based movement. Secondly, while interpolation-based movement can allow NPCs to turn, the NPC's orientation in the game scene may differ from the direction of the turn, rendering interpolation ineffective. Additionally, interpolation-based movement is prone to causing NPCs to slide within the game scene, making it unsuitable for demanding game scenarios.

[0082] Because current methods for controlling NPC movement are not adapted to the increasingly complex game logic requirements, and the movement of non-player characters is rather rigid, this application proposes a method for controlling non-player characters. The electronic device can acquire the movement route of the non-player character in the game scene. The movement route includes multiple sub-paths, where the endpoint of one sub-path is connected to the starting point of the next sub-path in any two adjacent sub-paths. An offset speed is determined based on the non-player character's velocity in a first direction at the endpoint of the first sub-path and the second sub-path. The offset speed is perpendicular to the second sub-path, and the first direction is along the first sub-path. The first sub-path is any sub-path other than the last one, and the second sub-path is the sub-path following the first sub-path. The offset distance of the non-player character is predicted based on the offset speed and a preset acceleration, where the preset acceleration is the acceleration set in the game scene. Based on the offset distance, the velocity in the first direction of the non-player character at the endpoint of the first sub-path is adjusted. The adjusted velocity in the first direction and the velocity in the second direction corresponding to the starting point of the preset second sub-path are used to control the non-player character's movement along the second sub-path, where the second direction is along the second sub-path.

[0083] For example, such as Figure 1a As shown, when the route to be moved includes a first sub-path 1 and a second sub-path 2, the end point of the first sub-path 1 is the starting point of the second sub-path 2. Controlling a non-player character A to move from the starting point to the end point of the first sub-path 1, at this time, the non-player character A has a velocity V1 in a first direction along the direction of the first sub-path 1. That is, the non-player character A has inertia in the game scene. Since the first sub-path 1 and the second sub-path 2 may not be in the same direction, the velocity in the first direction has an offset velocity V1 that deviates from the second sub-path 2. y Predict the offset velocity V1 of non-player character A. y The velocity V1 in the first direction is adjusted based on the offset distance under the preset acceleration. x The speed V2 in the second direction is used to make the non-player character move along the second sub-path 2. In this way, the movement of the non-player character A in the game scene can be made to match the movement of objects in the real scene, thus improving the movement of the non-player character A in the game scene and making its movement more natural.

[0084] The following sections provide detailed descriptions of each example. It should be noted that the sequence numbers of the following embodiments are not intended to limit the preferred order of the embodiments.

[0085] In this embodiment, a control method for a non-player character is provided, such as... Figure 1b As shown, the specific process of controlling this non-player character can be as follows:

[0086] 110. Obtain the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in any two adjacent sub-paths.

[0087] Non-player characters are virtual characters controlled by computer AI (Artificial Intelligence). For example, non-player characters can interact with player-controlled virtual characters; this interaction can specifically refer to dialogue, selling virtual items, fighting together, battling, and so on.

[0088] Game scenes can be composed of virtual objects such as virtual characters, buildings, terrain, plants, and animals. For example, virtual objects in a game scene can include virtual characters, virtual buildings, and virtual items. Virtual characters can include player-controlled virtual characters and virtual NPCs; virtual buildings can include virtual defense towers, virtual hot springs, and virtual respawn points; and virtual items can include virtual pets, virtual mounts, and dropped virtual money bags.

[0089] The movement route is a pre-set path in the game scene for non-player characters to move along. For example, the movement route can include flat ground, waterways, mountain paths, etc. in the game scene. There can also be obstacles on the movement route, such as residential buildings, broken walls, cliffs, virtual objects, etc.

[0090] A sub-path is a portion of the planned movement route, used to restrict the movement of non-player characters within the game scene. For example, if two adjacent sub-paths in the planned movement route are sub-path 1 and sub-path 2, their orientations may differ, or their path configurations may differ, requiring the non-player character to use different methods to move between sub-paths 1 and 2. Path configurations could specifically mean that sub-path 1 is a straight line, while sub-path 2 contains obstacles (such as cliffs), causing sub-path 2 to potentially follow a parabola. The non-player character could walk or run along sub-path 1, but would need to climb or jump along sub-path 2 to move over cliffs. Path configurations could also mean that sub-path 1 and sub-path 2 have different geographical types, such as flat land, mountain paths, or waterways.

[0091] For example, the end point of sub-path 1 is the starting point of sub-path 2. Non-player characters need to pass through sub-path 1 first and then sub-path 2.

[0092] In some embodiments, considering that when the distance between the starting point and the ending point is too long, it is difficult to obtain a path that is easy for a non-player character to move through directly through the starting point and the ending point, in order to obtain a path that a non-player character can move from the starting point to the ending point, before obtaining the path to be moved by the non-player character in the game scene, the following is included:

[0093] Obtain the starting point and ending point of movement for non-player characters in the game scene, as well as the midpoint between the starting point and the ending point;

[0094] Based on the starting point, intermediate point, and ending point of the movement, a sub-path is determined. A sub-path is a path between two adjacent points, which are any two adjacent points among the starting point, intermediate point, and ending point of the movement.

[0095] Determine the route to be moved based on all sub-paths.

[0096] The starting point of movement is the starting point for non-player characters when they move within the game scene.

[0097] The destination of movement is the point in the game scene where the player character completes the movement.

[0098] For example, in a game, a non-player character A is set to perform a movement task. In this movement task, the starting point P1 and the ending point P of the non-player character A's movement in the game scene are pre-set. n Non-player character A needs to move from the starting point P1 to the ending point P in the game scene. n .

[0099] The midpoint is the point in the game scene between the starting point P1 and the ending point P. n Any point between the starting point P1 and the ending point P. n The points directly above can also be the starting point P1 and the ending point P. n As the endpoints within the preset range, the intermediate points are at P1 and P2. n Any point within the preset range between them, etc.

[0100] In some embodiments, the preset range can be of any shape. It is understood that the preset range can be a rectangle, meaning the starting point P1 is located at the same position as the center point of one boundary of the rectangle. n The center point of the rectangle is in the same position as the other boundary, and one boundary is parallel to the other.

[0101] In some embodiments, if there are multiple intermediate points between the starting point and the ending point, the sub-path can be a path between the starting point and the intermediate points, a path between two adjacent intermediate points, or a path between an intermediate point and the ending point.

[0102] In some embodiments, a subpath can be any path between two adjacent points. For example, a path between two adjacent points can be a straight line, a parabola, and so on.

[0103] For example, the route to be moved can be denoted as [P1, P2, ..., P...n-1 P n ], where P2, ..., P n-1 Let be the intermediate point, and pass through [P1, P2, ..., P... n-1 P n Any two adjacent points in the path form a subpath.

[0104] In some embodiments, considering that multiple sequentially connected sub-paths may form a straight route, or multiple sequentially adjacent sub-paths may form a large bend route, and the large bend route may have redundant sub-paths, in order to simplify the sub-paths, the route to be moved is determined based on all sub-paths, including:

[0105] Obtain information about obstacles between the target sub-path, the next sub-path of the target sub-path, the start point of the target sub-path, and the end point of the next sub-path. The target sub-path is any sub-path except the last one among all sub-paths.

[0106] Based on the starting point of the target sub-path, the ending point of the next sub-path, and obstacle information, the target sub-path and the next sub-path are smoothed to obtain the smoothed sub-path.

[0107] Determine the route to be moved based on all the smoothed sub-paths.

[0108] The target sub-path is any one of the sub-paths.

[0109] The next subpath is the subpath that connects to the endpoint of the target subpath among all subpaths.

[0110] Obstacle information refers to obstacles on the straight line between the start of the target sub-path and the end of the next sub-path. For example, if there is an obstacle between the start of the target sub-path and the end of the next sub-path, or if there is no obstacle between the start of the target sub-path and the end of the next sub-path, then the obstacle information is an empty set.

[0111] The smoothed sub-path is the sub-path corresponding to the target sub-path and the next sub-path after they have been reset to a straight line.

[0112] In some implementations, the target subpath may include a smoothed subpath.

[0113] For example, if there are obstacles, the target sub-path and the next sub-path will not become a straight line after smoothing. However, if there are no obstacles, the target sub-path and the next sub-path will become a straight line after smoothing.

[0114] For example, the route to be moved is [P1, P2, ..., P... n-1 P nFirst, take P1-P2 as the target sub-path and P2-P3 as the next sub-path. If P1-P2-P3 can be obtained as a straight line after smoothing, then the smoothed sub-path is P1-P3. If P1-P2-P3 cannot be obtained as a straight line after smoothing, then the smoothed sub-path is still P1-P2 and P2-P3.

[0115] If P1-P2-P3 results in P1-P3 after smoothing, then P1-P3 is taken as the target sub-path, and P3-P4 is taken as the next sub-path for smoothing. If P1-P2-P3 remains P1-P2-P3, then P2-P3 is taken as the target sub-path, and P3-P4 is taken as the next sub-path for smoothing, and so on, until the next sub-path is P. n-1 -P n .

[0116] For example, P i-1 -P i -P i+1 P i For P i-1 and P i+1 Points on the line, then P i-1 -P i -P i+1 After smoothing, a straight line P can be obtained. i-1 -P i+1 Or P i-1 -P i -P i+1 If it forms a bent line segment, then after smoothing, a line P is obtained. i-1 and P i+1 The straight line between them does not pass through P. i .

[0117] 120. Determine the offset speed based on the speed of the non-player character in the first direction when the character is at the end of the first sub-path and the speed of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any sub-path other than the last sub-path among multiple sub-paths. The second sub-path is the sub-path after the first sub-path.

[0118] The first sub-path ends at the same point as the second sub-path begins at the same point. The first sub-path is the sub-path that the non-player character has already traversed, and the second sub-path is the sub-path that connects to the end point of the first sub-path and is waiting for the non-player character to move.

[0119] The velocity in the first direction is due to the inertia of the non-player character in the game scene, so that it has a velocity in the direction of the first sub-path at the end of the first sub-path, and the velocity in the first direction starts to decrease continuously at the end of the first sub-path.

[0120] The offset velocity is the component of the velocity in the first direction perpendicular to the second sub-path. For example, if there is an angle between the first direction and the second sub-path, the offset velocity is not zero; if the first direction overlaps with the second sub-path, the offset velocity is zero.

[0121] 130. Based on the offset velocity and preset acceleration, predict the offset distance of non-player characters. The preset acceleration is the acceleration set in the game scene.

[0122] The preset acceleration is the acceleration corresponding to the resistance set in the game scene, used to limit the movement of non-player characters.

[0123] The offset distance is the distance a non-player character moves when the offset speed continuously decreases to zero under the effect of the preset acceleration.

[0124] Among them, v h v1 represents the offset velocity in the first direction, and a represents the preset acceleration.

[0125] 140. Based on the offset distance, adjust the speed of the non-player character in the first direction at the end of the first sub-path, so as to control the non-player character to move along the second sub-path by using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path. The second direction is the direction along the second sub-path.

[0126] The adjusted velocity direction of the first direction follows the second sub-path.

[0127] The speed in the second direction is the speed of the non-player character associated with the second sub-path, which is a pre-set speed in the second direction for the non-player character on the second sub-path.

[0128] For example, a non-player character located at the starting point of the second sub-path moves along the second sub-path based on the adjusted speed in the first and second directions.

[0129] In some embodiments, to prevent a non-player character from deviating from the second sub-path while moving along it, the speed in the first direction includes a non-offset speed, the direction of which is the same as the second direction. Based on the offset distance, the speed in the first direction of the non-player character at the end of the first sub-path is adjusted. This is to control the non-player character's movement along the second sub-path by using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path, including:

[0130] If the offset distance is outside the preset range, the offset speed is eliminated;

[0131] Based on the non-player character's non-offset velocity at the end of the first sub-path and the velocity in the second direction corresponding to the preset start point of the second sub-path, control the non-player character to move along the second sub-path;

[0132] If the offset distance is within the preset range, the non-player character is controlled to move along the second sub-path based on the speed of the non-player character in the first direction and the speed of the second direction at the end of the first sub-path.

[0133] The non-offset velocity is the component of the velocity in the first direction that is parallel to the second sub-path. For example, if there is an angle between the first direction and the second sub-path, the non-offset velocity is less than the velocity in the first direction; if the first direction and the second sub-path overlap, the offset velocity is equal to the velocity in the first direction.

[0134] The preset range is a pre-defined range used to measure the deviation of a non-player character's position from the sub-path. For example, if the distance between the non-player character's position and the sub-path is outside the preset range, then the non-player character has deviated from the sub-path; if the distance between the non-player character's position and the sub-path is within the preset range, then the non-player character has not deviated from the sub-path.

[0135] For example, if the predicted offset distance of a non-player character is outside the preset range, first eliminate the offset speed of the non-player character at the end of the first sub-path, and then control the non-player character to move along the second sub-path by using the speed in the second direction corresponding to the non-offset speed and the preset second sub-path starting point.

[0136] For example, if the predicted offset distance of the non-player character is within a preset range, that is, the non-player character does not deviate from the second sub-path under the action of the speed in the first direction, then the non-player character can be controlled to move along the second sub-path by the speed in the first direction at the end of the first sub-path and the speed in the second direction corresponding to the preset starting point of the second sub-path.

[0137] In some embodiments, to ensure that the movement of a non-player character matches the sub-path, the second sub-path carries at least one movement information, including the movement type of the non-player character, and the starting and ending points corresponding to the movement type. After adjusting the speed of the non-player character in a first direction at the end of the first sub-path based on the offset distance, and controlling the movement of the non-player character along the second sub-path by using the adjusted speed in the first direction and the speed in a second direction corresponding to the preset starting point of the second sub-path, the method further includes:

[0138] Obtain the real-time position of a non-player character moving along the second sub-path, and at least one piece of movement information containing target movement information corresponding to the real-time position;

[0139] Based on the movement type in the target movement information, control the non-player character to move from the target starting point to the target ending point. The target starting point and target ending point are the starting point and ending point corresponding to the movement type in the target movement information.

[0140] The movement information corresponds to the road segments in the sub-path and is used to assist non-player characters in moving along the road segments in the second sub-path.

[0141] Movement type indicates how a non-player character moves along a segment of a sub-path. For example, movement type can be walking, running, jumping, vaulting, climbing, etc.

[0142] The start and end points of a movement type are used to limit the scope of its application. For example, the start and end points of a movement type constitute a road segment corresponding to that movement type, and non-player characters use that movement type when moving along that road segment.

[0143] For example, if the second sub-path carries one movement information, then non-player characters will only use one movement type when moving along the second sub-path. If the second sub-path carries multiple movement information, then the second sub-path is divided into multiple segments, and non-player characters will use the corresponding movement type for each segment.

[0144] The real-time position is the location where a non-player character moves along the second sub-path in real time. For example, a non-player character can provide real-time feedback on its position in the game scene, thus obtaining the non-player character's real-time position.

[0145] The target movement information is the movement information corresponding to the real-time location among at least one movement information carried by the second sub-path. For example, the real-time location may correspond to the target origin in the target movement information, or it may correspond to the road segment between the target origin and the target destination in the target movement information, and so on.

[0146] For example, control a non-player character to move from the target starting point to the target ending point according to the movement type in the target movement information.

[0147] In some embodiments, to enable a non-player character to cross obstacles on a sub-path, controlling the non-player character to move from the target starting point to the target ending point based on the movement type in the target movement information includes:

[0148] When the movement type in the target movement information is jump type, calculate the free fall time corresponding to the vertical height. The vertical height is the height difference between the real-time position and the target endpoint. The target endpoint is the endpoint corresponding to the movement type in the target movement information.

[0149] Based on the free fall time and the real-time velocity of the non-player character at its real-time position, determine the horizontal displacement distance of the non-player character during the free fall time.

[0150] Based on the displacement distance, adjust the target start point and target end point located on the second sub-path so that the horizontal distance between the adjusted target start point and target end point is equal to the displacement distance. The target start point is the start point corresponding to the movement type in the target movement information.

[0151] Based on the real-time speed of the non-player character at the adjusted target starting point, control the non-player character to jump from the adjusted target starting point to the adjusted target endpoint.

[0152] Vertical height is the height difference between the real-time position and the target endpoint. For example, if the height of the real-time position is lower than the height of the target endpoint, then vertical height = height of the target endpoint - height of the real-time position; if the height of the real-time position is higher than the height of the target endpoint, then vertical height = height of the real-time position - height of the target endpoint.

[0153] For example, if the height of the real-time position is lower than the height of the target endpoint, the jump type is an upward jump; if the height of the real-time position is higher than the height of the target endpoint, the jump type is a downward jump.

[0154] Free fall time is the time a non-player character spends in free fall from a vertical height within the game scene.

[0155] h is the vertical height, and g is the gravity value set in the game scene.

[0156] The real-time speed of a non-player character at its current location is the speed of the non-player character at that current location.

[0157] Displacement distance is the distance a non-player character moves horizontally during the free fall time. For example, displacement distance = first distance + second distance.

[0158] Among them, v x v is the non-offset velocity v1 of the non-player character in the first direction when the character is at the end of the first sub-path. x ′ represents the non-player character's non-offset velocity at the real-time position, t represents the free fall time, and a represents the acceleration corresponding to the resistance set in the game scene.

[0159] Second distance = v2t, where v2 is the velocity of the non-player character in the second direction at the starting point of the second sub-path, and t is the free fall time.

[0160] The adjusted target starting point is the adjusted starting point corresponding to the movement type in the target movement information.

[0161] The adjusted target endpoint is the adjusted endpoint corresponding to the movement type in the target movement information.

[0162] For example, if the displacement distance is greater than the distance between the target starting point and the target ending point before adjustment, the target starting point after adjustment can be located at the real-time position, and the target ending point can be moved away from the target starting point on the second sub-path, so that the distance between the target starting point and the target ending point after adjustment is equal to the displacement distance.

[0163] For example, if the displacement distance is less than the distance between the target starting point and the target ending point before adjustment, the target starting point can be moved towards the target ending point, or the target starting point and the target ending point can be moved towards each other, or the target ending point can be moved towards the target starting point, so that the distance between the adjusted target starting point and the adjusted target ending point is equal to the displacement distance.

[0164] The real-time speed of a non-player character at the adjusted target starting point is the speed of the non-player character at its real-time location.

[0165] In some embodiments, in order to obtain the real-time velocity of the non-player character, the velocity in the first direction includes a non-offset velocity. Before determining the displacement distance of the non-player character in the horizontal direction during the free fall time based on the free fall time and the real-time velocity of the non-player character at its real-time position, the method further includes:

[0166] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the first real-time non-offset velocity of the non-player character at the real-time position;

[0167] Based on the first real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the real-time position;

[0168] Before controlling the non-player character to jump from the adjusted target starting point to the adjusted target endpoint based on the non-player character's real-time speed at the adjusted target starting point, the following is also included:

[0169] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the second real-time non-offset velocity of the non-player character at the adjusted target starting point;

[0170] Based on the second real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the adjusted target starting point.

[0171] The first real-time non-offset speed is the non-offset speed at which a non-player character moves from the end of the first sub-path to the real-time position under the action of a preset acceleration.

[0172] Where a is the preset acceleration and s1 is the distance between the starting point of the second sub-path and the real-time position.

[0173] The second real-time non-offset speed is the non-offset speed at which a non-player character moves from the end of the first sub-path to the adjusted target starting point under the effect of preset acceleration.

[0174] Where a is the preset acceleration and s1 is the distance between the starting point of the second sub-path and the adjusted target starting point.

[0175] In some embodiments, considering that non-player characters are prone to deviating from the second sub-path when vaulting obstacles, in order to correct the position of non-player characters during obstacle vaulting, the movement of non-player characters from the target starting point to the target ending point is controlled according to the movement type in the target movement information, including:

[0176] If the movement type in the target movement information is the target movement type, obtain the real-time target movement position of the non-player character moving from the target starting point to the target ending point. The target movement type is the movement type corresponding to climbing over obstacles.

[0177] Determine the real-time distance between the target's current location and the second sub-path;

[0178] If the real-time distance is outside the preset range, adjust the movement direction of the non-player character at the real-time target movement position so that the non-player character moves towards the target endpoint.

[0179] The target movement type refers to the movement type that a non-player character needs to overcome when traversing an obstacle. For example, the target movement type could be jumping, vaulting, climbing, flying, gliding, and so on.

[0180] The real-time target movement position is the real-time position of a non-player character as they move from the target's starting point to its target's ending point. For example, the real-time target movement position could be the real-time position of a non-player character during actions such as jumping, vaulting, climbing, flying, or gliding.

[0181] The real-time distance is the distance between the real-time target's moving position and the second sub-path.

[0182] In some embodiments, the real-time distance is calculated using a point-to-line calculation formula.

[0183] The movement direction refers to the direction in which a non-player character moves within the game scene.

[0184] In some embodiments, if the real-time distance is outside a preset range, the non-player character is instructed to deviate from the second sub-path, thereby allowing a reverse movement command to be sent to the non-player character, which can control the non-player character to move towards the second sub-path.

[0185] In some embodiments, considering that non-player characters may have difficulty successfully traversing obstacles in sub-paths, in order not to affect the movement task of non-player characters, after adjusting the movement direction of the non-player character at the real-time target movement position if the real-time distance is outside a preset range, the method further includes:

[0186] Get the number of adjustments. The number of adjustments is the number of times a non-player character adjusts the movement direction when moving from the target starting point to the target ending point.

[0187] If the number of adjustments exceeds the preset number, the route to be moved is updated. The updated route is the path between the target starting point and the end point of the original route.

[0188] The number of adjustments refers to the number of times a non-player character moves onto the second sub-path during the process of moving from the target starting point to the target ending point.

[0189] The preset quantity is a number that is pre-set to measure the number of adjustments, and there is no limit to the preset quantity here.

[0190] The updated route to be moved is the new path between the target origin and the updated destination of the route to be moved.

[0191] The original movement route was the route initially planned by non-player characters for movement tasks within the game scene.

[0192] In some embodiments, the target game includes a calculator that can record the number of times the non-player character's movement direction is adjusted.

[0193] In some embodiments, to prevent non-player characters from having to traverse paths with obstacles that are difficult for them to overcome when performing subsequent movement tasks, after obtaining the number of adjustments, the method further includes:

[0194] If the number of adjustments exceeds the preset number, the weight corresponding to the target path is determined. The target path is the path between the target start point and the target end point in the second sub-path. The weight represents the difficulty of controlling the non-player character to move along the target path.

[0195] If the number of adjustments exceeds the preset limit, update the route to be moved, including:

[0196] Update the route to be moved based on the weights. The updated route does not include the target path.

[0197] The target path is the segment of the second sub-path between the target start point and the target end point. For example, obstacles on the target path can be residential buildings, broken walls, cliffs, virtual objects, etc., in the game scene.

[0198] The weight represents the difficulty of controlling the movement of non-player characters along the target path.

[0199] In some embodiments, the weight corresponding to the number of adjustments can be determined based on the mapping relationship between the preset number of adjustments and the preset weight.

[0200] In some embodiments, after determining the weight corresponding to the target path if the number of adjustments exceeds a preset number, the method further includes:

[0201] Obtain a non-player character's quest to move to, which includes the quest start point and quest end point;

[0202] Based on the weights corresponding to the target path, plan the route to be moved from the task start point to the task end point.

[0203] Among them, the task to be moved is the task of controlling the movement of non-player characters in the game scene.

[0204] The task start point and task end point are the start point and end point set in the task to be moved. For example, the task start point can be the movement start point, and the task end point can be the movement end point.

[0205] In some embodiments, to restrict the movement of non-player characters in the game scene, the game scene includes a displacement trigger, which carries a triggering condition and a displacement strategy, and further includes:

[0206] Get the location of non-player characters in the game scene;

[0207] If the position meets the triggering conditions, the non-player character will be controlled to move within the area controlled by the displacement trigger according to the displacement strategy.

[0208] The displacement trigger is a type of trigger that, when activated by a non-player character, forces the non-player character to move until they escape its control. For example, a displacement trigger could be a jump trigger, a movement direction control trigger, a safety check trigger, and so on. Specifically, when a non-player character touches a jump trigger, they will jump. When a non-player character activates a movement direction control trigger, they will move in the direction indicated by that trigger. Safety check triggers are used to control the accessibility of paths within the game scene.

[0209] The triggering conditions are pre-set, and the displacement trigger can be triggered based on the position of a non-player character.

[0210] Displacement strategies are used to control the movement of non-player characters within the area controlled by a displacement trigger. For example, a displacement strategy can control the type of displacement a non-player character makes them move within the area controlled by that type of displacement. A displacement strategy can also control the direction of displacement, allowing the non-player character to move along that direction within the area controlled by the displacement trigger. Furthermore, a displacement strategy can control the accessibility of paths within the area controlled by the displacement trigger, thus restricting the movement of non-player characters within that area.

[0211] In some embodiments, considering that the displacement trigger affects the movement of the non-player character, in order to allow the non-player character to escape the control of the displacement trigger, the displacement strategy includes a displacement direction. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including:

[0212] If the position meets the triggering conditions, the non-player character is controlled to move in the direction of displacement according to the displacement strategy until the non-player character leaves the area controlled by the displacement trigger.

[0213] The displacement direction is the displacement direction preset in the displacement strategy.

[0214] For example, when a non-player character's position in the game scene meets the triggering conditions, the displacement trigger is activated. At this time, the non-player character is within the area controlled by the displacement trigger, and the displacement trigger controls the non-player character to move in the displacement direction until the non-player character leaves the area controlled by the displacement trigger, at which point the displacement trigger goes into sleep mode.

[0215] In some embodiments, to enrich the movement of non-player characters within the displacement trigger-controlled area, the displacement trigger-controlled area includes a control path. This control path facilitates the non-player character's escape from the displacement trigger-controlled area. If the position meets the triggering condition, the non-player character is controlled to move within the displacement trigger-controlled area according to a displacement strategy, including:

[0216] If the location meets the triggering conditions, determine the opening status of the control path;

[0217] Depending on the activation status, non-player characters are controlled to move along the controlled path according to the displacement strategy.

[0218] The controlled path is the path controlled by the displacement trigger within the area controlled by the displacement trigger. For example, there are 3 paths (path 1, path 2, and path 3) within the area controlled by the displacement trigger, and all 3 paths can be controlled by the displacement trigger, or any one or two of the 3 paths can be controlled by the displacement trigger, and so on.

[0219] The "on" state indicates whether the controlled path is open or closed. For example, if the "on" state indicates that the controlled path is open, the displacement trigger will control the movement of non-player characters on the controlled path according to the displacement strategy. If the "on" state indicates that the controlled path is closed, non-player characters will not be able to move on the controlled path.

[0220] As can be seen from the above, the embodiments of this application can obtain the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the starting point of the next sub-path in two adjacent sub-paths. The offset speed is determined based on the speed of the non-player character in the first direction when it is at the end point of the first sub-path and the speed of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any sub-path among the multiple sub-paths except the last one. The second sub-path is the sub-path following the first sub-path. The offset distance of the non-player character is predicted based on the offset speed and the preset acceleration, which is the acceleration set in the game scene. Based on the offset distance, the speed of the non-player character in the first direction when it is at the end point of the first sub-path is adjusted. By adjusting the speed in the first direction and the speed in the second direction corresponding to the starting point of the preset second sub-path, the non-player character is controlled to move along the second sub-path. The second direction is the direction along the second sub-path.

[0221] Therefore, in this solution, the non-player character has a velocity in the first direction when it moves to the end of the first sub-path. That is, the non-player character in the game scene has inertia. Since the first sub-path and the second sub-path may not be in the same direction, the velocity in the first direction has an offset velocity that deviates from the second sub-path. The offset distance of the non-player character under the action of the offset velocity and the preset acceleration is predicted. The velocity in the first direction and the velocity in the second direction are adjusted according to the offset distance so that the non-player character moves along the second sub-path. In this way, the movement of the non-player character in the game scene can be made to fit the movement of objects in the real scene, which improves the movement of the non-player character in the game scene and makes its movement more natural.

[0222] The method described in the above embodiments will be further described in detail below.

[0223] In this embodiment, the method of this application embodiment will be described in detail by taking the control of a non-player character to move in the game scene as an example.

[0224] like Figure 2a As shown, the specific process of a control method for a non-player character is as follows:

[0225] 210. Call the pathfinding algorithm to obtain the route to be moved from the non-player character's starting point to the ending point. The route to be moved includes multiple sub-paths, and the ending point of the previous sub-path is connected to the starting point of the next sub-path in any two adjacent sub-paths.

[0226] In one feasible approach, step 210 uses the game's built-in pathfinding and scene management system to obtain the route to be moved from the starting point to the ending point. The obtained route is represented by a coordinate list, denoted as [P1, P2, ... P2]. n ], where P1 is the starting point of the movement, P n P2-P is the destination of the movement. n-1 This is the midpoint. In some games, the pathfinding algorithm also returns movement information, including movement types such as vaulting, climbing walls, and jumping. These movement types are usually accompanied by coordinate information, i.e., the starting and ending points corresponding to the movement type, denoted as [O1, O2, ... O2]. n This corresponds one-to-one with the coordinate list, and its meaning is that the subpath is P. i -P i+1 When, corresponding to O i Movement information assists non-player characters in movement. Furthermore, the pathfinding algorithm invoked in this step may be affected by the adjustment method described in step 260.

[0227] 220. Smooth out the movement path according to the needs of the game logic.

[0228] The list of coordinates returned by pathfinding algorithms often contains redundancy. For example, a straight route may contain multiple intermediate points, and a turning path may have a large bend. In such cases, this step can be used to simplify the path. The simplified result is as follows: Figure 2b As shown. In practice, each coordinate point P in the path can be traversed. i+1 Consider its relationship with the coordinates P before and after. i and P i+2 Does it form a straight line? If so, P can be deleted. i+1 Point. Or, consider P. i and P i+2 Are there any obstructions in the line segment formed? If there are no obstructions, P can be deleted. i+1 Point. Repeat this step until the step no longer changes the coordinate list. Additionally, if P i+1 Point corresponding to O i If the information is important, then P i+1 Dots cannot be deleted.

[0229] 230. Set P i and P i+1 P i and P i+1 Let P be any two adjacent points among the starting point, ending point, and intermediate point. i and P i+1 Connected by a subpath.

[0230] 240. Invoke the character controller to predict the non-player character's movement from P. i+1 Move to P i+2 The predicted movement path.

[0231] In the embodiments of this application, the algorithm invokes the relevant functions of the movement controller by directly sending movement commands to control the movement of non-player characters.

[0232] This step also includes adaptive cornering control: such as Figure 2c As shown, during the movement of a non-player character in the first sub-path, i.e. from P... i Move to P i+1 At this point, the non-player character already possesses a velocity V1 in the first direction. If the non-player character is directly controlled to follow the second sub-path (P... i+1 -P i+2 Move, depending on the non-player character's location in P. i+1 The speed in the first direction, if the character is directly controlled to move towards P i+2 If you move, the character may deviate directly from the route due to inertia. V1 y This application calculates the vertical component (offset velocity) of the velocity in the first direction on the second sub-path, and analyzes the offset distance of the non-player character on the second sub-path as the offset velocity gradually decreases to 0 under the influence of a preset acceleration 'a' caused by physical resistance. Outside the preset range. If the offset distance may exceed the preset range in the future, meaning the non-player character will deviate from the second sub-path due to inertia, then first send a command to move in the opposite direction of the velocity to control the non-player character to eliminate the offset velocity, and then continue towards P. i+2 move.

[0233] Furthermore, when controlling a non-player character to P i+2 When moving, via P i+1 The displacement type O corresponding to the point i+1 This controls the movement of non-player characters. Movement types can include jumping, vaulting, climbing, etc. This step can easily cause non-player characters to deviate from the second sub-path when moving along it. If this occurs, consider adjusting the weights of the second sub-path to avoid passing through it in subsequent pathfinding.

[0234] For mobile information O i+1 Instructing a non-player character to jump involves considering the non-player character's current movement capabilities and surrounding environment information, such as... Figure 2d As shown, this describes the process of dynamically calculating the jump start position S (i.e., the target's starting point corresponding to the jump type in the target movement information), the jump charge intensity, and performing aerial position correction. Typically, the pathfinding system provides O... iThe movement information includes the starting point S (i.e., the target starting point) and ending point E (the target ending point) of the non-player character's jump, pre-stored on the map. This algorithm improves the accuracy of the non-player character's movement by dynamically adjusting the jump starting point and ending point. Specifically, it first uses the height difference (vertical height) between the current position (i.e., real-time position) and the jump ending point, combined with game logic and physics formulas. Calculate the required charge strength for a jump and the freefall time required for vertical movement. Calculate the horizontal V-axis movement of the non-player character during the freefall time. x The horizontal displacement distance. Move the non-player character's jump start and end points so that the horizontal distance between the two coordinates equals the character's horizontal movement distance. One possible method is to move the two points closer or further apart while maintaining the same movement distance for each point, ultimately making the horizontal distance between them equal to the character's horizontal movement distance. Finally, during the jump, use movement commands in the air to correct the non-player character's real-time target movement position to ensure the non-player character lands at the designated endpoint. Simultaneously, avoid frequent large-angle turns during the correction process, such as... Figure 2e As shown, the specific method is that when the real-time distance between the non-player character's real-time target movement position and the second sub-path exceeds the preset range (threshold), a movement command is sent in the opposite direction (i.e., the movement direction of the non-player character at the real-time target movement position is adjusted) to control the non-player character to turn around.

[0235] 250. Determine whether the real-time target's position deviates from P. i+1- P i+2 The second sub-path.

[0236] By setting a preset threshold, such as Figure 2f As shown, and using Figure 2f The diagram shown illustrates the calculation of the distance from a point to a line segment, calculating the predicted position of a non-player character to the second sub-path P. i+1 -P i+2 If the distance exceeds the preset range, it is considered that the non-player character has deviated from the route. One feasible way to set the preset range is to set it as the non-player character's body radius, or other allowable movement error values ​​determined by the gameplay, to ensure that the non-player character's movement behavior is normal and does not get stuck in walls when the movement error is within this range.

[0237] 260. Correct the behavior of non-player characters.

[0238] This step can be implemented in multiple ways. In the embodiment of this invention, if P i The displacement type O corresponding to the point i If the value is empty (i.e., normal movement), return to step 210, reset the algorithm, and move again. Otherwise, if Oi For movement types such as jumping and vaulting, if the non-player character has deviated from the real-time target position, a counter (error_count) is maintained, where the error_count value represents the number of iterations. The non-player character is then controlled to retry jumping or vaulting in place. If it still fails, the error counter (error_count) is incremented. When error_count exceeds a preset number, the movement is considered a failure, and the pathfinding system's interface is called to adjust the position of the target. i+1- P i+2 Adjust the weights (of the target path), generally by increasing the pathfinding weights to minimize subsequent pathfinding movements through this point. The increased weights can be determined empirically. Finally, return to step 210. If the correction is successful before error_count exceeds a preset limit, continue to the next step.

[0239] 270. Determine if a character is not a player from P i+1 To P i+2 Does the arrival condition meet?

[0240] In embodiments of the present invention, such as Figure 2g As shown, determine whether a non-player character has reached point P. i+2 Among them, the vertical line segment of the dashed line is the sub-path P. i+1 -P i+2 The radius of the semicircle is the preset range described in step 250. When the coordinates of a non-player character are within the preset range, it is considered that the non-player character has reached P. i+2 .

[0241] 280: Increment i by 1, check if i+2 equals n+1, if not, continue to step 240.

[0242] 290: After a non-player character reaches the destination, control the non-player character to stop moving.

[0243] In addition, this application also provides independent displacement triggers to enrich the unit behavior of non-player characters in specific areas. These displacement triggers include jump triggers, movement direction control triggers, and safety check triggers. These triggers can be placed in the scene using map editing tools, and when virtual characters (both non-player characters and player-controlled virtual characters) enter the trigger area, they will execute the actions specified by the trigger.

[0244] When a virtual character touches the jump trigger, a jump is executed. This is achieved using the physics engine's triggers and callbacks; the trigger's callback calls the character controller to send the jump command. This behavior executes concurrently with the movement control logic described earlier, and can be used to enrich character actions.

[0245] When a character touches a movement direction control trigger, the virtual character will ignore the aforementioned movement control and move unconditionally in the direction specified by the trigger until the virtual character leaves the trigger area. In the implementation, the non-player character control logic described above will determine whether the non-player character is at the trigger for moving in the specified direction. If so, it will directly control the non-player character to move in the specified direction, skipping the aforementioned algorithm.

[0246] Safety check triggers are used to control path access using additional triggering conditions. In the implementation, by configuring the trigger's triggering conditions and the controlled path, road access can be controlled based on specific physical triggering conditions. Configurable triggering conditions include one or more types of virtual characters, or one or more specific virtual characters entering or leaving the area controlled by the displacement trigger. The controlled path can be configured to be enabled or disabled when the trigger is activated. In the implementation, whether to enable or disable is added to the controlled path, and the trigger modifies this based on its own departure conditions. The virtual character's movement control can read the enabled / disabled information of the controlled path. If the controlled path is disabled, the movement control algorithm keeps the virtual character in place, waiting for the controlled path to be enabled.

[0247] Virtual characters include player-controlled virtual characters and non-player characters.

[0248] As described above, this application introduces a control method for non-player characters to achieve movement control of non-player characters based on a character controller, abandoning the original interpolation movement control method. By simulating player input, the program-controlled non-player character can share the same character controller as the player. It also provides a series of independent triggers to enrich the character control behavior. This application allows the program-controlled non-player character to have natural movement behavior like a player-controlled virtual character, applicable to most games. Furthermore, it provides a more flexible motion control method based on triggers.

[0249] To better implement the above methods, this application also provides a control device for a non-player character. This control device can be integrated into an electronic device, such as a terminal or server. The terminal can be a mobile phone, tablet computer, smart Bluetooth device, laptop computer, or personal computer; the server can be a single server or a server cluster consisting of multiple servers.

[0250] For example, in this embodiment, the method of this application embodiment will be described in detail by taking the integration of a non-player character's control device into an electronic device as an example.

[0251] For example, such as Figure 3 As shown, the control device for the non-player character may include an acquisition unit 310, a speed determination unit 320, an offset determination unit 330, and an adjustment unit 340, as follows:

[0252] (I) Acquisition Unit 310.

[0253] The acquisition unit 310 is used to acquire the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in two adjacent sub-paths.

[0254] In some embodiments, before obtaining the movement route of a non-player character in the game scene, the process includes:

[0255] Obtain the starting point and ending point of movement for non-player characters in the game scene, as well as the midpoint between the starting point and the ending point;

[0256] Based on the starting point, intermediate point, and ending point of the movement, a sub-path is determined. A sub-path is a path between two adjacent points, which are any two adjacent points among the starting point, intermediate point, and ending point of the movement.

[0257] Determine the route to be moved based on all sub-paths.

[0258] In some embodiments, determining the route to be moved based on all sub-paths includes:

[0259] Obtain information about obstacles between the target sub-path, the next sub-path of the target sub-path, the start point of the target sub-path, and the end point of the next sub-path. The target sub-path is any sub-path among all sub-paths.

[0260] Based on the starting point of the target sub-path, the ending point of the next sub-path, and obstacle information, the target sub-path and the next sub-path are smoothed to obtain the smoothed sub-path.

[0261] Determine the route to be moved based on all the smoothed sub-paths.

[0262] (II) Velocity determination unit 320.

[0263] The speed determination unit 320 is used to determine the offset speed based on the speed of the non-player character in the first direction when it is located at the end of the first sub-path and the second sub-path. The speed direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the plurality of sub-paths except the last sub-path. The second sub-path is the sub-path after the first sub-path.

[0264] (III) Offset Determination Unit 330.

[0265] The offset determination unit 330 is used to predict the offset distance of a non-player character based on the offset velocity and the preset acceleration, which is the acceleration set in the game scene.

[0266] (iv) Adjustment unit 340.

[0267] The adjustment unit 340 is used to adjust the speed of the non-player character in the first direction at the end of the first sub-path based on the offset distance, so as to control the non-player character to move along the second sub-path by using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path. The second direction is the direction along the second sub-path.

[0268] In some embodiments, the velocity in the first direction includes a non-offset velocity, the direction of which is the same as the second direction. Based on the offset distance, the velocity in the first direction of the non-player character at the end of the first sub-path is adjusted so that the non-player character can be controlled to move along the second sub-path by using the adjusted velocity in the first direction and the velocity in the second direction corresponding to the preset start point of the second sub-path. This includes:

[0269] If the offset distance is outside the preset range, the offset speed is eliminated;

[0270] Based on the non-player character's non-offset velocity at the end of the first sub-path and the velocity in the second direction corresponding to the preset start point of the second sub-path, control the non-player character to move along the second sub-path;

[0271] If the offset distance is within the preset range, the non-player character is controlled to move along the second sub-path based on the speed of the non-player character in the first direction and the speed of the second direction at the end of the first sub-path.

[0272] In some embodiments, the second sub-path carries at least one movement information, including the movement type of the non-player character, and the starting point and ending point corresponding to the movement type. After adjusting the speed of the non-player character in a first direction at the end of the first sub-path based on the offset distance, and controlling the non-player character to move along the second sub-path using the adjusted speed in the first direction and the speed in a second direction corresponding to the preset starting point of the second sub-path, the method further includes:

[0273] Obtain the real-time position of a non-player character moving along the second sub-path, and at least one piece of movement information containing target movement information corresponding to the real-time position;

[0274] Based on the movement type in the target movement information, control the non-player character to move from the target starting point to the target ending point. The target starting point and target ending point are the starting point and ending point corresponding to the movement type in the target movement information.

[0275] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0276] When the movement type in the target movement information is jump type, calculate the free fall time corresponding to the vertical height. The vertical height is the height difference between the real-time position and the target endpoint. The target endpoint is the endpoint corresponding to the movement type in the target movement information.

[0277] Based on the free fall time and the real-time velocity of the non-player character at its real-time position, determine the horizontal displacement distance of the non-player character during the free fall time.

[0278] Based on the displacement distance, adjust the target start point and target end point located on the second sub-path so that the horizontal distance between the adjusted target start point and target end point is equal to the displacement distance. The target start point is the start point corresponding to the movement type in the target movement information.

[0279] Based on the real-time speed of the non-player character at the adjusted target starting point, control the non-player character to jump from the adjusted target starting point to the adjusted target endpoint.

[0280] In some embodiments, the velocity in the first direction includes a non-offset velocity, and before determining the displacement distance of the non-player character in the horizontal direction during the free fall time based on the free fall time and the real-time velocity of the non-player character at the real-time position, it further includes:

[0281] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the first real-time non-offset velocity of the non-player character at the real-time position;

[0282] Based on the first real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the real-time position;

[0283] Before controlling the non-player character to jump from the adjusted target starting point to the adjusted target endpoint based on the non-player character's real-time speed at the adjusted target starting point, the following is also included:

[0284] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the second real-time non-offset velocity of the non-player character at the adjusted target starting point;

[0285] Based on the second real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the adjusted target starting point.

[0286] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0287] If the movement type in the target movement information is the target movement type, obtain the real-time target movement position of the non-player character moving from the target starting point to the target ending point. The target movement type is the movement type corresponding to climbing over obstacles.

[0288] Determine the real-time distance between the target's current location and the second sub-path;

[0289] If the real-time distance is outside the preset range, adjust the movement direction of the non-player character at the real-time target movement position so that the non-player character moves towards the target endpoint.

[0290] In some embodiments, after adjusting the movement direction of the non-player character at the real-time target movement position if the real-time distance is outside a preset range, the method further includes:

[0291] Get the number of adjustments. The number of adjustments is the number of times a non-player character adjusts the movement direction when moving from the target starting point to the target ending point.

[0292] If the number of adjustments exceeds the preset number, the route to be moved is updated. The updated route is the path between the target starting point and the end point of the original route.

[0293] In some embodiments, after obtaining the number of adjustments, the method further includes:

[0294] If the number of adjustments exceeds the preset number, the weight corresponding to the target path is determined. The target path is the path between the target start point and the target end point in the second sub-path. The weight represents the difficulty of controlling the non-player character to move along the target path.

[0295] If the number of adjustments exceeds the preset limit, update the route to be moved, including:

[0296] Update the route to be moved based on the weights. The updated route does not include the target path.

[0297] In some embodiments, the game scene includes a displacement trigger, which carries a triggering condition and a displacement strategy, and further includes:

[0298] Get the location of non-player characters in the game scene;

[0299] If the position meets the triggering conditions, the non-player character will be controlled to move within the area controlled by the displacement trigger according to the displacement strategy.

[0300] In some embodiments, the displacement strategy includes a displacement direction. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including:

[0301] If the position meets the triggering conditions, the non-player character is controlled to move in the direction of displacement according to the displacement strategy until the non-player character leaves the area controlled by the displacement trigger.

[0302] In some embodiments, the area controlled by the displacement trigger includes a control path, which facilitates the non-player character's escape from the area controlled by the displacement trigger. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to a displacement strategy, including:

[0303] If the location meets the triggering conditions, determine the opening status of the control path;

[0304] Depending on the activation status, non-player characters are controlled to move along the controlled path according to the displacement strategy.

[0305] In practice, each of the above units can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units, please refer to the previous method embodiments, which will not be repeated here.

[0306] As can be seen from the above, the control device for the non-player character in this embodiment obtains the movement route of the non-player character in the game scene by the acquisition unit. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the starting point of the next sub-path in two adjacent sub-paths. The speed determination unit determines the offset speed based on the speed of the non-player character in the first direction when it is at the end point of the first sub-path and the speed of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the multiple sub-paths except the last one. The second sub-path is the next sub-path after the first sub-path. The offset determination unit predicts the offset distance of the non-player character based on the offset speed and the preset acceleration, where the preset acceleration is the acceleration set in the game scene. The adjustment unit adjusts the speed of the non-player character in the first direction when it is at the end point of the first sub-path based on the offset distance. By adjusting the speed in the first direction and the speed in the second direction corresponding to the starting point of the preset second sub-path, the non-player character is controlled to move along the second sub-path. The second direction is the direction along the second sub-path.

[0307] Therefore, the embodiments of this application can make the movement of non-player characters in the game scene conform to the movement of objects in the real scene, improve the movement of non-player characters in the game scene, and make their movement more natural.

[0308] Accordingly, this application also provides an electronic device, which can be a terminal or a server. The terminal can be a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer, personal digital assistant (PDA) and other terminal devices.

[0309] like Figure 4 As shown, Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 400 includes a processor 410 with one or more processing cores, a memory 420 with one or more computer-readable storage media, and a computer program stored in the memory 420 and executable on the processor. The processor 410 is electrically connected to the memory 420. Those skilled in the art will understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0310] The processor 410 is the control center of the electronic device 400. It connects various parts of the electronic device 400 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 420, and calling data stored in the memory 420, it performs various functions of the electronic device 400 and processes data, thereby monitoring the electronic device 400 as a whole.

[0311] In this embodiment, the processor 410 in the electronic device 400 loads the instructions corresponding to the processes of one or more applications into the memory 420 according to the following steps, and the processor 410 runs the applications stored in the memory 420 to realize various functions:

[0312] A method for controlling a non-player character includes:

[0313] Obtain the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in any two adjacent sub-paths.

[0314] The offset speed is determined based on the speed of the non-player character in the first direction when the character is at the end of the first sub-path and the speed of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the multiple sub-paths except the last one. The second sub-path is the sub-path after the first sub-path.

[0315] Based on the offset velocity and preset acceleration, predict the offset distance of non-player characters. The preset acceleration is the acceleration set in the game scene.

[0316] Based on the offset distance, the speed of the non-player character at the end of the first sub-path in the first direction is adjusted. By using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path, the non-player character is controlled to move along the second sub-path. The second direction is the direction along the second sub-path.

[0317] In some embodiments, the velocity in the first direction includes a non-offset velocity, the direction of which is the same as the second direction. Based on the offset distance, the velocity in the first direction of the non-player character at the end of the first sub-path is adjusted so that the non-player character can be controlled to move along the second sub-path by using the adjusted velocity in the first direction and the velocity in the second direction corresponding to the preset start point of the second sub-path. This includes:

[0318] If the offset distance is outside the preset range, the offset speed is eliminated;

[0319] Based on the non-player character's non-offset velocity at the end of the first sub-path and the velocity in the second direction corresponding to the preset start point of the second sub-path, control the non-player character to move along the second sub-path;

[0320] If the offset distance is within the preset range, the non-player character is controlled to move along the second sub-path based on the speed of the non-player character in the first direction and the speed of the second direction at the end of the first sub-path.

[0321] In some embodiments, the second sub-path carries at least one movement information, including the movement type of the non-player character, and the starting point and ending point corresponding to the movement type. After adjusting the speed of the non-player character in a first direction at the end of the first sub-path based on the offset distance, and controlling the non-player character to move along the second sub-path using the adjusted speed in the first direction and the speed in a second direction corresponding to the preset starting point of the second sub-path, the method further includes:

[0322] Obtain the real-time position of a non-player character moving along the second sub-path, and at least one piece of movement information containing target movement information corresponding to the real-time position;

[0323] Based on the movement type in the target movement information, control the non-player character to move from the target starting point to the target ending point. The target starting point and target ending point are the starting point and ending point corresponding to the movement type in the target movement information.

[0324] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0325] When the movement type in the target movement information is jump type, calculate the free fall time corresponding to the vertical height. The vertical height is the height difference between the real-time position and the target endpoint. The target endpoint is the endpoint corresponding to the movement type in the target movement information.

[0326] Based on the free fall time and the real-time velocity of the non-player character at its real-time position, determine the horizontal displacement distance of the non-player character during the free fall time.

[0327] Based on the displacement distance, adjust the target start point and target end point located on the second sub-path so that the horizontal distance between the adjusted target start point and target end point is equal to the displacement distance. The target start point is the start point corresponding to the movement type in the target movement information.

[0328] Based on the real-time speed of the non-player character at the adjusted target starting point, control the non-player character to jump from the adjusted target starting point to the adjusted target endpoint.

[0329] In some embodiments, the velocity in the first direction includes a non-offset velocity, and before determining the displacement distance of the non-player character in the horizontal direction during the free fall time based on the free fall time and the real-time velocity of the non-player character at the real-time position, it further includes:

[0330] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the first real-time non-offset velocity of the non-player character at the real-time position;

[0331] Based on the first real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the real-time position;

[0332] Before controlling the non-player character to jump from the adjusted target starting point to the adjusted target endpoint based on the non-player character's real-time speed at the adjusted target starting point, the following is also included:

[0333] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the second real-time non-offset velocity of the non-player character at the adjusted target starting point;

[0334] Based on the second real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the adjusted target starting point.

[0335] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0336] If the movement type in the target movement information is the target movement type, obtain the real-time target movement position of the non-player character moving from the target starting point to the target ending point. The target movement type is the movement type corresponding to climbing over obstacles.

[0337] Determine the real-time distance between the target's current location and the second sub-path;

[0338] If the real-time distance is outside the preset range, adjust the movement direction of the non-player character at the real-time target movement position so that the non-player character moves towards the target endpoint.

[0339] In some embodiments, after adjusting the movement direction of the non-player character at the real-time target movement position if the real-time distance is outside a preset range, the method further includes:

[0340] Get the number of adjustments. The number of adjustments is the number of times a non-player character adjusts the movement direction when moving from the target starting point to the target ending point.

[0341] If the number of adjustments exceeds the preset number, the route to be moved is updated. The updated route is the path between the target starting point and the end point of the original route.

[0342] In some embodiments, after obtaining the number of adjustments, the method further includes:

[0343] If the number of adjustments exceeds the preset number, the weight corresponding to the target path is determined. The target path is the path between the target start point and the target end point in the second sub-path. The weight represents the difficulty of controlling the non-player character to move along the target path.

[0344] If the number of adjustments exceeds the preset limit, update the route to be moved, including:

[0345] Update the route to be moved based on the weights. The updated route does not include the target path.

[0346] In some embodiments, the game scene includes a displacement trigger, which carries a triggering condition and a displacement strategy, and further includes:

[0347] Get the location of non-player characters in the game scene;

[0348] If the position meets the triggering conditions, the non-player character will be controlled to move within the area controlled by the displacement trigger according to the displacement strategy.

[0349] In some embodiments, the displacement strategy includes a displacement direction. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including:

[0350] If the position meets the triggering conditions, the non-player character is controlled to move in the direction of displacement according to the displacement strategy until the non-player character leaves the area controlled by the displacement trigger.

[0351] In some embodiments, the area controlled by the displacement trigger includes a control path, which facilitates the non-player character's escape from the area controlled by the displacement trigger. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to a displacement strategy, including:

[0352] If the location meets the triggering conditions, determine the opening status of the control path;

[0353] Depending on the activation status, non-player characters are controlled to move along the controlled path according to the displacement strategy.

[0354] In some embodiments, before obtaining the movement route of a non-player character in the game scene, the process includes:

[0355] Obtain the starting point and ending point of movement for non-player characters in the game scene, as well as the midpoint between the starting point and the ending point;

[0356] Based on the starting point, intermediate point, and ending point of the movement, a sub-path is determined. A sub-path is a path between two adjacent points, which are any two adjacent points among the starting point, intermediate point, and ending point of the movement.

[0357] Determine the route to be moved based on all sub-paths.

[0358] In some embodiments, determining the route to be moved based on all sub-paths includes:

[0359] Obtain information about obstacles between the target sub-path, the next sub-path of the target sub-path, the start point of the target sub-path, and the end point of the next sub-path. The target sub-path is any sub-path among all sub-paths.

[0360] Based on the starting point of the target sub-path, the ending point of the next sub-path, and obstacle information, the target sub-path and the next sub-path are smoothed to obtain the smoothed sub-path.

[0361] Determine the route to be moved based on all the smoothed sub-paths.

[0362] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0363] Optional, such as Figure 4As shown, the electronic device 400 also includes: a touch display screen 430, a radio frequency circuit 440, an audio circuit 450, an input unit 460, and a power supply 470. The processor 410 is electrically connected to the touch display screen 430, the radio frequency circuit 440, the audio circuit 450, the input unit 460, and the power supply 470. Those skilled in the art will understand that... Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0364] The touch display screen 430 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 430 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 410. It can also receive and execute commands from the processor 410. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 410 to determine the type of touch event. Subsequently, the processor 410 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 430 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 430 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 430 can also be used as part of the input unit 460 to achieve input functions.

[0365] In this embodiment, a game application is executed by processor 410 to generate a graphical user interface (GUI) on touch display screen 430. The virtual scene on the GUI includes at least one skill control area, and the skill control area includes at least one skill control. The touch display screen 430 is used to present the GUI and receive operation commands generated by the user interacting with the GUI.

[0366] The radio frequency circuit 440 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other electronic devices, and to transmit and receive signals with network devices or other electronic devices.

[0367] Audio circuitry 450 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuitry 450 can convert received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuitry 450, converted back into audio data, and then processed by processor 410 before being transmitted via radio frequency circuitry 440 to, for example, another electronic device, or output to memory 420 for further processing. Audio circuitry 450 may also include an earphone jack to provide communication between peripheral headphones and electronic devices.

[0368] The input unit 460 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.

[0369] Power supply 470 is used to power various components of electronic device 400. Optionally, power supply 470 can be logically connected to processor 410 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 470 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0370] although Figure 4 As not shown in the diagram, the electronic device 400 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.

[0371] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0372] As can be seen from the above, the electronic device provided in this embodiment can make the movement of non-player characters in the game scene match the movement of objects in the real scene, thus improving the movement of non-player characters in the game scene and making their movement more natural.

[0373] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0374] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of computer programs that can be loaded by a processor to execute steps in any of the non-player character control methods provided in embodiments of this application. For example, the computer program can execute the following steps:

[0375] A method for controlling a non-player character includes:

[0376] Obtain the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in any two adjacent sub-paths.

[0377] The offset speed is determined based on the speed of the non-player character in the first direction when the character is at the end of the first sub-path and the speed of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the multiple sub-paths except the last one. The second sub-path is the sub-path after the first sub-path.

[0378] Based on the offset velocity and preset acceleration, predict the offset distance of non-player characters. The preset acceleration is the acceleration set in the game scene.

[0379] Based on the offset distance, the speed of the non-player character at the end of the first sub-path in the first direction is adjusted. By using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path, the non-player character is controlled to move along the second sub-path. The second direction is the direction along the second sub-path.

[0380] In some embodiments, the velocity in the first direction includes a non-offset velocity, the direction of which is the same as the second direction. Based on the offset distance, the velocity in the first direction of the non-player character at the end of the first sub-path is adjusted so that the non-player character can be controlled to move along the second sub-path by using the adjusted velocity in the first direction and the velocity in the second direction corresponding to the preset start point of the second sub-path. This includes:

[0381] If the offset distance is outside the preset range, the offset speed is eliminated;

[0382] Based on the non-player character's non-offset velocity at the end of the first sub-path and the velocity in the second direction corresponding to the preset start point of the second sub-path, control the non-player character to move along the second sub-path;

[0383] If the offset distance is within the preset range, the non-player character is controlled to move along the second sub-path based on the speed of the non-player character in the first direction and the speed of the second direction at the end of the first sub-path.

[0384] In some embodiments, the second sub-path carries at least one movement information, including the movement type of the non-player character, and the starting point and ending point corresponding to the movement type. After adjusting the speed of the non-player character in a first direction at the end of the first sub-path based on the offset distance, and controlling the non-player character to move along the second sub-path using the adjusted speed in the first direction and the speed in a second direction corresponding to the preset starting point of the second sub-path, the method further includes:

[0385] Obtain the real-time position of a non-player character moving along the second sub-path, and at least one piece of movement information containing target movement information corresponding to the real-time position;

[0386] Based on the movement type in the target movement information, control the non-player character to move from the target starting point to the target ending point. The target starting point and target ending point are the starting point and ending point corresponding to the movement type in the target movement information.

[0387] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0388] When the movement type in the target movement information is jump type, calculate the free fall time corresponding to the vertical height. The vertical height is the height difference between the real-time position and the target endpoint. The target endpoint is the endpoint corresponding to the movement type in the target movement information.

[0389] Based on the free fall time and the real-time velocity of the non-player character at its real-time position, determine the horizontal displacement distance of the non-player character during the free fall time.

[0390] Based on the displacement distance, adjust the target start point and target end point located on the second sub-path so that the horizontal distance between the adjusted target start point and target end point is equal to the displacement distance. The target start point is the start point corresponding to the movement type in the target movement information.

[0391] Based on the real-time speed of the non-player character at the adjusted target starting point, control the non-player character to jump from the adjusted target starting point to the adjusted target endpoint.

[0392] In some embodiments, the velocity in the first direction includes a non-offset velocity, and before determining the displacement distance of the non-player character in the horizontal direction during the free fall time based on the free fall time and the real-time velocity of the non-player character at the real-time position, it further includes:

[0393] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the first real-time non-offset velocity of the non-player character at the real-time position;

[0394] Based on the first real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the real-time position;

[0395] Before controlling the non-player character to jump from the adjusted target starting point to the adjusted target endpoint based on the non-player character's real-time speed at the adjusted target starting point, the following is also included:

[0396] Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the second real-time non-offset velocity of the non-player character at the adjusted target starting point;

[0397] Based on the second real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the adjusted target starting point.

[0398] In some embodiments, controlling a non-player character to move from a target starting point to a target ending point based on the movement type in the target movement information includes:

[0399] If the movement type in the target movement information is the target movement type, obtain the real-time target movement position of the non-player character moving from the target starting point to the target ending point. The target movement type is the movement type corresponding to climbing over obstacles.

[0400] Determine the real-time distance between the target's current location and the second sub-path;

[0401] If the real-time distance is outside the preset range, adjust the movement direction of the non-player character at the real-time target movement position so that the non-player character moves towards the target endpoint.

[0402] In some embodiments, after adjusting the movement direction of the non-player character at the real-time target movement position if the real-time distance is outside a preset range, the method further includes:

[0403] Get the number of adjustments. The number of adjustments is the number of times a non-player character adjusts the movement direction when moving from the target starting point to the target ending point.

[0404] If the number of adjustments exceeds the preset number, the route to be moved is updated. The updated route is the path between the target starting point and the end point of the original route.

[0405] In some embodiments, after obtaining the number of adjustments, the method further includes:

[0406] If the number of adjustments exceeds the preset number, the weight corresponding to the target path is determined. The target path is the path between the target start point and the target end point in the second sub-path. The weight represents the difficulty of controlling the non-player character to move along the target path.

[0407] If the number of adjustments exceeds the preset limit, update the route to be moved, including:

[0408] Update the route to be moved based on the weights. The updated route does not include the target path.

[0409] In some embodiments, the game scene includes a displacement trigger, which carries a triggering condition and a displacement strategy, and further includes:

[0410] Get the location of non-player characters in the game scene;

[0411] If the position meets the triggering conditions, the non-player character will be controlled to move within the area controlled by the displacement trigger according to the displacement strategy.

[0412] In some embodiments, the displacement strategy includes a displacement direction. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including:

[0413] If the position meets the triggering conditions, the non-player character is controlled to move in the direction of displacement according to the displacement strategy until the non-player character leaves the area controlled by the displacement trigger.

[0414] In some embodiments, the area controlled by the displacement trigger includes a control path, which facilitates the non-player character's escape from the area controlled by the displacement trigger. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to a displacement strategy, including:

[0415] If the location meets the triggering conditions, determine the opening status of the control path;

[0416] Depending on the activation status, non-player characters are controlled to move along the controlled path according to the displacement strategy.

[0417] In some embodiments, before obtaining the movement route of a non-player character in the game scene, the process includes:

[0418] Obtain the starting point and ending point of movement for non-player characters in the game scene, as well as the midpoint between the starting point and the ending point;

[0419] Based on the starting point, intermediate point, and ending point of the movement, a sub-path is determined. A sub-path is a path between two adjacent points, which are any two adjacent points among the starting point, intermediate point, and ending point of the movement.

[0420] Determine the route to be moved based on all sub-paths.

[0421] In some embodiments, determining the route to be moved based on all sub-paths includes:

[0422] Obtain information about obstacles between the target sub-path, the next sub-path of the target sub-path, the start point of the target sub-path, and the end point of the next sub-path. The target sub-path is any sub-path among all sub-paths.

[0423] Based on the starting point of the target sub-path, the ending point of the next sub-path, and obstacle information, the target sub-path and the next sub-path are smoothed to obtain the smoothed sub-path.

[0424] Determine the route to be moved based on all the smoothed sub-paths.

[0425] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0426] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0427] Since the computer program stored in the storage medium can execute the steps in any of the non-player character control methods provided in the embodiments of this application, the beneficial effects that any of the non-player character control methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.

[0428] The foregoing has provided a detailed description of a non-player character control method, device, electronic device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for controlling a non-player character, characterized in that, include: Obtain the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the endpoint of the preceding sub-path is connected to the starting point of the following sub-path in two adjacent sub-paths. The offset speed is determined based on the speed in the first direction when the non-player character is at the end of the first sub-path and the second sub-path. The offset speed is the component of the speed in the first direction perpendicular to the direction of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the plurality of sub-paths except the last sub-path. The second sub-path is the sub-path following the first sub-path. Based on the offset velocity and the preset acceleration, the offset distance of the non-player character is predicted, where the preset acceleration is the acceleration corresponding to the resistance set in the game scene; Based on the offset distance, the speed of the non-player character in the first direction at the end of the first sub-path is adjusted, so that the non-player character can be controlled to move along the second sub-path by the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path, where the second direction is the direction along the second sub-path; Wherein, the velocity in the first direction includes a non-offset velocity, the velocity direction of which is the same as that in the second direction; the step of adjusting the velocity in the first direction of the non-player character at the end of the first sub-path based on the offset distance, so as to control the non-player character to move along the second sub-path by means of the adjusted velocity in the first direction and the velocity in the second direction corresponding to the preset starting point of the second sub-path, includes: If the offset distance is outside the preset range, the offset speed is eliminated; Based on the non-player character's non-offset speed at the end of the first sub-path and the speed in the second direction corresponding to the preset starting point of the second sub-path, the non-player character is controlled to move along the second sub-path; If the offset distance is within a preset range, the non-player character is controlled to move along the second sub-path based on the speed of the non-player character in the first direction and the speed in the second direction at the end of the first sub-path.

2. The method for controlling a non-player character as described in claim 1, characterized in that, The second sub-path carries at least one movement information, including the movement type of the non-player character and the starting and ending points corresponding to the movement type. After adjusting the speed of the non-player character in the first direction at the end of the first sub-path based on the offset distance, and controlling the non-player character to move along the second sub-path using the adjusted speed in the first direction and the speed in the second direction corresponding to the preset starting point of the second sub-path, the method further includes: Obtain the real-time position of the non-player character moving along the second sub-path, and the target movement information corresponding to the real-time position in the at least one movement information; Based on the movement type in the target movement information, the non-player character is controlled to move from the target starting point to the target ending point, where the target starting point and the target ending point are the starting point and ending point corresponding to the movement type in the target movement information.

3. The method for controlling a non-player character as described in claim 2, characterized in that, The step of controlling the non-player character to move from the target starting point to the target ending point according to the movement type in the target movement information includes: When the movement type in the target movement information is a jump type, the free fall time corresponding to the vertical height is calculated, where the vertical height is the height difference between the real-time position and the target endpoint, and the target endpoint is the endpoint corresponding to the movement type in the target movement information. Based on the free fall time and the real-time velocity of the non-player character at the real-time position, determine the horizontal displacement distance of the non-player character during the free fall time. Based on the displacement distance, the target starting point and the target ending point located on the second sub-path are adjusted so that the horizontal distance between the adjusted target starting point and the target ending point is equal to the displacement distance, wherein the target starting point is the starting point corresponding to the movement type in the target movement information; Based on the real-time speed of the non-player character at the adjusted target starting point, control the non-player character to jump from the adjusted target starting point to the adjusted target endpoint.

4. The method for controlling a non-player character as described in claim 3, characterized in that, The velocity in the first direction includes a non-offset velocity. Before determining the horizontal displacement distance of the non-player character during the free fall time based on the free fall time and the real-time velocity of the non-player character at the real-time position, the method further includes: Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the first real-time non-offset velocity of the non-player character at the real-time position; Based on the first real-time non-offset velocity and the velocity in the second direction, determine the real-time velocity of the non-player character at the real-time position; Before controlling the non-player character to jump from the adjusted target starting point to the adjusted target endpoint based on the non-player character's real-time speed at the adjusted target starting point, the method further includes: Based on the preset acceleration and the non-player character's non-offset velocity at the end of the first sub-path, determine the second real-time non-offset velocity of the non-player character at the adjusted target starting point; Based on the second real-time non-offset velocity and the velocity in the second direction, the real-time velocity of the non-player character at the adjusted target starting point is determined.

5. The method for controlling a non-player character as described in claim 2, characterized in that, The step of controlling the non-player character to move from the target starting point to the target ending point according to the movement type in the target movement information includes: If the movement type in the target movement information is a target movement type, obtain the real-time target movement position of the non-player character moving from the target starting point to the target ending point, where the target movement type is the movement type corresponding to climbing over obstacles; Determine the real-time distance between the real-time target's moving position and the second sub-path; If the real-time distance is outside the preset range, adjust the movement direction of the non-player character at the real-time target movement position so that the non-player character moves towards the target endpoint.

6. The method for controlling a non-player character as described in claim 5, characterized in that, After adjusting the movement direction of the non-player character at the real-time target movement position when the real-time distance is outside the preset range, the method further includes: The number of adjustments is the number of times the non-player character adjusts the movement direction when moving from the target starting point to the target ending point; If the number of adjustments exceeds a preset number, the route to be moved is updated. The updated route to be moved is the path between the target starting point and the end point of the route to be moved before the update.

7. The method for controlling a non-player character as described in claim 6, characterized in that, After obtaining the number of adjustments, the method further includes: If the number of adjustments exceeds a preset number, the weight corresponding to the target path is determined. The target path is the path between the target starting point and the target ending point in the second sub-path. The weight represents the difficulty of controlling the non-player character to move along the target path. If the number of adjustments exceeds a preset number, the route to be moved is updated, including: The route to be moved is updated according to the weight, and the updated route to be moved does not include the target path.

8. The method for controlling a non-player character as described in claim 1, characterized in that, The game scene includes a displacement trigger, which carries a triggering condition and a displacement strategy, and also includes: Obtain the position of the non-player character in the game scene; If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy.

9. The method for controlling a non-player character as described in claim 8, characterized in that, The displacement strategy includes a displacement direction, and if the position meets the triggering condition, then the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including: If the position meets the triggering condition, the non-player character is controlled to move in the displacement direction according to the displacement strategy until the non-player character leaves the area controlled by the displacement trigger.

10. The method for controlling a non-player character as described in claim 8, characterized in that, The area controlled by the displacement trigger includes a control path, which facilitates the non-player character's escape from the area controlled by the displacement trigger. If the position meets the triggering condition, the non-player character is controlled to move within the area controlled by the displacement trigger according to the displacement strategy, including: If the location meets the triggering condition, determine the opening status of the control path; Based on the activation state, the non-player character is controlled to move along the controlled path according to the displacement strategy.

11. The method for controlling a non-player character as described in claim 1, characterized in that, Before obtaining the movement route of the non-player character in the game scene, the following steps are included: Obtain the starting point and ending point of movement for non-player characters in the game scene, as well as the midpoint between the starting point and the ending point; Based on the starting point, the intermediate point, and the ending point, a sub-path is determined. The sub-path is a path between two adjacent points, where the two adjacent points are any two adjacent points among the starting point, the intermediate point, and the ending point. Determine the route to be moved based on all the described sub-paths.

12. The method for controlling a non-player character as described in claim 11, characterized in that, The step of determining the route to be moved based on all the sub-paths includes: Obtain obstacle information between the target sub-path, the next sub-path of the target sub-path, the starting point of the target sub-path, and the ending point of the next sub-path, wherein the target sub-path is any one of the sub-paths; Based on the starting point of the target sub-path, the ending point of the next sub-path, and the obstacle information, the target sub-path and the next sub-path are smoothed to obtain a smoothed sub-path. Based on all the smoothed sub-paths, determine the route to be moved.

13. A control device for a non-player character, characterized in that, include: The acquisition unit is used to acquire the movement route of a non-player character in the game scene. The movement route includes multiple sub-paths, and the end point of the previous sub-path is connected to the start point of the next sub-path in two adjacent sub-paths. A speed determination unit is used to determine an offset speed based on the speed in a first direction when the non-player character is located at the end of the first sub-path and the second sub-path. The offset speed is the component of the speed in the first direction perpendicular to the direction of the second sub-path. The direction of the offset speed is perpendicular to the second sub-path. The first direction is the direction along the first sub-path. The first sub-path is any one of the plurality of sub-paths except the last sub-path. The second sub-path is the sub-path following the first sub-path. The speed in the first direction includes non-offset speed. The offset determination unit is used to predict the offset distance of the non-player character based on the offset velocity and the preset acceleration, wherein the preset acceleration is the acceleration corresponding to the resistance set in the game scene; An adjustment unit is used to eliminate the offset speed if the offset distance is outside a preset range; Based on the non-player character's non-offset speed at the end of the first sub-path and the speed in the second direction corresponding to the preset starting point of the second sub-path, the non-player character is controlled to move along the second sub-path; if the offset distance is within a preset range, the non-player character is controlled to move along the second sub-path based on the speed in the first direction and the speed in the second direction at the end of the first sub-path, where the second direction is the direction along the second sub-path, and the speed direction of the non-offset speed is the same as the second direction.

14. An electronic device, characterized in that, It includes a processor and a memory, the memory storing multiple instructions; the processor loads instructions from the memory to perform the steps in the non-player character control method as described in any one of claims 1 to 12.

15. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to perform the steps of the non-player character control method according to any one of claims 1 to 12.