Virtual object control method based on distance from player-controlled virtual object
View Patent ↗A virtual object control method includes controlling a first virtual object in a virtual environment through a first behavior tree, the first virtual object being a Non-Player character (NPC) in the virtual environment, and obtaining a first distance between the first virtual object and a second virtual object controlled by a player in the virtual environment, the second virtual object being a closest virtual object controlled by a player to the first virtual object. The method further includes selecting, based on the first distance, a behavior tree among plural behavior trees for controlling the first virtual object. The first distance inversely relates to an amount of computing resources consumed during use of the selected behavior tree.
1 . A virtual object control method performed by at least one processor, the method comprising:
outputting for display a first virtual object in a virtual environment;
controlling the first virtual object in the displayed virtual environment through a first behavior tree, the first virtual object being a Non-Player character (NPC) in the virtual environment;
obtaining a first distance between the first virtual object and a second virtual object controlled by a player in the displayed virtual environment, the second virtual object being a closest virtual object controlled by the player to the first virtual object;
selecting, based on the first distance, a second behavior tree among plural behavior trees for controlling the first virtual object, wherein each of the plural behavior trees has a different complexity level and computational cost, and the complexity level of the selected second behavior tree decreases as the first distance increases; and
controlling the first virtual object to perform actions in the displayed virtual environment based on the selected second behavior tree.
2 . The method according to claim 1 , wherein the selecting the second behavior tree comprises:
selecting the second behavior tree in response to a determination that the first distance falls within a distance range among at least two distance ranges corresponding to the second virtual object, the selected second behavior tree corresponding to the distance range,
each distance range of the at least two distance ranges corresponds to one behavior tree among the plural behavior trees.
3 . The method according to claim 2 , wherein the virtual environment includes plural virtual objects controlled by different players; and
the method further comprises determining a distance between the first virtual object and each of two or more of the plural virtual objects controlled by the different players to determine one of the plural virtual objects controlled by the different players as the second virtual object that is the closest virtual object controlled by the player to the first virtual object.
4 . The method according to claim 1 , wherein the selecting the second behavior tree comprises:
replacing the first behavior tree with the selected second behavior tree; and
determining that the first virtual object is controlled through the selected second behavior tree, the selected second behavior tree corresponding to the first distance.
5 . The method according to claim 1 , wherein the selecting the second behavior tree comprises:
adjusting a first update cycle of the first behavior tree into a second update cycle based on the first distance, the first update cycle and the second update cycle indicating a time interval between outputting two subsequent decisions by the first behavior tree;
determining the first behavior tree using the second update cycle as the selected second behavior tree; and
determining that the first virtual object is controlled through the selected second behavior tree.
6 . The method according to claim 5 , further comprising:
adjusting a third update cycle of a service node of the first behavior tree into a fourth update cycle;
the fourth update cycle corresponding to the first distance, the service node updating data for running the first behavior tree, and the third update cycle and the fourth update cycle indicating a time interval between two adjacent updates performed by the service node.
7 . The method according to claim 1 , wherein
one sequence node of the selected second behavior tree is attached with m decorator nodes; and
the method further comprises:
performing, in controlling the first virtual object through the selected second behavior tree, condition determination once on the m decorator nodes after target data is updated for the last time within a k th update cycle of the selected second behavior tree, wherein
the target data is input data for running the selected second behavior tree;
the sequence node returns a success value in response to a determination that all child nodes of the sequence node return a success value;
the decorator nodes perform at least one action of determining whether or not to execute a branch where the sequence node is located, determine to interrupt the branch where the sequence node is located, and determine to interrupt a low-priority branch of the branch where the sequence node is located; and
m and k are positive integers.
8 . The method according to claim 7 , wherein
the target data comprises a blackboard value;
the m decorator nodes pay attention to a same blackboard value;
the blackboard value is updated n times in the k th update cycle, and n is a positive integer; and
the performing the condition determination comprises:
marking a current number of updates of the blackboard value on the sequence node in response to a determination that the blackboard value is updated for an i th time, i being a positive integer not greater than n;
obtaining m calculation results of the m decorator nodes based on the blackboard value after the blackboard value is updated for the n th time, and
performing the condition determination once based on the m calculation results.
9 . The method according to claim 8 , wherein
the m decorator nodes are notified in a traversing manner when the blackboard value is updated for the i th time; and
the marking the current number of updates of the blackboard value on the sequence node comprises:
marking the sequence node once when one of the m decorator nodes is notified, so that the sequence node is marked a total of m times during the i th update of the blackboard value; and
the obtaining the m calculation results of the m decorator nodes comprises:
obtaining the m calculation results of the m decorator nodes based on the blackboard value after the sequence node is marked m*n times.
10 . The method according to claim 1 , wherein types of both the first behavior tree and the selected second behavior tree are Unreal Engine 4 (UE4) behavior trees.
11 . A virtual object display method performed by at least one processor, the method comprising:
outputting for display a first virtual object and a second virtual object in a virtual environment, the first virtual object being a Non-Player character (NPC), the second virtual object being a virtual object controlled by a player;
outputting for display when a first distance between the first virtual object and the second virtual object in the virtual environment is p, the first virtual object being controlled to perform a first quantity of actions based on a first behavior tree having a first complexity level and a first computational cost; and
outputting for display when the first distance is q, the first virtual object being controlled to perform a second quantity of actions based on a second behavior tree having a second complexity level and a second computational cost, wherein
when p is greater than q, the first quantity is less than the second quantity and the first computational cost is less than the second computational cost; and
when p is less than q, the first quantity is greater than the second quantity and the first computational cost is greater than the second computational cost.
12 . A virtual object control apparatus, comprising:
processing circuitry configured to
output for display a first virtual object in a virtual environment;
control the first virtual object in the displayed virtual environment through a first behavior tree, the first virtual object being a Non-Player character (NPC) in the virtual environment;
obtain a first distance between the first virtual object and a second virtual object controlled by a player in the displayed virtual environment, the second virtual object being a closest virtual object controlled by the player to the first virtual object; and
select, based on the first distance, a second behavior tree among plural behavior trees for controlling the first virtual object, wherein each of the plural behavior trees has a different complexity level and computational cost, and the complexity level of the selected second behavior tree decreases as the first distance increases; and
control the first virtual object to perform actions in the displayed virtual environment based on the selected second behavior tree.
13 . The apparatus according to claim 12 , wherein the processing circuitry is further configured to:
select the second behavior tree in response to a determination that the first distance falls within a distance range among at least two distance ranges corresponding to the second virtual object, the selected second behavior tree corresponding to the distance range,
each distance range of the at least two distance ranges corresponds to one behavior tree among the plural behavior trees.
14 . The apparatus according to claim 13 , wherein the virtual environment includes plural virtual objects controlled by different players; and
the processing circuitry is further configured to determine a distance between the first virtual object and each of two or more of the plural virtual objects controlled by the different players to determine one of the plural virtual objects controlled by the different players as the second virtual object that is the closest virtual object controlled by the player to the first virtual object.
15 . The apparatus according to claim 12 , wherein the processing circuitry is further configured to:
replace the first behavior tree with the selected second behavior tree; and
determine that the first virtual object is controlled through the selected second behavior tree, the selected second behavior tree corresponding to the first distance.
16 . The apparatus according to claim 12 , wherein the processing circuitry is further configured to:
adjust a first update cycle of the first behavior tree into a second update cycle based on the first distance, the first update cycle and the second update cycle indicating a time interval between outputting two subsequent decisions by the first behavior tree;
determine the first behavior tree using the second update cycle as the selected second behavior tree; and
determine that the first virtual object is controlled through the selected second behavior tree.
17 . The apparatus according to claim 16 , wherein the processing circuitry is further configured to:
adjust a third update cycle of a service node of the first behavior tree into a fourth update cycle;
the fourth update cycle corresponding to the first distance, the service node updating data for running the first behavior tree, and the third update cycle and the fourth update cycle indicating a time interval between two adjacent updates performed by the service node.
18 . The apparatus according to claim 12 , wherein
one sequence node of the selected second behavior tree is attached with m decorator nodes; and
the processing circuitry is further configured to:
perform, in controlling the first virtual object through the selected second behavior tree, condition determination once on the m decorator nodes after target data is updated for the last time within a k th update cycle of the selected second behavior tree, wherein
the target data is input data for running the selected second behavior tree;
the sequence node returns a success value in response to a determination that all child nodes of the sequence node return a success value;
the decorator nodes perform at least one action of determining whether or not to execute a branch where the sequence node is located, determine to interrupt the branch where the sequence node is located, and determine to interrupt a low-priority branch of the branch where the sequence node is located; and
m and k are positive integers.
19 . The apparatus according to claim 18 , wherein
the target data comprises a blackboard value;
the m decorator nodes pay attention to a same blackboard value;
the blackboard value is updated n times in the k th update cycle, and n is a positive integer; and
the processing circuitry is further configured to:
mark a current number of updates of the blackboard value on the sequence node in response to a determination that the blackboard value is updated for an i th time, i being a positive integer not greater than n;
obtain m calculation results of the m decorator nodes based on the blackboard value after the blackboard value is updated for the n th time, and
perform the condition determination once based on the m calculation results.
20 . The apparatus according to claim 19 , wherein
the m decorator nodes are notified in a traversing manner when the blackboard value is updated for the i th time; and
the processing circuitry is further configured to:
mark the sequence node once when one of the m decorator nodes is notified, so that the sequence node is marked a total of m times during the i th update of the blackboard value; and
obtain the m calculation results of the m decorator nodes based on the blackboard value after the sequence node is marked m*n times.