Virtual object control method and apparatus, electronic device, and storage medium
By decomposing and fusing acceleration in the game, the missile guidance and control process is simplified, the problems of complexity and large computational load in virtual object control are solved, and efficient virtual object control is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2023-03-03
- Publication Date
- 2026-06-02
AI Technical Summary
Existing technologies make it difficult to efficiently apply missile guidance to games, resulting in complex virtual object control and a huge amount of computation, which leads to game lag.
By acquiring the aiming direction of the aiming line and the displacement and velocity of the virtual object, the deviation vector is calculated, and the velocity is decomposed into multiple mutually perpendicular velocity components. The acceleration in the specified direction is calculated, and finally the acceleration is fused to control the virtual object to move along the aiming direction.
It simplifies the missile guidance control process, reduces the amount of computation, and enables efficient virtual object control in games.
Smart Images

Figure CN116173506B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically to virtual object control methods, devices, electronic devices, and storage media. Background Technology
[0002] Missile guidance is a technology used to control the attitude and movement of a missile and guide it to its target. In military games, to enrich the game content, it is often necessary to simulate missile guidance within the game to control the movement of virtual objects and guide them to their targets.
[0003] Missile guidance technology typically involves the design of guidance laws for the missile body, dynamic analysis, design of the propulsion system controller, and analysis of air resistance. The control process is complex and computationally intensive, making it difficult to efficiently apply missile guidance in games to achieve control of virtual objects. Summary of the Invention
[0004] This application provides a virtual object control method, apparatus, electronic device, and storage medium, which can efficiently apply missile guidance in games to achieve control over virtual objects.
[0005] This application provides a virtual object control method, including:
[0006] Obtain the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object;
[0007] Calculate the deviation vector between the virtual object and the aiming starting point based on the displacement of the aiming starting point and the virtual object;
[0008] Based on the deviation vector, the velocity is decomposed into velocity components in multiple specified directions, wherein each of the multiple velocity components is perpendicular to the others, and the multiple specified directions include the aiming direction;
[0009] For each specified direction, the acceleration in the specified direction is calculated based on the velocity component in the specified direction;
[0010] By aggregating the accelerations in all the specified directions, the target acceleration of the virtual object is obtained;
[0011] Based on the target acceleration, the virtual object is controlled to move along the aiming direction.
[0012] This application embodiment also provides a virtual object control device, including:
[0013] The acquisition module is used to acquire the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object;
[0014] The deviation calculation module is used to calculate the deviation vector between the virtual object and the aiming starting point based on the displacement of the aiming starting point and the virtual object.
[0015] A velocity decomposition module is used to decompose the velocity into multiple velocity components in specified directions based on the deviation vector, wherein the multiple velocity components are perpendicular to each other in pairs, and the multiple specified directions include the aiming direction;
[0016] An acceleration calculation module is used to calculate the acceleration in the specified direction for each specified direction based on the velocity component in the specified direction.
[0017] The fusion module is used to fuse all accelerations in the specified directions to obtain the target acceleration of the virtual object;
[0018] The control module is used to control the virtual object to move along the aiming direction based on the target acceleration.
[0019] This application also provides an electronic device, including a memory storing multiple instructions; the processor loads instructions from the memory to execute steps in any of the virtual object control methods provided in this application.
[0020] 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 virtual object control methods provided in this application.
[0021] This application embodiment can obtain the aiming direction and aiming starting point of the aiming line, the displacement and velocity of the virtual object, and calculate the offset vector using the aiming starting point and the displacement of the virtual object. Based on the offset vector, the velocity is decomposed into multiple specified directions to obtain multiple mutually perpendicular velocity components. Then, the acceleration in the specified directions is calculated, and finally, the accelerations in multiple specified directions are fused to obtain the target acceleration. The target acceleration is then used to control the virtual object to move along the aiming direction. Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified, and the amount of calculation in the control is reduced. Thus, missile guidance can be efficiently applied in games to achieve control of virtual objects. Attached Figure Description
[0022] 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.
[0023] Figure 1 This is a schematic diagram illustrating an application scenario of the virtual object control method provided in the embodiments of this application;
[0024] Figure 2 This is a real-world missile guidance and control block diagram provided in the embodiments of this application;
[0025] Figure 3 This is a flowchart illustrating the virtual object control method provided in an embodiment of this application;
[0026] Figure 4 This is a schematic diagram illustrating the calculation of the deviation vector provided in an embodiment of this application;
[0027] Figure 5 This is a schematic diagram of the decomposition of the deviation vector provided in an embodiment of this application;
[0028] Figure 6 This is a schematic diagram of velocity decomposition provided in an embodiment of this application;
[0029] Figure 7 This is another schematic diagram of velocity decomposition provided in the embodiments of this application;
[0030] Figure 8 This is a flowchart illustrating a virtual object control method provided in another embodiment of this application;
[0031] Figure 9 This is a schematic diagram of the trajectory of a virtual missile provided in an embodiment of this application;
[0032] Figure 10 This is a schematic diagram of the structure of the virtual object control device provided in the embodiments of this application;
[0033] Figure 11 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0034] 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.
[0035] This application provides virtual object control methods, apparatus, electronic devices, and storage media.
[0036] Specifically, the virtual object control device 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.
[0037] In some embodiments, the virtual object control device can also be integrated into multiple electronic devices. For example, the virtual object control device can be integrated into multiple servers, and the virtual object control method of this application can be implemented by multiple servers.
[0038] In some embodiments, the server may also be implemented as a terminal.
[0039] For example, refer to Figure 1 This diagram illustrates an application scenario of the virtual object control method provided in this embodiment. The scenario may include a terminal device 1000, a server 2000, a database 3000, and a network 4000. The user's terminal 1000 can connect to the server 2000 via the network 4000. The terminal device 1000 can be any device with computing hardware capable of supporting and executing software products corresponding to the page display; the server 2000 can be a single server or a server cluster; the network 4000 can be a wireless network or a wired network, such as a wireless local area network (WLAN), local area network (LAN), cellular network, 2G network, 3G network, 4G network, 5G network, etc. Furthermore, different terminal devices 1000 can also connect to other terminals or to the server 2000 using their own Bluetooth network or hotspot network. The database 3000 is used to store data generated when the user uses the terminal device 1000 to control virtual objects.
[0040] The terminal device 1000 can have game-related applications installed. After the game application is launched, the graphical user interface of the terminal device 1000 can display virtual scenes, virtual characters, virtual items, etc. in the virtual scenes. Players can operate on the terminal device 1000 so that the server 2000 can execute virtual object control methods.
[0041] When executing the virtual object control method, the server 2000 can obtain the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object; calculate the deviation vector between the virtual object and the aiming starting point based on the aiming starting point and the displacement of the virtual object; decompose the velocity into velocity components in multiple specified directions based on the deviation vector, wherein the multiple velocity components are mutually perpendicular to each other, and the multiple specified directions include the aiming direction; for each specified direction, calculate the acceleration in the specified direction based on the velocity components in the specified direction; fuse the accelerations in all specified directions to obtain the target acceleration of the virtual object; and control the virtual object to move along the aiming direction based on the target acceleration.
[0042] It should be noted that a real-world missile is a rigid body in three-dimensional space, involving movement and rotation in three directions. Real-world missile guidance and control are complex, involving the design of the missile's guidance law, dynamics analysis, propulsion system controller design, and air resistance analysis. (See also...) Figure 2 The diagram illustrates a real-world missile guidance and control system. The guidance system primarily generates guidance commands to control the missile's flight trajectory by collecting information about the missile's own motion and the target's motion. The dynamics controller calculates data such as the actual canard angle change and the size of the thruster fuel valve based on the missile's guidance commands to generate the required angular and linear accelerations, enabling the missile to fly along the trajectory generated by the guidance system.
[0043] Incorporating missile guidance into a game requires significant time investment in learning missile-related knowledge. Furthermore, simulating missile guidance in the game via code necessitates building a simulation platform, which is challenging due to its programming and debugging complexity. The massive computational demands of missile guidance can easily lead to a surge in server CPU consumption, causing game lag. Therefore, when guiding a moving missile in the game, the focus can be solely on generating guidance commands to ensure the virtual missile's trajectory approaches the target according to guidance principles.
[0044] Semi-Automatic Command to Line of Sight (SACLOS) guidance is a common missile guidance method. The missile operator guides the missile along the center of the sight's field of view by aligning the sight with the target, thus hitting the target. The principle behind its guidance command generation is that the missile's exhaust plume position is collected through the sight to determine its distance from the aiming line. This information, combined with the missile's own motion data, generates guidance commands that continuously reduce the missile's deviation from the aiming line and decrease the deviation between the missile's flight velocity direction and the aiming line direction.
[0045] In this embodiment of the application, when simulating SACLOS guidance in a game, the dynamic system response process can be ignored, that is, the kinetic system response process can be ignored. Figure 2 The dynamic control system section abstracts the virtual object as a point mass and calculates the linear acceleration required for the virtual object to approach the target according to guidance principles, thus efficiently applying missile guidance in the game. A detailed explanation follows.
[0046] In this embodiment, a virtual object control method is provided, such as... Figure 3 As shown, the specific process of this virtual object control method may include S110 to S160.
[0047] S110: Obtain the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object.
[0048] A line of sight is a ray used to aim at a target. For example, in a virtual environment, virtual items can be provided so that players can use them in competitions. Virtual items often come with a scope, and since the scope can aim at a target, the ray pointing from the center of the scope's field of view to that target is the line of sight.
[0049] The aiming starting point refers to the starting point of the aiming line, such as the position of the sight in the virtual scene. The aiming direction refers to the direction of the aiming line. Since the aiming line is a ray, the aiming direction is the direction from the aiming starting point to the aiming ending point, where the aiming ending point is the end point of the aiming line, i.e., the position of the target being aimed at.
[0050] A virtual object is an object to be launched. This virtual object can be a virtual missile, a virtual bullet, a virtual grappling hook, etc., and can be set according to actual needs. The displacement and velocity of a virtual object refer to the current displacement and velocity of the virtual object in the virtual scene.
[0051] It should be noted that a spatial coordinate system can be established in the virtual scene. The aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object, are all represented based on this spatial coordinate system. For example, the aiming starting point can be represented by coordinate information, the aiming line can be represented by a ray, and its direction is the aiming direction. The displacement and velocity of the virtual object are both vectors, that is, they have corresponding magnitude and direction, and can be represented in a vector manner.
[0052] In some implementations, the information corresponding to the aiming line and the relevant information of the virtual object can be obtained based on the player's actions. For example, the virtual scene can provide a function to launch virtual objects, which can appear in various forms, such as a skill of a virtual character or a virtual item.
[0053] The following explanation uses the function of launching virtual objects from a virtual prop as an example. For instance, in response to an aiming operation on the virtual prop, the target position of the virtual prop is determined. A ray pointing from the virtual prop's position to the target position is used as the aiming line, with the virtual prop's position as the aiming start point and the target position as the aiming end point. Then, in response to a launching operation on the virtual prop, the virtual object is launched towards the aiming end point. After being launched, the virtual object moves within the virtual scene, allowing the acquisition of its displacement and velocity.
[0054] S120. Calculate the deviation vector between the virtual object and the aiming starting point based on the displacement of the aiming starting point and the virtual object.
[0055] The deviation vector refers to the deviation of the virtual object's current position relative to the aiming starting point. Based on a pre-created spatial coordinate system, the displacement of the aiming starting point and the virtual object can be represented. For example, see [link to relevant documentation]. Figure 4 This diagram illustrates the calculation of the deviation vector. Point O is the origin of the spatial coordinate system, point A is the aiming starting point, point B is the current position of the virtual object, and the vector... The displacement of the virtual object, i.e., the directed line segment from point O to point B in the diagram, can be obtained by subtracting the coordinates of point O from the coordinates of point B. The displacement of the aiming starting point, i.e., the vector, can be obtained from the aiming starting point. The directed line segment from point O to point A can be obtained by subtracting the coordinates of the origin O from the coordinates of point A. The deviation vector, on the other hand, is the directed line segment from point A to point B.
[0056] In some implementations, the displacement of the aiming starting point can be used as a reference. and displacement of virtual objects According to vector operations, the deviation vector can be calculated using the following formula:
[0057]
[0058] In some implementations, the deviation vector can be obtained by subtracting the coordinates of the aiming starting point A from the coordinates of the virtual object's position B.
[0059] S130. Based on the deviation vector, the velocity is decomposed into multiple velocity components in specified directions.
[0060] After calculating the deviation vector, the velocity of the virtual object can be decomposed into velocity components in multiple specified directions using the deviation vector. These specified directions can be pre-set directions or directions corresponding to the velocity components obtained according to a specific velocity decomposition method.
[0061] In some implementations, the decomposition method of velocity can be determined based on the deviation vector. For example, the deviation vector can be decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction. If the first deviation component satisfies a preset condition, the velocity is decomposed into a first velocity component, a second velocity component, and a tangential velocity component along the aiming direction, wherein the first velocity component, the second velocity component, and the tangential velocity component are mutually perpendicular. If the first deviation component does not satisfy the preset condition, the velocity is decomposed into a first velocity component perpendicular to the aiming direction and a tangential velocity component along the aiming direction, and the second velocity component is set to a specified value.
[0062] One approach is to decompose the deviation vector, specifically into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction. For example, see [reference needed]. Figure 5 This diagram illustrates the decomposition of the deviation vector. The deviation vector is denoted as... Let the first deviation component be denoted as Let the second deviation component be denoted as It indicates the aiming line and aiming direction. This means that the deviation vector Split into along the aiming direction and perpendicular to the aiming direction Two vectors, the first deviation component Second deviation component from Figure 5 As can be seen from this, the magnitude of the first deviation component can indicate the displacement of the virtual object's current position relative to the aiming line.
[0063] Depending on the magnitude of the first deviation component, the speed can be split in different ways. For example, it can be determined whether the first deviation component meets a preset condition. As one implementation, it can be determined whether the magnitude of the first deviation component is greater than or equal to a preset value. If the magnitude of the first deviation component is greater than or equal to the preset value, it can be determined that the first deviation component meets the preset condition; if the magnitude of the first deviation component is less than the preset value, it can be determined that the first deviation component does not meet the preset condition.
[0064] The preset value can be a pre-set value, an empirical value, or a value obtained through continuous experimentation. It can be set according to actual needs, and no specific limitation is made here.
[0065] If the magnitude of the first deviation component is greater than or equal to the preset value, the distance between the virtual object and the aiming line is large, and the velocity can be divided into three velocity components in specified directions: the tangential velocity component along the aiming direction, the first velocity component along the first deviation component, and the second velocity component.
[0066] In some implementations, when decomposing the velocity into three velocity components in a specified direction, the velocity may be decomposed into a first velocity component along the first deviation component and an intermediate velocity component perpendicular to the first deviation component; the intermediate velocity component may be decomposed into a tangential velocity component along the aiming direction and a second velocity component perpendicular to the aiming direction.
[0067] For example, see Figure 6 This illustrates a schematic diagram of velocity decomposition. First, the velocity... Decomposed into components along the first deviation. First velocity component and the component perpendicular to the first deviation intermediate velocity component This process can be written as
[0068] Then, the intermediate velocity component Decomposed into along the aiming direction tangential velocity component and perpendicular to the aiming direction Second velocity component This process can be written as
[0069] If the magnitude of the first deviation component is less than a preset value, the distance between the virtual object and the aiming line is very small. To avoid large errors during velocity decomposition, the first deviation component can be directly ignored. At this point, the velocity can be directly decomposed into a first velocity component along the first deviation component and a tangential velocity component along the aiming direction. For example, see [reference needed]. Figure 7 This illustrates another schematic diagram of velocity decomposition, directly decomposing the velocity... Decomposed into along the aiming direction tangential velocity component and the first velocity component perpendicular to the aiming direction Then the second velocity component can be... Set to a specified value, that is, set the second velocity component to 0.
[0070] In some implementations, before decomposing the deviation vector, it can be determined whether the decomposition conditions are met. For example, a first angle between the deviation vector and the aiming direction can be calculated; a second angle between the velocity and the aiming direction can be calculated; if the first angle is less than or equal to a first preset angle and the second angle is less than or equal to a second preset angle, the deviation vector can be decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction.
[0071] The first angle refers to the angle between the deviation vector and the aiming direction. Velocity is a vector with magnitude and direction. The second angle refers to the angle between the velocity direction and the aiming direction.
[0072] The first preset angle refers to the maximum angle between the deviation vector and the aiming direction when the deviation vector is decomposed. The first preset angle can be set according to the actual application scenario or guidance principle. For example, in the embodiments of this application, the first preset angle can be set to 90 degrees according to the SACLOS guidance principle.
[0073] The second preset angle refers to the maximum angle between the velocity direction and the aiming direction when the deviation vector is decomposed. The second preset angle can be set according to the actual application scenario or guidance principle. For example, in the embodiments of this application, the second preset angle can be set to 90 degrees according to the SACLOS guidance principle.
[0074] As one implementation method, the first angle can be calculated by calculating the dot product between the deviation vector and the aiming direction; if the dot product is less than 0, it indicates that the first angle is greater than 90 degrees; if the dot product is greater than 0, it indicates that the first angle is less than 90 degrees. It can be understood that the dot product of the deviation vector and the aiming direction can be represented by the following formula:
[0075]
[0076] in, The magnitude of the deviation vector is represented. The modulus indicating the aiming direction. This represents the first angle. Therefore, we know that if the dot product between the deviation vector and the aiming direction... If the cosine of the first angle is less than 0, then the first angle is greater than 90 degrees. Based on the SACLOS guidance principle, the aiming device cannot observe the virtual object at this time, and therefore cannot control the virtual object, so the process can be terminated directly. If the first angle is less than 90 degrees, the aiming device can observe the virtual object, and subsequent deviation vector decomposition can be performed.
[0077] Similarly, when calculating the second angle, the dot product between the velocity and the aiming direction can be used. If the dot product is less than 0, it means the second angle is greater than 90 degrees. Based on the SACLOS guidance principle, the virtual object cannot be observed at this time, so it cannot be controlled and the process can be terminated directly. If the dot product is greater than 0, it means the second angle is less than 90 degrees, the virtual object can be observed, and the subsequent deflection vector can be split.
[0078] S140. For each specified direction, calculate the acceleration in the specified direction based on the velocity component in the specified direction.
[0079] In order to control the virtual object to move along the aiming line to the aiming endpoint, it is necessary to reduce the first deviation component, and when the first deviation component approaches 0, the second angle between the control speed and the aiming direction approaches 0. At the same time, it is also necessary to ensure that the speed value of the virtual object approaches the desired speed value as much as possible.
[0080] According to the velocity decomposition method described above, velocity is divided into velocity components in three specified directions: a first velocity component along the first deviation component, a tangential velocity component along the aiming direction, and a second velocity component. Clearly, in order to control the virtual object to move along the aiming direction, the acceleration that needs to be applied in each specified direction can be calculated.
[0081] For example, one could obtain the damping coefficient and the first proportional coefficient on the first velocity component, the second proportional coefficient on the second velocity component, and the tangential proportional coefficient on the tangential velocity component; determine the first acceleration under a first preset expected value based on the product of the damping coefficient and the first velocity component, and the product of the first proportional coefficient and the second deviation component; determine the second acceleration under a second preset expected value based on the second proportional coefficient and the second velocity component; and determine the tangential acceleration under the expected velocity value based on the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential proportional coefficient.
[0082] A first velocity component exists in the direction of the first deviation component. In this specified direction, it is necessary to control the first deviation component to approach 0, and the first velocity component to approach 0. Therefore, a corresponding controller can be set in the direction indicated by the first deviation component to calculate the first acceleration.
[0083] The damping coefficient on the first velocity component refers to the damping coefficient in the direction of the first velocity component, while the first proportional coefficient refers to the proportional coefficient of the controller set in the direction of the first velocity component.
[0084] Specifically, the first acceleration at a first preset expected value can be determined by multiplying the damping coefficient and the first velocity component, and by multiplying the first proportional coefficient and the second deviation component. Here, the first preset expected value refers to the first deviation component approaching 0, and the first velocity component approaching 0.
[0085] To control the first deviation component to approach 0, the first deviation component can be used as the input of the first controller in that direction, and 0 can be used as the output of the first controller. The control force output by the first controller can then be expressed as: Let represent the first proportionality coefficient. To control the first velocity component to approach zero, the applied damping force can be expressed as: Therefore, in the direction of the first velocity component, the required control force is: If the mass of the virtual object is set to 1, the first acceleration can be calculated using the following formula:
[0086]
[0087] in, Indicates the first acceleration; Indicates the damping coefficient; Indicates the first velocity component; Indicates the first proportionality coefficient; This represents the first deviation component.
[0088] To ensure that the first velocity value corresponding to the first velocity component does not approach infinity, when the first velocity value is greater than the magnitude of the cutoff velocity in the direction of the first velocity component... When the direction of the first acceleration is consistent with the direction of the first velocity component, the first acceleration is set to 0. The cutoff velocity in the direction of the first velocity component can be calculated using the following formula:
[0089]
[0090] in, It represents the magnitude of the cutoff velocity in the direction of the first velocity component; This indicates the velocity cutoff ratio in the direction of the first velocity component. This represents the expected speed value of the virtual object.
[0091] In the direction of the second velocity component, if the control objective is to make the second velocity component approach 0, then the second preset expected value is 0. Similarly, a second controller can be set in the direction of the second velocity component, and the second acceleration can be calculated according to the following formula:
[0092]
[0093] in, Indicates the second acceleration; Indicates the second velocity component; This represents the second proportionality coefficient.
[0094] For the tangential velocity component in the aiming direction, it is necessary to control the tangential velocity value corresponding to the tangential velocity component to approach the desired velocity value. The tangential acceleration at the desired velocity value can be calculated using the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential scaling factor.
[0095] As one implementation method, when calculating tangential acceleration, the desired tangential velocity value can be calculated using the desired velocity value, the first velocity value, and the second velocity value; the larger of the desired tangential velocity value and the minimum tangential velocity value of the virtual object can be determined as the target desired tangential velocity value; the tangential unit vector on the tangential velocity component can be calculated; and the tangential acceleration can be calculated using the tangential unit vector, the tangential scaling factor, the target desired tangential velocity value, and the tangential velocity value corresponding to the tangential velocity component.
[0096] To control the velocity of a virtual object to reach a desired velocity value, the corresponding tangential velocity value at the desired velocity value can be calculated. As shown in the aforementioned velocity decomposition, the first velocity component, the second velocity component, and the tangential velocity component are mutually perpendicular, and the sum of the first velocity component, the second velocity component, and the tangential velocity component equals the velocity. That is, the multiple velocity components and the velocity satisfy the following relationship:
[0097]
[0098] in, Indicates the speed of the virtual object; Indicates the tangential velocity component; Indicates the first velocity component; This represents the second velocity component.
[0099] The velocity values corresponding to multiple velocity components and the velocity values of the virtual object have the following relationship:
[0100]
[0101] in, This represents the speed value of the virtual object; Indicates the tangential velocity value; This indicates the first speed value; This indicates the second speed value.
[0102] When the speed value of the virtual object is the desired speed value When the desired tangential velocity is obtained, it can be expressed by the following formula:
[0103]
[0104] To prevent the tangential velocity of a virtual object from being less than the minimum tangential velocity, the larger of the desired tangential velocity and the minimum tangential velocity can be determined as the target desired tangential velocity.
[0105] The minimum tangential velocity of the virtual object can be calculated using the following formula:
[0106]
[0107] in, This represents the minimum tangential velocity value; This indicates the velocity cutoff ratio on the first deviation component; This represents the desired speed value.
[0108] A tangential controller with a tangential proportional coefficient can be set in the aiming direction. To control the tangential velocity value to approach the desired tangential velocity value of the target, the tangential acceleration can be calculated according to the following formula:
[0109]
[0110] in, Indicates tangential acceleration; This represents the target's desired tangential velocity value; Indicates the tangential velocity value; Indicates the tangential scaling factor; This represents the unit vector in the direction of the tangential velocity component, i.e., the tangential unit vector.
[0111] It should be noted that when the first deviation component does not meet the preset conditions, the second velocity component is directly set to 0, and the corresponding second acceleration is also 0. By setting corresponding controllers in each specified direction, the corresponding acceleration is calculated. The calculation process is relatively simple, resulting in low memory and CPU consumption during controller calculation, making it safe to integrate into the game.
[0112] S150. Merge all accelerations in the specified directions to obtain the target acceleration of the virtual object.
[0113] The aforementioned acceleration can be calculated in each specified direction. Based on the acceleration in all specified directions, the target acceleration of the virtual object can be calculated. For example, the desired acceleration can be obtained by summing the first acceleration, the second acceleration, and the tangential acceleration; the unit vector of the desired acceleration can be calculated to obtain the desired unit vector; and the target acceleration can be calculated based on the desired acceleration value, the desired unit vector, and the maximum acceleration value of the virtual object.
[0114] The desired acceleration can be calculated using the following formula:
[0115]
[0116] in, Indicates the desired acceleration; Indicates the first acceleration; Indicates the second acceleration; This indicates tangential acceleration.
[0117] Then, the unit vector of the desired acceleration can be calculated to obtain the desired unit vector, which is the unit vector in the direction of the desired acceleration. Then, based on the desired acceleration value, the desired unit vector, and the maximum acceleration value of the virtual object, the target acceleration is calculated. In some implementations, to avoid overload, when calculating the target acceleration, the smaller of the maximum acceleration value and the desired acceleration value can be determined as the target desired acceleration value; the product of the target desired acceleration value and the desired unit vector is calculated to obtain the target acceleration.
[0118] To ensure that the acceleration of the virtual object does not exceed the maximum acceleration value, the smaller of the maximum acceleration value and the desired acceleration value can be determined as the target desired acceleration value. The target acceleration can then be calculated using the following formula:
[0119]
[0120] in, Indicates the target acceleration. This represents the desired acceleration value; Indicates the desired acceleration; a represents the expected unit vector; max This indicates the maximum acceleration value; This represents the target expected acceleration value.
[0121] S160. Based on the target acceleration, control the virtual object to move along the aiming direction.
[0122] The target acceleration is applied to the virtual object. The displacement of the virtual object off the aiming line (the first deviation component) and the velocity component off the aiming direction (the first velocity component and the second velocity component) are gradually reduced by the first and second controllers, ultimately achieving... At the same time, under the control of the tangential controller, it can also make This allows you to control the virtual object to move along the aiming direction at the desired speed.
[0123] In some implementations, it is necessary to display the process of a virtual object moving from launch to the aiming endpoint. In the game, the time interval between frames is a preset time interval. Steps S110 to S150 described above can be executed once in each frame to obtain the target acceleration to be applied in the current frame. Then, the displacement and velocity of the virtual object in the next frame are calculated using the target acceleration, thereby controlling the virtual object to reach the aiming endpoint along the aiming direction. Specifically, this process may involve calculating a specified displacement of the virtual object within the preset time interval based on the target acceleration and the velocity; calculating the velocity increment of the virtual object within the preset time interval based on the target acceleration; updating the displacement using the specified displacement; and updating the velocity using the velocity increment, thereby controlling the virtual object to reach the aiming endpoint along the aiming direction.
[0124] Based on the velocity obtained in the current frame and the calculated target acceleration, the specified displacement of the virtual object within a preset time interval can be calculated. For example, using... This represents the target acceleration calculated in the current frame, i.e., the Nth frame. Let Δt represent the velocity of the virtual object acquired in the Nth frame, and let Δt represent the preset time interval. Then, the specified displacement can be expressed as: Based on the velocity and target acceleration obtained in the current frame, the velocity increment of the virtual object within a preset time interval can also be calculated. For example, in the previous example, the velocity increment can be expressed as...
[0125] Then, by updating the obtained displacement using a specified displacement, the displacement of the virtual object in frame N+1 can be obtained. Similarly, by updating the obtained velocity using the velocity increment, the velocity of the virtual object in frame N+1 can be obtained. See the following formula for details:
[0126]
[0127]
[0128] in, This represents the displacement of the virtual object in the Nth frame; This represents the displacement of the virtual object in the (N+1)th frame; This indicates the speed of the virtual object in the Nth frame; This represents the speed of the (N+1)th virtual object.
[0129] This allows us to calculate the displacement and velocity of the virtual object in each frame sequentially, and control the virtual object to move along the aiming direction to the aiming endpoint.
[0130] It should be noted that the aiming line can change during the movement of the virtual object. Since the target acceleration is calculated every preset time interval, even if the aiming line changes, the virtual object can be controlled to always move along the latest aiming line, thereby reaching the aiming endpoint corresponding to the latest aiming line.
[0131] The virtual object control scheme provided in this application can be applied to various scenarios simulating guidance principles in games. For example, taking the control of a missile in a game as an example, the scheme provided in this application can realistically simulate the missile guidance principle in the game. In the game, the missile can quickly approach the aiming direction, and the player can continuously adjust the aiming direction to dynamically guide the virtual missile to track the moving target. The calculation is simple and efficient, thus enabling efficient and realistic simulation of missile guidance in the game.
[0132] The method provided in this application embodiment can obtain the aiming direction and aiming starting point of the aiming line, the displacement and velocity of the virtual object, and calculate the offset vector using the aiming starting point and the displacement of the virtual object. Based on the offset vector, the velocity is decomposed into multiple specified directions to obtain multiple mutually perpendicular velocity components. Then, the acceleration in the specified directions is calculated, and finally, the accelerations in multiple specified directions are fused to obtain the target acceleration. The target acceleration is then used to control the virtual object to move along the aiming direction. Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified, and the amount of calculation in the control is reduced. Thus, missile guidance can be efficiently applied in games to achieve control of virtual objects.
[0133] The method described in the above embodiments will be further described in detail below.
[0134] In this embodiment, the method of this application embodiment will be described in detail using a virtual missile as the virtual object and SACLOS guidance as the missile guidance as an example.
[0135] like Figure 8 As shown, the specific process of a virtual object control method is as follows:
[0136] S210, in response to a triggering operation on a virtual missile, acquires the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object.
[0137] The device can run game-related applications, which players can launch to play. In the game, players can use virtual items to launch virtual missiles. Triggering actions include aiming and launching. When an aiming action is detected for a virtual item, the aiming starting point and aiming direction of the aiming line can be obtained; when a launching action is detected for a virtual item, the virtual missile can be launched, and its displacement and speed can be obtained.
[0138] S220. Calculate the deviation vector between the virtual missile and the aiming starting point based on the displacement of the aiming starting point and the virtual missile.
[0139] The displacement of the aiming starting point can be calculated using the aiming starting point. If the displacement of the virtual missile is denoted as Then the deviation vector
[0140] S230. If the first angle between the deviation vector and the aiming direction is less than or equal to the first preset angle, and the second angle between the velocity and the aiming direction is less than or equal to the second preset angle, the deviation vector is decomposed.
[0141] To determine whether a virtual missile meets the guidance conditions of the SACLOS guidance system, the first preset angle refers to the maximum angle between the aiming direction and the deviation vector when the guidance system is operating; this can be set to 90 degrees. The second angle refers to the maximum angle between the velocity direction and the aiming direction when the guidance system is operating; this can also be set to 90 degrees. Specifically, this can be achieved by calculating the dot product between the aiming direction and the deviation vector. If the dot product is less than 0, it indicates that the first angle is greater than 90 degrees, the sight cannot observe the missile, and the guidance system is not operating. Similarly, calculating the dot product between the aiming direction and the velocity indicates that the second angle is greater than 90 degrees, the missile's exhaust plume cannot be observed, and the guidance system is not operating.
[0142] Therefore, the guidance system operates only when the first angle is less than or equal to the first preset angle and the second angle is less than or equal to the second preset angle, and can decompose the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction.
[0143] S240. If the first deviation component meets the preset conditions, the velocity is decomposed into a first velocity component, a second velocity component, and a tangential velocity component.
[0144] The length of the first deviation component can indicate the distance by which the virtual missile deviates from the aiming line. When the length of the first deviation component is greater than a preset value, it can be considered that the virtual missile has deviated from the aiming line by a greater distance. The velocity can be divided into three velocity components in three specified directions: the first velocity component along the first deviation component, the tangential velocity component along the aiming direction, and the second velocity component.
[0145] S250. If the first deviation component does not meet the preset condition, the velocity is decomposed into a first velocity component and a tangential velocity component, and the second velocity component is set to a specified value.
[0146] If the length of the first deviation component is less than the preset value, it can be considered that the distance of the virtual missile deviating from the aiming line is relatively short and can be ignored. Thus, the velocity can be directly split into the first velocity component along the first deviation component and the tangential velocity component along the aiming direction, and the second velocity component can be directly set to the specified value.
[0147] S260. For each specified direction, calculate the acceleration in the specified direction based on the velocity component in the specified direction.
[0148] In order to control the virtual missile to move along the aiming direction, the first deviation component and the first velocity component need to be gradually reduced in the direction of the first velocity component, so that the first controller can be designed to calculate the corresponding first acceleration.
[0149] In the direction of the second velocity component, the second velocity component also needs to be gradually reduced so that a second controller can be designed to calculate the corresponding second acceleration.
[0150] In the direction of the tangential velocity component, i.e., the aiming direction, it is necessary to control the tangential velocity component to approach the desired velocity, and to prevent it from deviating too much from the desired velocity. This allows for the design of a tangential controller to calculate the corresponding tangential acceleration.
[0151] S270: By integrating accelerations in all specified directions, the target acceleration of the virtual missile is obtained.
[0152] The first acceleration, the second acceleration, and the tangential acceleration are then fused together to calculate the desired acceleration. To avoid overload, the target acceleration value also needs to be controlled to be less than the maximum acceleration value, so the smaller of the desired acceleration value and the maximum acceleration value is taken as the target acceleration.
[0153] S280. Based on the target acceleration, control the virtual missile to move along the aiming direction.
[0154] After calculating the target acceleration, a virtual missile can be launched based on the target acceleration. Since the interval between frames in the game is a preset time interval, usually 0.033 seconds, the displacement and velocity of the virtual missile will be calculated for each frame.
[0155] Specifically, after calculating the target acceleration corresponding to the current frame, the displacement and velocity obtained in the current frame can be updated based on the target acceleration and a preset time interval. This allows the displacement and velocity of the virtual missile in the next frame to be obtained, so as to continue calculating the target acceleration in the next frame. This enables the virtual missile to be controlled to move along the aiming line to hit the target.
[0156] The content of this embodiment and the previous embodiments can be referred to each other. The following is a specific example for illustration.
[0157] Establish a spatial coordinate system with the Z-axis pointing vertically upwards, and set the initial position of the virtual missile. Initial velocity of the virtual missile The virtual missile is positioned 10m directly above the origin of the spatial coordinate system, flying obliquely upwards with an initial velocity of approximately 100m / s at an angle of 45° to the Y-axis. The aiming starting point is set. The displacement remains constant The initial aiming direction is After step 1, the aiming line direction was changed. The preset time interval Δt = 0.0330.
[0158] Set the virtual missile controller parameters as follows: desired velocity magnitude The maximum acceleration of the virtual missile, a max =400m / s 2 directional velocity cutoff ratio of the first deviation component Default value Tangential scaling factor Damping coefficient in the direction of the first deviation component First proportional coefficient Second proportionality coefficient
[0159] Through in-game simulation and data collection, the missile trajectory can be obtained, for example, see [reference needed]. Figure 9 The diagram illustrates the trajectory of a virtual missile. Since the virtual missile initially has an upward vertical velocity component, and its initial aiming direction is within 0-1 seconds... Therefore, under the action of the guidance controller, the vertical upward velocity component of the virtual missile gradually decreases to 0 (the initial peak in the figure), and then the trajectory approaches the aiming line and eventually coincides with the aiming line.
[0160] After 1 second, the aiming line direction is changed to the new aiming direction. Under the control of the guidance system, the trajectory of the virtual missile changed again, and it began to approach the new aiming direction. Eventually, the flight trajectory of the virtual missile coincided with the new aiming direction.
[0161] As can be seen from the above, the embodiments of this application can obtain the aiming direction and aiming starting point of the aiming line, the displacement and velocity of the virtual missile, and calculate the offset vector using the aiming starting point and the displacement of the virtual missile; decompose the velocity into multiple specified directions according to the offset vector to obtain multiple mutually perpendicular velocity components; then calculate the acceleration in the specified directions, and finally fuse the acceleration in multiple specified directions to obtain the target acceleration; then use the target acceleration to control the virtual object to move along the aiming direction. Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified, the amount of calculation in the control is reduced, and thus missile guidance can be efficiently applied in games, so that the virtual missile in the game can move according to the guidance principle, improving the realism of the virtual missile in military games.
[0162] To better implement the above methods, this application also provides a virtual object control device, which 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 composed of multiple servers.
[0163] For example, in this embodiment, the method of this application embodiment will be described in detail by taking the virtual object control device specifically integrated into the server as an example.
[0164] For example, such as Figure 10 As shown, the virtual object control device 300 may include an acquisition module 310, a deviation calculation module 320, a velocity decomposition module 330, an acceleration calculation module 340, a fusion module 350, and a control module 360.
[0165] The acquisition module 310 is used to acquire the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object;
[0166] The deviation calculation module 320 is used to calculate the deviation vector between the virtual object and the aiming starting point based on the displacement of the aiming starting point and the virtual object;
[0167] The velocity decomposition module 330 is used to decompose the velocity into multiple velocity components in specified directions according to the deviation vector, wherein the multiple velocity components are perpendicular to each other, and the multiple specified directions include the aiming direction;
[0168] The acceleration calculation module 340 is used to calculate the acceleration in the specified direction for each specified direction based on the velocity component in the specified direction;
[0169] The fusion module 350 is used to fuse all accelerations in the specified directions to obtain the target acceleration of the virtual object;
[0170] The control module 360 is used to control the virtual object to move along the aiming direction based on the target acceleration.
[0171] In some embodiments, the velocity decomposition module 330 further includes:
[0172] A deviation decomposition unit is used to decompose the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction;
[0173] The first decomposition unit is used to decompose the velocity into a first velocity component, a second velocity component, and a tangential velocity component along the aiming direction if the first deviation component meets a preset condition. The first velocity component, the second velocity component, and the tangential velocity component are perpendicular to each other.
[0174] The second decomposition unit is used to decompose the velocity into a first velocity component perpendicular to the aiming direction and a tangential velocity component along the aiming direction if the first deviation component does not meet the preset condition, and to set the second velocity component to a specified value.
[0175] In some embodiments, the first decomposition unit is further configured to:
[0176] The velocity is decomposed into a first velocity component along the first deviation component and an intermediate velocity component perpendicular to the first deviation component;
[0177] The intermediate velocity component is decomposed into a tangential velocity component along the aiming direction and a second velocity component perpendicular to the aiming direction.
[0178] In some embodiments, the virtual object control device 300 further includes a condition determination module, which, before decomposing the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction, is configured to:
[0179] Calculate the first angle between the deviation vector and the aiming direction;
[0180] Calculate the second angle between the velocity and the aiming direction;
[0181] If the first angle is less than or equal to the first preset angle, and the second angle is less than or equal to the second preset angle, the deviation vector is decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction.
[0182] In some embodiments, the acceleration calculation module 340 further includes:
[0183] The acquisition unit is used to acquire the damping coefficient and the first proportional coefficient on the first velocity component, the second proportional coefficient on the second velocity component, and the tangential proportional coefficient on the tangential velocity component.
[0184] The first calculation unit is used to determine the first acceleration under the first preset expected value based on the product of the damping coefficient and the first velocity component, and the product of the first proportional coefficient and the second deviation component.
[0185] The second calculation unit is used to determine the second acceleration under the second preset expected value based on the second proportional coefficient and the second velocity component;
[0186] The tangential calculation unit is used to determine the tangential acceleration at the desired velocity value based on the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential scaling factor.
[0187] In some embodiments, the tangential calculation unit is further configured to:
[0188] The desired tangential velocity value is calculated using the desired velocity value, the first velocity value, and the second velocity value;
[0189] The larger of the desired tangential velocity value and the minimum tangential velocity value of the virtual object is determined as the target desired tangential velocity value;
[0190] Calculate the tangential unit vector on the tangential velocity component;
[0191] The tangential acceleration is calculated using the tangential unit vector, the tangential scaling factor, the target desired tangential velocity value, and the tangential velocity values corresponding to the tangential velocity components.
[0192] In some embodiments, the fusion module 350 further includes:
[0193] The summation unit is used to sum the first acceleration, the second acceleration, and the tangential acceleration to obtain the desired acceleration.
[0194] A unit calculation unit is used to calculate the unit vector of the desired acceleration to obtain the desired unit vector;
[0195] The target calculation unit is used to calculate the target acceleration based on the expected acceleration value corresponding to the expected acceleration, the expected unit vector, and the maximum acceleration value of the virtual object.
[0196] In some embodiments, the target computing unit is further configured to:
[0197] The smaller of the maximum acceleration value and the desired acceleration value is determined as the target desired acceleration value;
[0198] The target acceleration is obtained by multiplying the target expected acceleration value and the expected unit vector.
[0199] In some embodiments, the control module 360 further includes:
[0200] The displacement calculation unit is used to calculate the specified displacement of the virtual object within a preset time interval based on the target acceleration and the velocity;
[0201] A velocity calculation unit is used to calculate the velocity increment of the virtual object within the preset time interval based on the target acceleration.
[0202] An update control unit is used to update the displacement using the specified displacement and to update the velocity using the velocity increment, so as to control the virtual object to reach the aiming endpoint along the aiming direction.
[0203] In practice, each of the above modules or 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 modules or units, please refer to the previous method embodiments, which will not be repeated here.
[0204] As can be seen from the above, the virtual object control device of this embodiment can obtain the aiming direction and aiming starting point of the aiming line, the displacement and velocity of the virtual object, and calculate the offset vector using the aiming starting point and the displacement of the virtual object; decompose the velocity into multiple specified directions according to the offset vector to obtain multiple mutually perpendicular velocity components; then calculate the acceleration in the specified directions, and finally fuse the acceleration in multiple specified directions to obtain the target acceleration; then use the target acceleration to control the virtual object to move along the aiming direction. Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified and the amount of calculation in the control is reduced, so that missile guidance can be efficiently applied in games to achieve control of virtual objects.
[0205] 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.
[0206] like Figure 11 As shown, Figure 11This 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 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, and a computer program stored in the memory 402 and executable on the processor. The processor 401 and the memory 402 are electrically connected. 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.
[0207] The processor 401 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 402, and calling data stored in the memory 402, it performs various functions of the electronic device 400 and processes data, thereby monitoring the electronic device 400 as a whole.
[0208] In this embodiment, the processor 401 in the electronic device 400 loads the instructions corresponding to the processes of one or more applications into the memory 402 according to the following steps, and the processor 401 runs the applications stored in the memory 402 to realize various functions:
[0209] The aiming direction and aiming starting point of the aiming line are obtained, as well as the displacement and velocity of the virtual object; based on the aiming starting point and the displacement of the virtual object, a deviation vector is calculated between the virtual object and the aiming starting point; based on the deviation vector, the velocity is decomposed into velocity components in multiple specified directions, wherein each of the multiple velocity components is perpendicular to the others, and the multiple specified directions include the aiming direction; for each specified direction, the acceleration in the specified direction is calculated based on the velocity components in the specified direction; the accelerations in all specified directions are fused to obtain the target acceleration of the virtual object; based on the target acceleration, the virtual object is controlled to move along the aiming direction.
[0210] Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified and the amount of computation in control is reduced, so that missile guidance can be efficiently applied in games to achieve control of virtual objects.
[0211] The deviation vector is decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction. If the first deviation component satisfies a preset condition, the velocity is decomposed into a first velocity component, a second velocity component, and a tangential velocity component along the aiming direction, wherein the first velocity component, the second velocity component, and the tangential velocity component are mutually perpendicular to each other. If the first deviation component does not satisfy the preset condition, the velocity is decomposed into a first velocity component perpendicular to the aiming direction and a tangential velocity component along the aiming direction, and the second velocity component is set to a specified value.
[0212] By breaking down the speed according to preset conditions in different ways, calculation errors can be effectively reduced and the accuracy of controlling virtual objects can be improved.
[0213] The velocity is decomposed into a first velocity component along the first deviation component and an intermediate velocity component perpendicular to the first deviation component; the intermediate velocity component is decomposed into a tangential velocity component along the aiming direction and a second velocity component perpendicular to the aiming direction.
[0214] The velocity is decomposed into three specified directions in a specific manner, and the resulting velocity components are perpendicular to each other in pairs, so as to facilitate subsequent acceleration calculations.
[0215] Calculate a first angle between the deviation vector and the aiming direction; calculate a second angle between the velocity and the aiming direction; if the first angle is less than or equal to a first preset angle and the second angle is less than or equal to a second preset angle, decompose the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction.
[0216] Under certain conditions, the deviation vector and velocity are decomposed to improve the accuracy of control over the virtual object.
[0217] Obtain the damping coefficient and first proportional coefficient on the first velocity component, the second proportional coefficient on the second velocity component, and the tangential proportional coefficient on the tangential velocity component; determine the first acceleration under a first preset expected value based on the product of the damping coefficient and the first velocity component, and the product of the first proportional coefficient and the second deviation component; determine the second acceleration under a second preset expected value based on the second proportional coefficient and the second velocity component; determine the tangential acceleration under the expected velocity value based on the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential proportional coefficient.
[0218] Using the desired velocity value, the first velocity value, and the second velocity value, calculate the desired tangential velocity value; determine the larger of the desired tangential velocity value and the minimum tangential velocity value of the virtual object as the target desired tangential velocity value; calculate the tangential unit vector on the tangential velocity component;
[0219] The tangential acceleration is calculated using the tangential unit vector, the tangential scaling factor, the target desired tangential velocity value, and the tangential velocity values corresponding to the tangential velocity components.
[0220] Different control targets exist in different specified directions, allowing acceleration in a specified direction to be calculated based on the control targets in each direction, thus achieving more precise control.
[0221] Summing the first acceleration, the second acceleration, and the tangential acceleration yields the desired acceleration; calculating the unit vector of the desired acceleration yields the desired unit vector; and calculating the target acceleration based on the desired acceleration value, the desired unit vector, and the maximum acceleration value of the virtual object.
[0222] The smaller of the maximum acceleration value and the desired acceleration value is determined as the target desired acceleration value; the product of the target desired acceleration value and the desired unit vector is calculated to obtain the target acceleration.
[0223] When calculating the target acceleration, it is necessary to ensure that the target acceleration does not exceed the maximum acceleration to avoid overload and to more realistically simulate the guidance principle.
[0224] Based on the target acceleration and the velocity, calculate the specified displacement of the virtual object within a preset time interval; based on the target acceleration, calculate the velocity increment of the virtual object within the preset time interval; update the displacement using the specified displacement, and update the velocity using the velocity increment, so as to control the virtual object to move along the aiming direction.
[0225] The target acceleration is calculated once at a preset time interval, and the displacement and velocity of the virtual object are updated using the target acceleration, thereby enabling the virtual object to move along the aiming direction and realizing a realistic simulation of the guidance principle.
[0226] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0227] Optional, such as Figure 11As shown, the electronic device 400 also includes: a touch display screen 403, a radio frequency circuit 404, an audio circuit 405, an input unit 406, and a power supply 407. The processor 401 is electrically connected to the touch display screen 403, the radio frequency circuit 404, the audio circuit 405, the input unit 406, and the power supply 407. Those skilled in the art will understand that... Figure 11 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.
[0228] The touch display screen 403 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 403 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 401. It can also receive and execute commands from the processor 401. 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 401 to determine the type of touch event. Subsequently, the processor 401 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 403 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 403 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 403 can also be used as part of the input unit 406 to achieve input functions.
[0229] In this embodiment, a game application is executed by processor 401 to generate a graphical user interface (GUI) on touch display screen 403. The virtual scene on the GUI includes virtual items and virtual characters. The touch display screen 403 is used to present the GUI and receive operation commands generated by the user interacting with it.
[0230] The radio frequency circuit 404 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.
[0231] Audio circuit 405 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuit 405 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 circuit 405, converted back into audio data, and then processed by processor 401 before being transmitted via radio frequency circuit 404 to, for example, another electronic device, or output to memory 402 for further processing. Audio circuit 405 may also include an earphone jack to provide communication between peripheral headphones and electronic devices.
[0232] The input unit 406 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.
[0233] Power supply 407 is used to supply power to various components of electronic device 400. Optionally, power supply 407 can be logically connected to processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 407 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.
[0234] although Figure 11 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.
[0235] 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.
[0236] As can be seen from the above, the electronic device provided in this embodiment can obtain the aiming direction and aiming starting point of the aiming line, the displacement and velocity of the virtual object, and calculate the offset vector using the aiming starting point and the displacement of the virtual object; decompose the velocity into multiple specified directions according to the offset vector to obtain multiple mutually perpendicular velocity components; then calculate the acceleration in the specified directions, and finally fuse the acceleration in multiple specified directions to obtain the target acceleration; then use the target acceleration to control the virtual object to move along the aiming direction. Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified and the amount of calculation in the control is reduced, so that missile guidance can be efficiently applied in games to achieve control of virtual objects.
[0237] 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.
[0238] 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 virtual object control methods provided in embodiments of this application. For example, the computer program can execute the following steps:
[0239] The aiming direction and aiming starting point of the aiming line are obtained, as well as the displacement and velocity of the virtual object; based on the aiming starting point and the displacement of the virtual object, a deviation vector is calculated between the virtual object and the aiming starting point; based on the deviation vector, the velocity is decomposed into velocity components in multiple specified directions, wherein each of the multiple velocity components is perpendicular to the others, and the multiple specified directions include the aiming direction; for each specified direction, the acceleration in the specified direction is calculated based on the velocity components in the specified direction; the accelerations in all specified directions are fused to obtain the target acceleration of the virtual object; based on the target acceleration, the virtual object is controlled to move along the aiming direction.
[0240] Based on simple velocity decomposition and acceleration calculation, the missile guidance control process is simplified and the amount of computation in control is reduced, so that missile guidance can be efficiently applied in games to achieve control of virtual objects.
[0241] The deviation vector is decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction. If the first deviation component satisfies a preset condition, the velocity is decomposed into a first velocity component, a second velocity component, and a tangential velocity component along the aiming direction, wherein the first velocity component, the second velocity component, and the tangential velocity component are mutually perpendicular to each other. If the first deviation component does not satisfy the preset condition, the velocity is decomposed into a first velocity component perpendicular to the aiming direction and a tangential velocity component along the aiming direction, and the second velocity component is set to a specified value.
[0242] By breaking down the speed according to preset conditions in different ways, calculation errors can be effectively reduced and the accuracy of controlling virtual objects can be improved.
[0243] The velocity is decomposed into a first velocity component along the first deviation component and an intermediate velocity component perpendicular to the first deviation component; the intermediate velocity component is decomposed into a tangential velocity component along the aiming direction and a second velocity component perpendicular to the aiming direction.
[0244] The velocity is decomposed into three specified directions in a specific manner, and the resulting velocity components are perpendicular to each other in pairs, so as to facilitate subsequent acceleration calculations.
[0245] Calculate a first angle between the deviation vector and the aiming direction; calculate a second angle between the velocity and the aiming direction; if the first angle is less than or equal to a first preset angle and the second angle is less than or equal to a second preset angle, decompose the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction.
[0246] Under certain conditions, the deviation vector and velocity are decomposed to improve the accuracy of control over the virtual object.
[0247] Obtain the damping coefficient and first proportional coefficient on the first velocity component, the second proportional coefficient on the second velocity component, and the tangential proportional coefficient on the tangential velocity component; determine the first acceleration under a first preset expected value based on the product of the damping coefficient and the first velocity component, and the product of the first proportional coefficient and the second deviation component; determine the second acceleration under a second preset expected value based on the second proportional coefficient and the second velocity component; determine the tangential acceleration under the expected velocity value based on the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential proportional coefficient.
[0248] Using the desired velocity value, the first velocity value, and the second velocity value, calculate the desired tangential velocity value; determine the larger of the desired tangential velocity value and the minimum tangential velocity value of the virtual object as the target desired tangential velocity value; calculate the tangential unit vector on the tangential velocity component;
[0249] The tangential acceleration is calculated using the tangential unit vector, the tangential scaling factor, the target desired tangential velocity value, and the tangential velocity values corresponding to the tangential velocity components.
[0250] Different control targets exist in different specified directions, allowing acceleration in a specified direction to be calculated based on the control targets in each direction, thus achieving more precise control.
[0251] Summing the first acceleration, the second acceleration, and the tangential acceleration yields the desired acceleration; calculating the unit vector of the desired acceleration yields the desired unit vector; and calculating the target acceleration based on the desired acceleration value, the desired unit vector, and the maximum acceleration value of the virtual object.
[0252] The smaller of the maximum acceleration value and the desired acceleration value is determined as the target desired acceleration value; the product of the target desired acceleration value and the desired unit vector is calculated to obtain the target acceleration.
[0253] When calculating the target acceleration, it is necessary to ensure that the target acceleration does not exceed the maximum acceleration to avoid overload and to more realistically simulate the guidance principle.
[0254] Based on the target acceleration and the velocity, calculate the specified displacement of the virtual object within a preset time interval; based on the target acceleration, calculate the velocity increment of the virtual object within the preset time interval; update the displacement using the specified displacement, and update the velocity using the velocity increment, so as to control the virtual object to move along the aiming direction.
[0255] The target acceleration is calculated once at a preset time interval, and the displacement and velocity of the virtual object are updated using the target acceleration, thereby enabling the virtual object to move along the aiming direction and realizing a realistic simulation of the guidance principle.
[0256] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0257] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0258] Since the computer program stored in the storage medium can execute the steps in any of the virtual object control methods provided in the embodiments of this application, the beneficial effects that any of the virtual object 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.
[0259] The foregoing has provided a detailed description of a virtual object control method, apparatus, 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 virtual objects, characterized in that, The method includes: Obtain the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object; Calculate the deviation vector between the virtual object and the aiming starting point based on the displacement of the aiming starting point and the virtual object; Based on the deviation vector, the velocity is decomposed into velocity components in multiple specified directions, wherein each of the multiple velocity components is perpendicular to the others, and the multiple specified directions include the aiming direction; For each specified direction, the acceleration in the specified direction is calculated based on the velocity component in the specified direction; By aggregating the accelerations in all the specified directions, the target acceleration of the virtual object is obtained; Based on the target acceleration, control the virtual object to move along the aiming direction; The step of decomposing the velocity into multiple velocity components in specified directions based on the deviation vector includes: The deviation vector is decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction; If the first deviation component meets the preset conditions, the velocity is decomposed into a first velocity component, a second velocity component, and a tangential velocity component along the aiming direction, wherein the first velocity component, the second velocity component, and the tangential velocity component are perpendicular to each other. If the first deviation component does not meet the preset condition, the velocity is decomposed into a first velocity component perpendicular to the aiming direction and a tangential velocity component along the aiming direction, and the second velocity component is set to a specified value.
2. The method according to claim 1, characterized in that, The step of decomposing the velocity into a first velocity component along the first deviation component, a second velocity component, and a tangential velocity component along the aiming direction includes: The velocity is decomposed into a first velocity component along the first deviation component and an intermediate velocity component perpendicular to the first deviation component; The intermediate velocity component is decomposed into a tangential velocity component along the aiming direction and a second velocity component perpendicular to the aiming direction.
3. The method according to claim 1, characterized in that, Before decomposing the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction, the method further includes: Calculate the first angle between the deviation vector and the aiming direction; Calculate the second angle between the velocity and the aiming direction; If the first angle is less than or equal to the first preset angle, and the second angle is less than or equal to the second preset angle, the deviation vector is decomposed into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction.
4. The method according to claim 1, characterized in that, The step of calculating the acceleration in each specified direction based on the velocity component in that specified direction includes: Obtain the damping coefficient and the first proportional coefficient on the first velocity component, the second proportional coefficient on the second velocity component, and the tangential proportional coefficient on the tangential velocity component; The first acceleration under the first preset expected value is determined based on the product of the damping coefficient and the first velocity component, and the product of the first proportional coefficient and the second deviation component. Based on the second proportionality coefficient and the second velocity component, determine the second acceleration under the second preset expected value; Based on the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential scaling factor, the tangential acceleration at the desired velocity value is determined.
5. The method according to claim 4, characterized in that, The step of determining the tangential acceleration at the desired velocity value based on the first velocity value corresponding to the first velocity component, the second velocity value corresponding to the second velocity component, the tangential velocity component, and the tangential scaling factor includes: The desired tangential velocity value is calculated using the desired velocity value, the first velocity value, and the second velocity value; The larger of the desired tangential velocity value and the minimum tangential velocity value of the virtual object is determined as the target desired tangential velocity value; Calculate the tangential unit vector on the tangential velocity component; The tangential acceleration is calculated using the tangential unit vector, the tangential scaling factor, the target desired tangential velocity value, and the tangential velocity values corresponding to the tangential velocity components.
6. The method according to claim 4, characterized in that, The process of fusing accelerations in all specified directions to obtain the target acceleration of the virtual object includes: Summing the first acceleration, the second acceleration, and the tangential acceleration yields the desired acceleration; Calculate the unit vector of the desired acceleration to obtain the desired unit vector; The target acceleration is calculated based on the expected acceleration value corresponding to the expected acceleration, the expected unit vector, and the maximum acceleration value of the virtual object.
7. The method according to claim 6, characterized in that, The step of calculating the target acceleration based on the expected acceleration value corresponding to the expected acceleration, the expected unit vector, and the maximum acceleration value of the virtual object includes: The smaller of the maximum acceleration value and the desired acceleration value is determined as the target desired acceleration value; The target acceleration is obtained by multiplying the target expected acceleration value and the expected unit vector.
8. The method according to claim 1, characterized in that, The step of controlling the virtual object to move along the aiming direction based on the target acceleration includes: Calculate the specified displacement of the virtual object within a preset time interval based on the target acceleration and the velocity; Based on the target acceleration, calculate the velocity increment of the virtual object within the preset time interval; The displacement is updated using the specified displacement, and the velocity is updated using the velocity increment, so as to control the virtual object to move along the aiming direction.
9. A virtual object control device, characterized in that, The device includes: The acquisition module is used to acquire the aiming direction and aiming starting point of the aiming line, as well as the displacement and velocity of the virtual object; The deviation calculation module is used to calculate the deviation vector between the virtual object and the aiming starting point based on the displacement of the aiming starting point and the virtual object. A velocity decomposition module is used to decompose the velocity into multiple velocity components in specified directions based on the deviation vector, wherein the multiple velocity components are perpendicular to each other in pairs, and the multiple specified directions include the aiming direction; An acceleration calculation module is used to calculate the acceleration in the specified direction for each specified direction based on the velocity component in the specified direction. The fusion module is used to fuse all accelerations in the specified directions to obtain the target acceleration of the virtual object; The control module is used to control the virtual object to move along the aiming direction based on the target acceleration; The velocity decomposition module includes: A deviation decomposition unit is used to decompose the deviation vector into a first deviation component perpendicular to the aiming direction and a second deviation component along the aiming direction; The first decomposition unit is used to decompose the velocity into a first velocity component, a second velocity component, and a tangential velocity component along the aiming direction if the first deviation component meets a preset condition. The first velocity component, the second velocity component, and the tangential velocity component are perpendicular to each other. The second decomposition unit is used to decompose the velocity into a first velocity component perpendicular to the aiming direction and a tangential velocity component along the aiming direction if the first deviation component does not meet the preset condition, and to set the second velocity component to a specified value.
10. 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 virtual object control method as described in any one of claims 1 to 8.
11. 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 execute the steps of the virtual object control method according to any one of claims 1 to 8.