CN-115920400-B - Control method and device for non-player character, electronic equipment and storage medium
Abstract
The embodiment of the application discloses a control method, a device, electronic equipment and a storage medium for a non-player character, wherein the method, the device, the electronic equipment and the storage medium can acquire a to-be-moved route of the non-player character in a game scene, the to-be-moved route comprises a plurality of sub-paths, an offset speed is determined according to the speed of the non-player character in a first direction when the non-player character is located at a first sub-path end point and a second sub-path, an offset distance of the non-player character is predicted according to the offset speed and a preset acceleration, the speed of the non-player character in the first direction of the first sub-path end point is adjusted based on the offset distance, and the non-player character is controlled to move along the second sub-path through the adjusted speed of the first direction and the speed of the non-player character in a second direction corresponding to a preset second sub-path start point. In the embodiment of the application, the movement of the non-player character in the game scene is improved, so that the movement is natural.
Inventors
- SUN MINGQI
Assignees
- 网易(杭州)网络有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20221219
Claims (15)
- 1. A method for controlling a non-player character, comprising: Acquiring a to-be-moved route of a non-player character in a game scene, wherein the to-be-moved route comprises a plurality of sub-paths, and the end point of a previous sub-path in two adjacent sub-paths is connected with the start point of a next sub-path; Determining an offset speed according to a speed of the non-player character in a first direction and a second sub-path when the non-player character is at the end point of the first sub-path, wherein the offset speed is a component of the speed of the first direction along a direction perpendicular to the second sub-path, the speed direction of the offset speed is perpendicular to the second sub-path, the first direction is along the first sub-path, the first sub-path is any sub-path except the last sub-path in the plurality of sub-paths, and the second sub-path is a sub-path after the first sub-path; predicting the offset distance of the non-player character according to the offset speed and a preset acceleration, wherein the preset acceleration is the acceleration corresponding to the resistance set in the game scene; Based on the offset distance, adjusting the speed of the non-player character in the first direction of a first sub-path end point to control the non-player character to move along a second sub-path according to the adjusted speed in the first direction and a preset speed in a second direction corresponding to a second sub-path start point, wherein the second direction is a direction along the second sub-path; The speed in the first direction includes a non-offset speed, the speed direction of the non-offset speed is the same as the second direction, the speed in the first direction of the non-player character at the end point of the first sub-path is adjusted based on the offset distance, so as to control the non-player character to move along the second sub-path through the adjusted speed in the first direction and a preset speed in the second direction corresponding to the start point of the second sub-path, and the method includes: if the offset distance is out of the preset range, eliminating the offset speed; controlling the non-player character to move along the second sub-path based on the non-offset speed of the non-player character at the end point of the first sub-path and a preset speed in a second direction corresponding to the start point of the second sub-path; and if the offset distance is within the preset range, controlling the non-player character to move along the second sub-path according to the speed of the non-player character in the first direction and the speed of the non-player character in the second direction at the end point of the first sub-path.
- 2. The method for controlling a non-player character according to claim 1, wherein the second sub-path carries at least one movement information, the movement information including a movement type of the non-player character, and a start point and an end point corresponding to the movement type, and after the adjusting the speed of the non-player character in the first direction at the end point of the first sub-path based on the offset distance, to control the movement of the non-player character along the second sub-path by the adjusted speed in the first direction and a preset speed in a second direction corresponding to the start point of the second sub-path, further comprising: acquiring a real-time position of the non-player character moving along the second sub-path and target movement information corresponding to the real-time position in the at least one movement information; And controlling the non-player character to move from a target starting point to a target destination according to the movement type in the target movement information, wherein the target starting point and the target destination are a starting point and a destination corresponding to the movement type in the target movement information.
- 3. The method of controlling a non-player character according to claim 2, wherein controlling the non-player character to move from a target start point to a target end point according to a movement type in the target movement information comprises: When the movement type in the target movement information is a jump type, calculating free falling time corresponding to vertical height, wherein the vertical height is a height difference between the real-time position and a target end point, and the target end point is an end point corresponding to the movement type in the target movement information; Determining a displacement distance of the non-player character in the horizontal direction in the free fall time based on the free fall time and a real-time speed of the non-player character at the real-time position; According to the displacement distance, adjusting a target starting point and the target end point which are positioned on the second sub-path, so that the horizontal distance between the adjusted target starting point and the adjusted target end point is equal to the displacement distance, wherein the target starting point is a starting point corresponding to a movement type in the target movement information; and controlling the non-player character to jump from the adjusted target starting point to the adjusted target ending point according to the real-time speed of the non-player character at the adjusted target starting point.
- 4. The method of controlling a non-player character according to claim 3, wherein the speed in the first direction includes a non-offset speed, and before the determining of the displacement distance of the non-player character in the horizontal direction in the free-fall time based on the free-fall time and the real-time speed of the non-player character in the real-time position, further comprising: Determining a first real-time non-offset speed of the non-player character at the real-time position according to the preset acceleration and the non-offset speed of the non-player character at the first sub-path end point; Determining a real-time speed of the non-player character at the real-time position according to the first real-time non-offset speed and the speed in the second direction; before controlling the non-player character to jump from the adjusted target starting point to the adjusted target ending point according to the real-time speed of the non-player character at the adjusted target starting point, the method further comprises: Determining a second real-time non-offset speed of the non-player character at the adjusted target starting point according to a preset acceleration and the non-offset speed of the non-player character at the first sub-path ending point; And determining the real-time speed of the non-player character at the adjusted target starting point according to the second real-time non-offset speed and the speed of the second direction.
- 5. The method of controlling a non-player character according to claim 2, wherein controlling the non-player character to move from a target start point to a target end point according to a movement type in the target movement information comprises: if the movement type in the target movement information is a target movement type, acquiring a real-time target movement position of the non-player character moving from a target starting point to a target destination, wherein the target movement type is a movement type corresponding to a crossing obstacle; Determining a real-time distance between the real-time target movement location and the second sub-path; And if the real-time distance is out of the preset range, adjusting the moving direction of the non-player character at the real-time target moving position so as to enable the non-player character to move towards the target end point.
- 6. The method of claim 5, wherein adjusting the movement direction of the non-player character at the real-time target movement position when the real-time distance is outside a preset range, further comprises: Acquiring adjustment times, wherein the adjustment times are times for adjusting the moving direction when the non-player character moves from the target starting point to the target ending point; And if the adjustment times are greater than the preset number, updating the route to be moved, wherein the updated route to be moved is a path between the target starting point and the end point of the route to be moved before updating.
- 7. The method for controlling a non-player character according to claim 6, further comprising, after said obtaining said adjustment times: if the adjustment times are greater than a preset number, determining a weight corresponding to a target path, wherein the target path is a path between the target starting point and the target ending point in the second sub-path, and the weight represents the difficulty of controlling the non-player character to move along the target path; if the adjustment times are greater than a preset number, updating the route to be moved includes: And updating the route to be moved according to the weight, wherein the updated route to be moved does not comprise the target path.
- 8. The method for controlling a non-player character according to claim 1, wherein the game scene includes a displacement trigger, the displacement trigger carrying a trigger condition and a displacement strategy, further comprising: Acquiring the position of the non-player character in the game scene; And if the position meets the trigger condition, controlling the non-player character to move in the area controlled by the displacement trigger according to the displacement strategy.
- 9. The method of controlling a non-player character according to claim 8, wherein the displacement strategy includes a displacement direction, and the controlling the non-player character to move within the area controlled by the displacement trigger according to the displacement strategy if the position satisfies the trigger condition includes: And if the position meets the trigger condition, controlling the non-player character to move towards the displacement direction according to the displacement strategy until the non-player character is separated from the area controlled by the displacement trigger.
- 10. The method of claim 8, wherein the area controlled by the displacement trigger includes a regulating path that facilitates the non-player character to depart from the area controlled by the displacement trigger, and wherein controlling the non-player character to move within the area controlled by the displacement trigger according to the displacement strategy if the position satisfies the trigger condition comprises: if the position meets the triggering condition, determining the opening state of the control path; and controlling the non-player character to move on the control path according to the displacement strategy according to the starting state.
- 11. The method for controlling a non-player character according to claim 1, comprising, before the acquiring a route to be moved by the non-player character in a game scene: Acquiring a moving starting point and a moving end point of a non-player character in a game scene and a middle point between the moving starting point and the moving end point; Determining a sub-path according to the movement starting point, the middle point and the movement ending point, wherein the sub-path is a path between two adjacent points, and the two adjacent points are any two adjacent points in the movement starting point, the middle point and the movement ending point; and determining a route to be moved according to all the sub-paths.
- 12. The method for controlling a non-player character according to claim 11, wherein the determining a route to be moved based on all the sub-paths includes: obtaining a target sub-path, a next sub-path of the target sub-path, and barrier information between a starting point of the target sub-path and an end point of the next sub-path, wherein the target sub-path is any one sub-path in all the sub-paths; Smoothing the target sub-path and the next sub-path according to the starting point of the target sub-path, the ending point of the next sub-path and the barrier information to obtain a sub-path after smoothing; and determining a route to be moved according to all the sub-paths after the smoothing processing.
- 13. A non-player character control device comprising: The device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a to-be-moved route of a non-player character in a game scene, the to-be-moved route comprises a plurality of sub-paths, and the end point of a previous sub-path in two adjacent sub-paths is connected with the start point of a next sub-path; A speed determining unit, configured to determine an offset speed according to a speed of the non-player character in a first direction and a second sub-path when the non-player character is at an end point of the first sub-path, where the offset speed is a component of the speed of the first direction along a direction perpendicular to a direction of the second sub-path, the speed of the offset speed is perpendicular to the second sub-path, the first direction is a direction along the first sub-path, the first sub-path is any sub-path except a last sub-path in the multiple sub-paths, the second sub-path is a sub-path subsequent to the first sub-path, and the speed of the first direction includes a non-offset speed; an offset determining unit, configured to predict an offset distance of the non-player character according to the offset speed and a preset acceleration, where the preset acceleration is an acceleration corresponding to a resistance set in the game scene; The device comprises a first sub-path end point, a second sub-path end point, an adjustment unit, a non-player character moving along the second sub-path, wherein the adjustment unit is used for eliminating the offset speed if the offset distance is out of a preset range, controlling the non-player character to move along the second sub-path based on the non-offset speed of the non-player character at the first sub-path end point and a preset speed of a second sub-path start point corresponding to the second sub-path end point, and controlling the non-player character to move along the second sub-path according to the speed of the non-player character at the first sub-path end point and the speed of the second sub-path end point when the offset distance is in the preset range, wherein the speed of the non-player character is the same as the speed of the non-offset speed along the second sub-path.
- 14. An electronic device comprising a processor and a memory, wherein the memory stores a plurality of instructions, and wherein the processor loads instructions from the memory to perform the steps in the method for controlling a non-player character according to any one of claims 1 to 12.
- 15. A computer readable storage medium storing a plurality of instructions adapted to be loaded by a processor to perform the steps in the method of controlling a non-player character according to any of claims 1 to 12.
Description
Control method and device for non-player character, electronic equipment and storage medium Technical Field The present application relates to the field of computers, and in particular, to a method and apparatus for controlling a non-player character, an electronic device, and a storage medium. Background There are a number of Non-player characters (NPCs) in the game, and the user can control the virtual characters to interact with the NPCs, thereby gaining sense of participation. To enrich the game scenario, there are some NPCs that can move in the game scenario. However, when the NPC is controlled to move, the path of the NPC is firstly obtained, and the position of the NPC on the path is preset at fixed time, so that the position change of the NPC corresponding to a period of continuous time can be obtained, and the NPC is controlled to move in a game scene. Disclosure of Invention The embodiment of the application provides a control method, a device, electronic equipment and a storage medium for a non-player character, which can improve the movement of the non-player character in a game scene so as to make the movement more natural. The embodiment of the application provides a control method of a non-player character, which comprises the following steps: Acquiring a to-be-moved route of a non-player character in a game scene, wherein the to-be-moved route comprises a plurality of sub-paths, and the end point of a former sub-path in two adjacent sub-paths is connected with the start point of a latter sub-path; determining an offset speed according to the speed of the non-player character in the first direction and the speed of the second sub-path when the non-player character is at the end point of the first sub-path, wherein 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 sub-path except the last sub-path in the plurality of sub-paths, and the second sub-path is the subsequent sub-path of the first sub-path; predicting the offset distance of the non-player character according to the offset speed and a preset acceleration, wherein the preset acceleration is the acceleration set in the game scene; And adjusting the speed of the non-player character in the first direction of the end point 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 through the adjusted speed in the first direction and the speed in the second direction corresponding to the preset start point of the second sub-path, wherein the second direction is the direction along the second sub-path. The embodiment of the application also provides a control device of the non-player character, which comprises the following steps: The device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a to-be-moved route of a non-player character in a game scene, the to-be-moved route comprises a plurality of sub-paths, and the end point of a previous sub-path in two adjacent sub-paths is connected with the start point of a next sub-path; A speed determining unit, configured to determine an offset speed according to a speed of the non-player character in a first direction and a second sub-path when the non-player character is at an end point of a first sub-path, where the speed direction of the offset speed is perpendicular to the second sub-path, the first direction is a direction along the first sub-path, the first sub-path is any sub-path except a last sub-path in the multiple sub-paths, and the second sub-path is a sub-path after the first sub-path; The offset determining unit is used for predicting the offset distance of the non-player character according to the offset speed and preset acceleration, wherein the preset acceleration is the acceleration set in the game scene; The adjusting unit is used for adjusting the speed of the non-player character in the first direction of the end point 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 through the adjusted speed in the first direction and the speed of the non-player character in the second direction corresponding to the preset start point of the second sub-path, wherein the second direction is the direction along the second sub-path. In some embodiments, the speed in the first direction includes a non-offset speed, the speed direction of the non-offset speed is the same as the second direction, the speed of the non-player character in the first direction at the end of the first sub-path is adjusted based on the offset distance, so as to control the non-player character to move along the second sub-path through the adjusted speed in the first direction and the speed in the second direction corresponding to the preset start of the second sub-path, including: if t