Game role control method and device based on center point
By pre-calculating the position pool of the character array, the problems of computational latency and performance overhead in the game character array are solved, and fast and smooth character movement and formation maintenance are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WUHU DOUZHAOWAN NETWORK TECHNOLOGY CO LTD
- Filing Date
- 2025-12-26
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies suffer from computational latency and performance overhead due to the large amount of computation required in game character arrays, which negatively impacts the gaming experience, especially when there are many characters.
By pre-calculating the position pool under different numbers of characters and center point coordinates, an index mapping table is generated, reducing the complexity of real-time coordinate calculation and using the position pool to achieve fast and smooth character position updates.
The computational complexity was reduced from O(n) to O(1), reducing the performance overhead of redundant calculations and improving the smoothness and stability of game character movement.
Smart Images

Figure CN121819331A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the game technical field, and particularly to a game character control method and device based on a center point. BACKGROUND
[0002] In the digital gate play of game software, a player controls the position of his own array (a group of human-shaped game characters) in the scene by long-pressing and dragging, and the array generally maintains a certain formation unchanged in the game process. If a digital light curtain is encountered, the number of characters corresponding to the digital light curtain will be increased or decreased, and after the number changes, the algorithm will refresh the position of the characters again to keep the overall array unchanged. When the character array moves due to dragging and the number of characters increases / decreases, the prior art needs to calculate the new coordinates of each character in real time according to the latest center point or the number of characters to ensure that the formation of the array is unchanged.
[0003] However, such real-time large-scale coordinate calculation not only causes calculation delay due to large calculation amount when the number of characters is large, affecting the game experience, but also needs to be recalculated for the same number of characters and the same center point appearing at different times, causing unnecessary performance overhead. Therefore, the technical problem of the present application is how to quickly and smoothly adjust the coordinate position of the character when the game character in the array changes position due to player operation, while ensuring the stability of the array formation and reducing real-time calculation overhead. SUMMARY
[0004] The present application provides a game character control method and device based on a center point, which can reduce the calculation complexity required for position refreshing in the game process, realize a quick and smooth dragging movement effect, and reduce the calculation overhead.
[0005] In a first aspect, the embodiments of the present application provide a game character control method based on a center point, comprising: obtaining the number of characters, a target formation, and a center point coordinate, calculating the position coordinates of each game character in the role array corresponding to the target formation based on the center point coordinate; calculating the Euclidean distance between the position coordinates of each game character and the center point coordinate; sorting each game character according to the Euclidean distance to obtain a character serial number; associating the character serial number and the position coordinates of the game character to obtain an index mapping table, and generating a position pool based on the number of characters, the target formation, the center point coordinate, and the index mapping table; receiving a dragging instruction, calculating the movement distance of the current character array according to the dragging instruction, and if the movement distance is greater than a preset change threshold, calculating the center point coordinate of the current character array after movement; Based on the center point coordinates and the number of characters in the current character array, a target position pool is matched, and the target position of each game character in the current character array is determined according to the index mapping table of the target position pool.
[0006] Furthermore, the method also includes: In response to a collision event, update the number of characters in the current character array and the current sequence number of each game character; Match the target position pool based on the center point coordinates of the current character array and the updated number of characters; The target location of each game character is determined based on the index mapping table of the target location pool.
[0007] Furthermore, the method also includes: After determining the target position of each game character, the game characters are moved from their current position to the corresponding target position according to the preset transition speed and smooth transition interpolation algorithm.
[0008] Furthermore, the method also includes: The obstacle avoidance range of the obstacle model is calculated based on the preset transition speed; When the current character array enters the obstacle avoidance range, the system determines whether obstacle avoidance was successful based on the coordinates of the center point of the current character array and the boundary of the obstacle model. If so, the system performs a compression operation on the current character array.
[0009] Furthermore, the above-mentioned compression operation on the current character array includes: Calculate the horizontal distance between any game character in the current character array and the center point coordinates; The cutting ratio of game characters is calculated based on horizontal distance; The horizontal offset of the game character is obtained based on the cutting ratio and horizontal distance. The game character moves towards the center of the current character array based on the horizontal offset.
[0010] Furthermore, the above-mentioned calculation of the game character's segmentation ratio based on horizontal distance includes: Calculate the sector half-angle based on the absolute value of the horizontal distance; Multiply the half-angle of the sector by 2 to obtain the target sector angle and calculate the corresponding sector area; Calculate the area of the triangle based on the absolute values of the target sector angle and horizontal distance; Subtract the area of the triangle from the area of the sector, and then divide by the area of the unit circle to obtain the cutting ratio.
[0011] Furthermore, the horizontal offset of the game character obtained based on the cutting ratio and horizontal distance includes: Multiply the cutting ratio by the horizontal distance to obtain the horizontal offset of the game character.
[0012] Furthermore, the method also includes: After the current character formation leaves the obstacle avoidance range, the recovery offset is obtained based on the horizontal offset. The game character moves away from the center of the current character array based on the recovery offset.
[0013] Furthermore, the method also includes: In response to combat commands, obtain the model radius value of the combat object model and the maximum radial value of the collider; The larger of the model radius value and the maximum radial value of the collider is taken as the enclosure radius value; Add the bounding radius, the preset safety distance, and the model radius of the game character to obtain the minimum radius; The combat coordinates of each game character in the current character array are determined based on the minimum radius and polar coordinate algorithm.
[0014] Furthermore, the above-mentioned algorithm for determining the combat coordinates of each game character in the current character array based on the minimum radius and polar coordinates includes: Add the model diameter of the game character to the preset safe distance to obtain the character spacing; Determine the target radius of multiple enclosing layers based on the character spacing and minimum radius; Calculate the enclosing arc length of each enclosing layer based on the target radius and the preset enclosing angle; Divide the length of each enclosing arc by the character interval to obtain the number of characters enclosed in each enclosing layer. Based on the number of characters encircled by each encircling layer and the current sequence number of each game character in the current character array, the game characters are divided to obtain the target layer number and the sorting of each game character in the target layer number. The combat angle of the game character is calculated based on the number of characters surrounding the target layer and the game character's order within the target layer. The combat angle and the target radius of the target layer are then used as the game character's combat coordinates.
[0015] Secondly, embodiments of this application provide a center-point-based game character control device, comprising: The acquisition module is used to acquire the number of characters, the target formation, and the coordinates of the center point. Based on the coordinates of the center point, it calculates the position coordinates of each game character when constructing the character array corresponding to the target formation. The distance calculation module is used to calculate the Euclidean distance between the position coordinates and center point coordinates of each game character; The sorting module is used to sort the game characters according to Euclidean distance and obtain the character number; The position pool module is used to associate the character number and position coordinates of game characters to obtain an index mapping table, and generate a position pool based on the number of characters, the target formation, the center point coordinates, and the index mapping table. The operation response module is used to receive drag commands, calculate the movement distance of the current character array based on the drag commands, and if the movement distance is greater than a preset change threshold, calculate the coordinates of the center point of the current character array after the movement. The position update module is used to match the target position pool based on the center point coordinates and the number of characters in the current character array, and to determine the target position of each game character in the current character array according to the index mapping table of the target position pool.
[0016] Furthermore, the device also includes a collision response module, which, in response to a collision event, updates the number of characters in the current character array and the current sequence number of each game character; matches a target position pool based on the center point coordinates of the current character array and the updated number of characters; and determines the target position of each game character according to the index mapping table of the target position pool.
[0017] Furthermore, the device also includes a smooth movement module, which, after determining the target position of each game character, moves the game character from its current position to the corresponding target position according to a preset transition speed and a smooth transition interpolation algorithm.
[0018] Furthermore, the device also includes an obstacle compression module, which is used to calculate the obstacle avoidance range of the obstacle model based on a preset transition speed; when the current character array enters the obstacle avoidance range, it determines whether obstacle avoidance is successful based on the center point coordinates of the current character array and the boundary of the obstacle model. If so, it performs a compression operation on the current character array.
[0019] Furthermore, the obstacle compression module is specifically used to calculate the horizontal distance between any game character in the current character array and the center point coordinates; calculate the cutting ratio of the game character based on the horizontal distance; obtain the horizontal offset of the game character based on the cutting ratio and the horizontal distance; and cause the game character to move towards the center point of the current character array based on the horizontal offset.
[0020] Furthermore, the device also includes a compression recovery module, which is used to obtain a recovery offset based on the horizontal offset after the current character array leaves the obstacle avoidance range; and to cause the game character to move in a direction away from the center point of the current character array based on the recovery offset.
[0021] Furthermore, the device also includes a combat encirclement module, which, in response to combat commands, obtains the model radius value of the combat object model and the maximum radial value of the collider; takes the larger value between the model radius value and the maximum radial value of the collider as the encirclement radius value; adds the encirclement radius value, the preset safety distance, and the model radius value of the game character to obtain the minimum radius; and determines the combat coordinates of each game character in the current character array based on the minimum radius and a polar coordinate algorithm.
[0022] Furthermore, the combat encirclement module is specifically used to add the model diameter value of the game character to the preset safety distance to obtain the character interval; determine the target radius of multiple encirclement layers based on the character interval and the minimum radius; calculate the encirclement arc length of each encirclement layer based on the target radius and the preset encirclement angle; divide each encirclement arc length by the character interval to obtain the number of characters encircled in each encirclement layer; divide each game character based on the number of characters encircled in each encirclement layer and the current sequence number of each game character in the current character array to obtain the target layer number and the ranking of each game character in the target layer number; calculate the combat angle of the game character based on the number of characters encircled in the target layer number and the ranking of the game character in the target layer number, and use the combat angle and the target radius of the target layer number as the combat coordinates of the game character.
[0023] Thirdly, embodiments of this application provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the steps of a center-point-based game character control method as described in any of the above embodiments.
[0024] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of a center-point-based game character control method as described in any of the above embodiments.
[0025] In summary, compared with the prior art, the beneficial effects of the technical solution provided in this application include at least the following: This application provides a center-point-based game character control method. First, it pre-calculates the positions of each game character at different center-point coordinates to maintain the target formation for different numbers of characters. Simultaneously, it generates a corresponding character number for each game character based on the Euclidean distance from the game character to the center-point coordinates, so that the corresponding position coordinates can be indexed according to the number later. The pre-calculated information is saved as a position pool, thereby obtaining the position pools corresponding to different numbers of characters, center-point coordinates, and target formations. During the game, when the player drags the current character array, causing the center-point coordinates to change, the new center-point coordinates to which the current character array will move are determined directly according to the drag command. The target position pool is determined according to the new center-point coordinates, the number of characters in the current character array, and the target formation. The pre-calculated position coordinates of each character in the position pool are retrieved as the target positions to refresh the game characters. This application moves the real-time coordinate calculation that was originally required to a position pool calculation, so that the real-time position update of the game character can be achieved directly through position pool matching during the game. The computational complexity is reduced from O(n) to O(1). Furthermore, the same number of characters, center point coordinates and target formation corresponding to the character positions do not need to be calculated repeatedly. The position pool can also be reused in different levels, which greatly reduces the performance overhead caused by redundant calculations. Attached Figure Description
[0026] Figure 1 A flowchart illustrating a center-point-based game character control method provided as an exemplary embodiment of this application.
[0027] Figure 2 A flowchart of the current role array compression operation provided for an exemplary embodiment of this application.
[0028] Figure 3 A flowchart illustrating a game character surrounding a combat object, provided as an exemplary embodiment of this application.
[0029] Figure 4 A flowchart illustrating the combat coordinate calculation steps provided in an exemplary embodiment of this application.
[0030] Figure 5 This is a structural diagram of a center-point-based game character control device provided as an exemplary embodiment of this application. Detailed Implementation
[0031] The technical solutions in 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.
[0032] Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0033] Please see Figure 1 This application provides a center-point-based game character control method, including: Step S11: Obtain the number of characters, the target formation, and the coordinates of the center point. Calculate the position coordinates of each game character in the target formation when constructing the character array corresponding to the target formation based on the coordinates of the center point.
[0034] The number of characters can be determined based on the game content. Taking the common Number Gate gameplay as an example, the range can be 100-2000, and the target formation can be rectangular, circular, or diamond-shaped. In the Number Gate gameplay, players can drag and control the movement of the character array, which is limited to left and right. At the same time, the character array collides with different digital light curtains / obstacles by moving the game scene. Therefore, different center point coordinates are actually different horizontal coordinates, while the vertical coordinate remains unchanged.
[0035] Specifically, when the target formation is rectangular, the position coordinates of each game character are calculated using a row and column grid, with the center point as the origin and the coordinates of (column i, row j) as (i * spacing, ...). j*spacing), where spacing is the row and column grid spacing; when the target formation is circular, the position coordinates of each game character are calculated using polar coordinates, and the angle of the nth game character is 2π*n / number of characters, with the radius increasing according to the level; when the target formation is rhombus, the spacing between adjacent game characters is fixed at 0.8 meters (in fact, it is only necessary to ensure that the two character models do not overlap, so we also take 0.7 / 0.9 meters to ensure horizontal / vertical consistency), the side length of the rhombus = number of levels × spacing × 2, where "level" refers to the concentric circles from the center outward (for example, level 1 has a side length of 1.6 meters, level 2 has a side length of 3.2 meters), when there is n levels, the number of characters = 1 + 4 × (1 + 2 + ... + (n-1)) = 1 + 2n(n-1) (1 person in the center, each level has 4 more people than the previous level), for example, level 3 corresponds to 13 people (1 + 4 + 8), with a side length of 4.8 meters, level 10 corresponds to 191 people, with a side length of 16 meters.
[0036] Step S12: Calculate the Euclidean distance between the position coordinates and center point coordinates of each game character.
[0037] Step S13: Sort each game character according to Euclidean distance to obtain the character number.
[0038] Specifically, taking the center point coordinates as the origin, other game characters calculate their relative coordinates based on the center point coordinates, calculate the Euclidean distance between the game character and the center point coordinates based on the relative coordinates, and sort them in ascending order to obtain the character number of each game character.
[0039] Step S14: Associate the character number and position coordinates of the game characters to obtain an index mapping table, and generate a position pool based on the number of characters, the target formation, the center point coordinates, and the index mapping table.
[0040] When generating the position pool, the position pool is named "number of characters + target formation" so that it can be matched with the target position pool later. The position pool includes an index mapping table of number of characters + center point coordinates + target formation.
[0041] The specific data structure stored in the ScriptableObject (position pool) can be: public class FormationDataSO : ScriptableObject { public FormationType type; / / Formation type (diamond / rectangle / circle) public int maxSoldierCount; / / The number of characters this formation supports (e.g., 2000) public Vector2[] positions; / / Position coordinates, storing the relative coordinates (x, y) of each soldier. public int[] sortedIndices; / / Role numbers sorted by Euclidean distance (ascending order) public int defaultCenterIdx; / / Default center index, coordinates of the center point public float updateThreshold; / / Preset change threshold to trigger an update of CurCenterIdx Step S15: Receive drag command, calculate the movement distance of the current character array according to the drag command, and if the movement distance is greater than the preset change threshold, calculate the center point coordinates of the current character array after the movement.
[0042] Step S16: Match the target position pool based on the center point coordinates and the number of characters in the current character array, and determine the target position of each game character in the current character array according to the index mapping table of the target position pool.
[0043] Specifically, when a player drags the current character array and causes the center point coordinates to change beyond the preset change threshold updateThreshold, the index mapping table corresponding to the position pool of the current character array's formation and character quantity index is obtained based on the center point coordinates after the movement, and the current sequence number of each game character in the current character array is matched to determine the target position of each game character after the center point coordinates are moved, and each game character is refreshed to the target position.
[0044] Furthermore, the method also includes: Step S17: After determining the target positions of each game character, the game characters are moved from their current positions to their corresponding target positions according to a preset transition speed and a smooth transition interpolation algorithm. Specifically, the smooth transition interpolation algorithm uses Transform.Lerp and Vector3.SmoothDamp to implement the game character movement animation, recording the game character's current position as the transition start point and the target position as the transition end point. Interpolation is performed between the transition start point and the end point according to the preset transition speed, allowing dynamic adjustment of the preset transition speed (0.1-2 seconds) to adapt to different game combat rhythms.
[0045] The above embodiment provides a center-point-based game character control method. First, it pre-calculates the positions of each game character at different center-point coordinates to maintain the target formation for different numbers of characters. Simultaneously, it generates a corresponding character number for each game character based on the Euclidean distance from the game character to the center-point coordinates, so that the corresponding position coordinates can be indexed according to the number later. The pre-calculated information is saved as a position pool, thereby obtaining the position pools corresponding to different numbers of characters, center-point coordinates, and target formations. During the game, when the player drags the current character array, causing the center-point coordinates to change, the new center-point coordinates to which the current character array will move are directly determined according to the drag command. The target position pool is determined according to the new center-point coordinates, the number of characters in the current character array, and the target formation. The pre-calculated position coordinates of each character in the position pool are retrieved as the target positions to refresh the game characters. This application moves the real-time coordinate calculation that was originally required to a position pool calculation, so that the real-time position update of the game character can be achieved directly through position pool matching during the game. The computational complexity is reduced from O(n) to O(1). Furthermore, the same number of characters, center point coordinates and target formation corresponding to the character positions do not need to be calculated repeatedly. The position pool can also be reused in different levels, which greatly reduces the performance overhead caused by redundant calculations.
[0046] In some embodiments, the method further includes: Step S21: In response to the collision event, update the number of characters in the current character array and the current sequence number of each game character.
[0047] If the current character array collides with the digital light screen in the game scene, or with an obstacle, some game characters in the current character array will be killed / disappear, or some game characters will be added. In this case, the number of characters and the current sequence number of some game characters need to be updated. In the specific implementation, ObjectPool technology can be used to manage character model instances, reducing the performance overhead caused by frequent instantiation / destruction.
[0048] Specifically, if the serial number of a missing / defeated game character is in the middle, the game characters with subsequent serial numbers will automatically fill the gap to ensure that the serial numbers are not interrupted. For example, if game characters with serial numbers 1-260 have serial numbers 30-36 and 90-127 missing / defeated, then the current serial numbers of game characters with serial numbers 37-89 and 128-260 must be reduced until the serial numbers 1-215 are filled. The serial number of a newly added game character starts from the largest serial number in the original current character array and increments. For example, if the largest serial number of a game character in the original array is 186, then the newly added character will increment sequentially starting from 187.
[0049] Step S22: Match the target position pool based on the center point coordinates of the current character array and the updated number of characters.
[0050] Step S23: Determine the target position of each game character based on the index mapping table of the target position pool.
[0051] The above embodiments can also achieve fast position switching of game characters by indexing the target position pool when the number of characters in the current character array increases or decreases, avoiding the latency and performance consumption caused by real-time position calculation.
[0052] In some embodiments, the method further includes: Step S31: Calculate the obstacle avoidance range of the obstacle model based on the preset transition speed.
[0053] Specifically, in this application, the movement of the game character is not directly refreshed in the next frame, but transitions to the target position frame by frame. This means that multiple frames are required for the game character to move to the target position. Consequently, when encountering obstacles, the player needs to react in advance to perform an avoidance maneuver for the obstacle avoidance animation to display perfectly. Otherwise, unreasonable situations may occur where the current character formation collides with the obstacle model or even clips through it before fully reaching an open area. To address this, this application sets an obstacle avoidance range for the obstacle model based on a preset transition speed. The maximum duration of the character movement animation after the player drags the current character formation (e.g., the time to move from the leftmost to the rightmost point) is calculated based on the preset transition speed. This maximum duration is then multiplied by the movement speed of the game scene to obtain the radius of the obstacle avoidance range, which is a circle centered on the obstacle model.
[0054] It can be considered that the obstacle avoidance range is the limit of the position where the player can perform obstacle avoidance operations. The player must adjust the center point coordinate of the current character array to meet the obstacle avoidance requirements outside the obstacle avoidance range. Otherwise, some game characters in the current character array will inevitably collide with the obstacle model before they have moved to the target position, triggering the disappearance / death mechanism and causing obstacle avoidance failure.
[0055] Step S32: When the current character array enters the obstacle avoidance range, determine whether obstacle avoidance is successful based on the center point coordinates of the current character array and the boundary of the obstacle model. If so, perform a compression operation on the current character array.
[0056] If the player completes obstacle avoidance adjustments for the current character array before reaching the obstacle avoidance range (e.g., dragging the current character array so that the distance between its center point coordinates and the boundary of the obstacle model is greater than a certain threshold), then when the obstacle arrives, all game characters in the current character array will have already moved to their target positions. At this point, the current character array can likely pass smoothly through the gap between the obstacle and the game boundary. However, if the number of characters in the current character array has become very large due to the digital light curtain mechanism, there is a possibility that game character models at the edge of the array may collide with obstacle models or partially clip through them. To avoid this, the character model density of the current character array when passing through obstacles needs to be compressed. However, in traditional solutions, the compression and deformation of the character array based on obstacles or game scene boundaries usually uses physical collision technology, which consumes a lot of performance from the game device and is prone to causing lag. Therefore, this application proposes an elastic deformation algorithm: Specifically, please see Figure 2 The above compression operation on the current character array includes: Step S321: Calculate the horizontal distance between any game character in the current character array and the center point coordinates.
[0057] Step S322: Calculate the cutting ratio of the game character based on the horizontal distance.
[0058] In the specific implementation process, the above-mentioned calculation of the game character's segmentation ratio based on horizontal distance includes: Step S3221: Calculate the half angle of the sector based on the absolute value of the horizontal distance.
[0059] First, calculate the sector half-angle sectorHalfRadian=arccos(absPosX) for the absolute value of the horizontal distance.
[0060] Where absPosX = |xPosPercent|, and xPosPercent is the horizontal distance.
[0061] Step S3222: Multiply the half angle of the sector by 2 to obtain the target sector angle and calculate the corresponding sector area.
[0062] Sector area = (sector angle / 360°) × π = ((2 × sector Half Radian) / 360°) × π.
[0063] Step S3223: Calculate the area of the triangle based on the absolute values of the target sector angle and horizontal distance.
[0064] Specifically, the area of the triangle = 2 × sin(sectorHalfRadian) × absPosX × 0.5.
[0065] Step S3224: Subtract the area of the triangle from the area of the sector, and then divide by the area of the unit circle to obtain the cutting ratio.
[0066] Cut Percent = Area of the arc / Area of the unit circle = (Area of the sector - Area of the triangle) / Area of the unit circle.
[0067] The arc area is the area that needs to be cut and avoided, and the result of the cutting ratio should fall within the range of [0, 0.25].
[0068] The program code for steps S3221-S3224 above is as follows (input parameter is xPosPercent, output parameter is cutPercent): function SDSoliderTeam:GetCutCircleRatio(xPosPercent) local absPosX = math.abs(xPosPercent); local sectorHalfRadian = math.acos(absPosX); local sectorAngle = math.deg(sectorHalfRadian) * 2; local sectorS = (sectorAngle / 360) * math.pi; local bottomLen = math.sin(sectorHalfRadian) * 2; local triangleS = bottomLen * absPosX * 0.5; local cutS = sectorS - triangleS; local cutPercent = cutS / math.pi; return cutPercent; end Step S323: Obtain the horizontal offset of the game character based on the cutting ratio and horizontal distance.
[0069] Specifically, the horizontal offset of the game character is obtained by multiplying the cutting ratio and the horizontal distance.
[0070] Step S324: Move the game character towards the center point of the current character array according to the horizontal offset.
[0071] Specifically, the game character moves only according to the horizontal offset, that is, the game character only moves left and right. If the game character is to the left of the center point, it moves to the right by the horizontal offset, and vice versa.
[0072] It can be assumed that the horizontal distance between the game character and the center point coordinates is positively correlated with the horizontal offset of the game character. That is, the farther away from the center point, the closer the game character is to the array boundary and the obstacle model, and the greater the degree of compression.
[0073] Furthermore, the method also includes: Step S33: After the current character array leaves the obstacle avoidance range, obtain the recovery offset based on the horizontal offset.
[0074] Step S34: Move the game character away from the center point of the current character array according to the recovery offset.
[0075] The recovery offset and the horizontal offset are equal, but in different directions. If the horizontal offset was moved to the left during the previous compression, the recovery offset is moved to the right at this time, thus restoring the original formation.
[0076] The above embodiment achieves the elastic deformation compression effect of the current character array when passing through obstacles by calculating the horizontal offset, avoiding the use of physical collision technology in traditional solutions. This not only reduces performance consumption but also ensures the integrity of the formation, preventing it from falling apart or becoming stiff, thus improving visual smoothness and player experience.
[0077] Please see Figure 3 Before the Digital Gate gameplay ends, a Boss battle often takes place, where the game characters in the current character queue fight against the final Boss. Existing technologies often involve having the game characters revolve around the Boss's character model, but this can easily lead to overlapping units of different game characters. To solve this problem, the method in this application also includes: Step S41: In response to the combat command, obtain the model radius value and the maximum radial value of the collider of the combat object model.
[0078] Step S42: Take the larger of the model radius value and the maximum radial value of the colliding body as the enclosing radius value.
[0079] The maximum radial value of the collider is the maximum radial value of the collider's bounds.extents in the Unity engine.
[0080] Step S43: Add the bounding radius value, the preset safety distance, and the model radius value of the game character to obtain the minimum radius.
[0081] Here, the minimum radius is the minimum radius of the encirclement formed by the game character and the combat target, or the radius of the encirclement closest to the combat target. The preset safe distance refers to a value X, which can be 0.5 / 1 / 10 / 100. The basis for choosing the value is that the game character and the combat target should not be too close.
[0082] Step S44: Determine the combat coordinates of each game character in the current character array based on the minimum radius and polar coordinate algorithm.
[0083] Please see Figure 4 In specific implementation, the above-mentioned algorithm based on minimum radius and polar coordinates for determining the combat coordinates of each game character in the current character array can include: Step S441: Add the model diameter value of the game character to the preset safety distance to obtain the character interval.
[0084] Step S442: Determine the target radius of multiple enclosing layers based on the character interval and minimum radius.
[0085] Specifically, the character interval obtained by adding the model diameter value and the preset safety distance is the distance interval between two adjacent game characters in the same encirclement layer, and also the interval between two adjacent encirclement layers. Taking the second encirclement layer as an example, its radius is equal to the minimum radius plus the character interval. Therefore, the target radius R of each encirclement layer can be expressed as R=r+(m-1)*L, where m is the mth encirclement layer from the inside out, L is the character interval, and r is the minimum radius.
[0086] Step S443: Calculate the enclosing arc length of each enclosing layer based on the target radius and the preset enclosing angle.
[0087] The preset encirclement angle is the angle of encirclement. The preset encirclement angle of each encirclement layer can be the same or different. Currently, 90° or 120° is commonly used in practice, which means that only about 1 / 3 of the combat object model is encircled.
[0088] The method for calculating the arc length of a sector is common knowledge in the field of mathematics, and will not be elaborated further here.
[0089] Step S444: Divide the length of each enclosing arc by the character interval to obtain the number of characters enclosing each enclosing layer.
[0090] Step S445: Divide each game character according to the number of characters encircled by each encircling layer and the current sequence number of each game character in the current character array to obtain the target layer number and the sorting of each game character in the target layer number.
[0091] Step S446: Calculate the combat angle of the game character based on the number of characters surrounding the target layer and the order of the game character in the target layer, and use the combat angle and the target radius of the target layer as the combat coordinates of the game character.
[0092] Specifically, by dividing the encircling arc length by the character interval, we can obtain how many game characters the encircling layer corresponding to the encircling arc length can accommodate, while ensuring that the game characters do not overlap with each other. Then, the game characters in the current character array are arranged according to their current sequence number, starting from the first encircling layer (i.e., the layer closest to the combat target). After the number of characters encircling the first encircling layer is filled, the second encircling layer is arranged, and so on, until all the characters in the current character array form an encircling circle.
[0093] Each game character's combat coordinates are polar coordinates (R, θ) with the combat object model as the origin, where the angle θ = (α*n) / N, α is the preset encirclement angle, n is the game character's ranking in the target layer, and N is the number of characters encircled in the target layer.
[0094] The polar coordinate-based character distribution algorithm defined in the above embodiments can not only avoid overlapping and clipping when game characters are surrounded, but also avoid local denseness when the number of characters does not match the size of the combat object model.
[0095] Please see Figure 5 Another embodiment of this application provides a center-point-based game character control device, including: The acquisition module 101 is used to acquire the number of characters, the target formation, and the coordinates of the center point, and to calculate the position coordinates of each game character when constructing the character array corresponding to the target formation based on the coordinates of the center point.
[0096] The distance calculation module 102 is used to calculate the Euclidean distance between the position coordinates and center point coordinates of each game character.
[0097] The sorting module 103 is used to sort the game characters according to Euclidean distance to obtain the character number.
[0098] The position pool module 104 is used to associate the character number and position coordinates of game characters to obtain an index mapping table, and generate a position pool based on the number of characters, target formation, center point coordinates and index mapping table.
[0099] The operation response module 105 is used to receive drag commands, calculate the movement distance of the current character array based on the drag commands, and if the movement distance is greater than a preset change threshold, calculate the coordinates of the center point of the current character array after the movement.
[0100] The position update module 106 is used to match the target position pool based on the center point coordinates and the number of characters in the current character array, and to determine the target position of each game character in the current character array according to the index mapping table of the target position pool.
[0101] Furthermore, the device also includes a collision response module, which, in response to a collision event, updates the number of characters in the current character array and the current sequence number of each game character; matches a target position pool based on the center point coordinates of the current character array and the updated number of characters; and determines the target position of each game character according to the index mapping table of the target position pool.
[0102] Furthermore, the device also includes a smooth movement module, which, after determining the target position of each game character, moves the game character from its current position to the corresponding target position according to a preset transition speed and a smooth transition interpolation algorithm.
[0103] Furthermore, the device also includes an obstacle compression module, which is used to calculate the obstacle avoidance range of the obstacle model based on a preset transition speed; when the current character array enters the obstacle avoidance range, it determines whether obstacle avoidance is successful based on the center point coordinates of the current character array and the boundary of the obstacle model. If so, it performs a compression operation on the current character array.
[0104] Furthermore, the obstacle compression module is specifically used to calculate the horizontal distance between any game character in the current character array and the center point coordinates; calculate the cutting ratio of the game character based on the horizontal distance; obtain the horizontal offset of the game character based on the cutting ratio and the horizontal distance; and cause the game character to move towards the center point of the current character array based on the horizontal offset.
[0105] Furthermore, the device also includes a compression recovery module, which is used to obtain a recovery offset based on the horizontal offset after the current character array leaves the obstacle avoidance range; and to cause the game character to move in a direction away from the center point of the current character array based on the recovery offset.
[0106] Furthermore, the device also includes a combat encirclement module, which, in response to combat commands, obtains the model radius value of the combat object model and the maximum radial value of the collider; takes the larger value between the model radius value and the maximum radial value of the collider as the encirclement radius value; adds the encirclement radius value, the preset safety distance, and the model radius value of the game character to obtain the minimum radius; and determines the combat coordinates of each game character in the current character array based on the minimum radius and a polar coordinate algorithm.
[0107] Furthermore, the combat encirclement module is specifically used to add the model diameter value of the game character to the preset safety distance to obtain the character interval; determine the target radius of multiple encirclement layers based on the character interval and the minimum radius; calculate the encirclement arc length of each encirclement layer based on the target radius and the preset encirclement angle; divide each encirclement arc length by the character interval to obtain the number of characters encircled in each encirclement layer; divide each game character based on the number of characters encircled in each encirclement layer and the current sequence number of each game character in the current character array to obtain the target layer number and the ranking of each game character in the target layer number; calculate the combat angle of the game character based on the number of characters encircled in the target layer number and the ranking of the game character in the target layer number, and use the combat angle and the target radius of the target layer number as the combat coordinates of the game character.
[0108] The specific limitations of the center-point-based game character control device provided in this embodiment can be found in the embodiment of the center-point-based game character control method described above, and will not be repeated here. Each module in the above-described center-point-based game character control device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0109] This application provides a computer device that may include a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it causes the processor to perform the steps of a center-based game character control method as described in any of the above embodiments.
[0110] The working process, working details and technical effects of the computer device provided in this embodiment can be found in the embodiment of a center-point-based game character control method described above, and will not be repeated here.
[0111] This application provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the steps of a center-based game character control method as described in any of the above embodiments. The computer-readable storage medium refers to a data storage carrier, which may include, but is not limited to, floppy disks, optical disks, hard disks, flash memory, USB flash drives, and / or memory sticks. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The working process, details, and technical effects of the computer-readable storage medium provided in this embodiment can be found in the embodiments of a center-based game character control method described above, and will not be repeated here.
[0112] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM).
[0113] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0114] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A center-point-based game character control method, characterized in that, include: Obtain the number of characters, the target formation, and the coordinates of the center point; and calculate the position coordinates of each game character of the specified number of characters when constructing the character array corresponding to the target formation based on the coordinates of the center point. Calculate the Euclidean distance between the position coordinates of each game character and the coordinates of the center point; The game characters are sorted according to the Euclidean distance to obtain character numbers; The game character's serial number and position coordinates are associated to obtain an index mapping table. A position pool is generated based on the number of characters, the target formation, the center point coordinates, and the index mapping table. Receive a drag command, calculate the movement distance of the current character array based on the drag command, and if the movement distance is greater than a preset change threshold, calculate the coordinates of the center point of the current character array after the movement. Based on the center point coordinates and the number of characters in the current character array, a target position pool is matched, and the target position of each game character in the current character array is determined according to the index mapping table of the target position pool.
2. The center-point-based game character control method according to claim 1, characterized in that, Also includes: In response to a collision event, update the number of characters in the current character array and the current sequence number of each game character; Match the target position pool based on the center point coordinates of the current character array and the updated number of characters; The target location of each game character is determined based on the index mapping table of the target location pool.
3. The center-point-based game character control method according to claim 1, characterized in that, Also includes: After determining the target position of each game character, the game character is moved from its current position to the corresponding target position according to a preset transition speed and a smooth transition interpolation algorithm.
4. The center-point-based game character control method according to claim 3, characterized in that, Also includes: The obstacle avoidance range of the obstacle model is calculated based on the preset transition speed; When the current character array enters the obstacle avoidance range, it is determined whether obstacle avoidance is successful based on the center point coordinates of the current character array and the boundary of the obstacle model. If so, a compression operation is performed on the current character array.
5. The center-point-based game character control method according to claim 4, characterized in that, The compression operation performed on the current character array includes: Calculate the horizontal distance between any game character in the current character array and the center point coordinates; The cutting ratio of the game character is calculated based on the horizontal distance; The horizontal offset of the game character is obtained based on the cutting ratio and the horizontal distance. The game character is instructed to move towards the center point of the current character array based on the horizontal offset.
6. The center-point-based game character control method according to claim 5, characterized in that, The calculation of the game character's cut ratio based on the horizontal distance includes: Calculate the sector half-angle based on the absolute value of the horizontal distance; Multiply the half-angle of the sector by 2 to obtain the target sector angle and calculate the corresponding sector area; The area of the triangle is calculated based on the absolute values of the target sector angle and the horizontal distance; Subtract the area of the triangle from the area of the sector, and then divide by the area of the unit circle to obtain the cutting ratio.
7. The center-point-based game character control method according to claim 5, characterized in that, The step of obtaining the horizontal offset of the game character based on the cutting ratio and the horizontal distance includes: Multiply the cutting ratio and the horizontal distance to obtain the horizontal offset of the game character.
8. The center-point-based game character control method according to claim 5, characterized in that, Also includes: After the current character array leaves the obstacle avoidance range, the recovery offset is obtained based on the horizontal offset. The game character is instructed to move away from the center point of the current character array based on the recovery offset.
9. The center-point-based game character control method according to claim 1, characterized in that, Also includes: In response to combat commands, obtain the model radius value of the combat object model and the maximum radial value of the collider; The larger of the model radius value and the maximum radial value of the collider is taken as the enclosure radius value; The minimum radius is obtained by adding the bounding radius value, the preset safety distance, and the model radius value of the game character; The combat coordinates of each game character in the current character array are determined based on the minimum radius and polar coordinate algorithm.
10. The center-point-based game character control method according to claim 9, characterized in that, The process of determining the combat coordinates of each game character in the current character array based on the minimum radius and polar coordinate algorithm includes: Add the model diameter value of the game character to the preset safety distance to obtain the character interval; The target radius of multiple enclosing layers is determined based on the role interval and the minimum radius; Calculate the enclosing arc length of each enclosing layer based on the target radius and the preset enclosing angle; Divide the length of each enclosing arc by the role interval to obtain the number of roles enclosing each enclosing layer. Based on the number of characters encircled by each encircling layer and the current sequence number of each game character in the current character array, each game character is divided to obtain the target layer number and the sorting of each game character in the target layer number. The combat angle of the game character is calculated based on the number of characters surrounding the target layer and the ranking of the game character in the target layer. The combat angle and the target radius of the target layer are used as the combat coordinates of the game character.
11. A center-point-based game character control device, characterized in that, include: The acquisition module is used to acquire the number of characters, the target formation, and the coordinates of the center point, and to calculate the position coordinates of each game character of the specified number of characters when constructing the character array corresponding to the target formation based on the coordinates of the center point. The distance calculation module is used to calculate the Euclidean distance between the position coordinates of each game character and the coordinates of the center point; The sorting module is used to sort each of the game characters according to the Euclidean distance to obtain the character number; The position pool module is used to associate the character number and position coordinates of the game characters to obtain an index mapping table, and to generate a position pool based on the number of characters, the target formation, the center point coordinates and the index mapping table; The operation response module is used to receive drag commands, calculate the movement distance of the current character array based on the drag commands, and if the movement distance is greater than a preset change threshold, calculate the coordinates of the center point of the current character array after the movement. The position update module is used to match the target position pool based on the center point coordinates and the number of characters in the current character array, and to determine the target position of each game character in the current character array according to the index mapping table of the target position pool.
12. The center-point-based game character control device according to claim 11, characterized in that, It also includes a collision response module, used to update the number of characters in the current character array and the current sequence number of each game character in response to a collision event; and to match a target position pool based on the center point coordinates of the current character array and the updated number of characters. The target location of each game character is determined based on the index mapping table of the target location pool.
13. The center-point-based game character control device according to claim 11, characterized in that, It also includes a smooth movement module, which, after determining the target position of each game character, moves the game character from its current position to the corresponding target position according to a preset transition speed and a smooth transition interpolation algorithm.
14. The center-point-based game character control device according to claim 13, characterized in that, It also includes an obstacle compression module, which is used to calculate the obstacle avoidance range of the obstacle model based on the preset transition speed; when the current character array enters the obstacle avoidance range, it determines whether the obstacle avoidance is successful based on the center point coordinates of the current character array and the boundary of the obstacle model. If so, it performs a compression operation on the current character array.
15. The center-point-based game character control device according to claim 14, characterized in that, The obstacle compression module is specifically used to calculate the horizontal distance between any game character in the current character array and the center point coordinates; and to calculate the cutting ratio of the game character based on the horizontal distance. The horizontal offset of the game character is obtained based on the cutting ratio and the horizontal distance. The game character is instructed to move towards the center point of the current character array based on the horizontal offset.
16. The center-point-based game character control device according to claim 15, characterized in that, It also includes a compression recovery module, used to obtain a recovery offset based on the horizontal offset after the current character array leaves the obstacle avoidance range; and to cause the game character to move in a direction away from the center point of the current character array based on the recovery offset.
17. The center-point-based game character control device according to claim 11, characterized in that, It also includes a combat encirclement module, which, in response to combat commands, obtains the model radius value and the maximum radial value of the collider of the combat object model; and takes the larger of the model radius value and the maximum radial value of the collider as the encirclement radius value; The minimum radius is obtained by adding the bounding radius value, the preset safety distance, and the model radius value of the game character; the combat coordinates of each game character in the current character array are determined based on the minimum radius and the polar coordinate algorithm.
18. The center-point-based game character control device according to claim 17, characterized in that, The combat encirclement module is specifically used to add the model diameter value of the game character to the preset safety distance to obtain the character interval; determine the target radius of multiple encirclement layers based on the character interval and the minimum radius; calculate the encirclement arc length of each encirclement layer based on the target radius and the preset encirclement angle; divide each encirclement arc length by the character interval to obtain the number of characters encircled by each encirclement layer; divide each game character based on the number of characters encircled by each encirclement layer and the current sequence number of each game character in the current character array to obtain the target layer number and the ranking of each game character in the target layer number; calculate the combat angle of the game character based on the number of characters encircled by the target layer number and the ranking of the game character in the target layer number, and use the combat angle and the target radius of the target layer number as the combat coordinates of the game character.
19. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the center-point-based game character control method as described in any one of claims 1 to 10.
20. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the center-point-based game character control method as described in any one of claims 1 to 10.