A collision detection method for character movement in a game

Through the grid-form map and obstacle expansion algorithm, the collision point and movement direction of the game character and the obstacle are detected in real time, which solves the problem of large collision detection calculation in traditional game engines and realizes a simple and efficient collision detection method, which is suitable for Customization needs in the game.

CN114949858BActive Publication Date: 2024-10-11XIAMEN FEIXIN NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210633831.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-06
Publication Date
2024-10-11
Estimated Expiration
2042-06-06

AI Technical Summary

Technical Problem

Physical collision detection in traditional game engines requires a large amount of calculations and is not suitable for customized needs, making it difficult to transform the project due to its huge size.

Method used

Using a grid-form map and obstacle expansion algorithm, the collision point and movement direction are detected in real time through the relationship between the expansion body of static and dynamic obstacles and the position of the center of mass of the game character, and are simplified to the relationship between points and polygons to improve detection efficiency.

Benefits of technology

It implements lightweight character and obstacle collision detection to meet customized needs, reduces computational complexity and engineering complexity, and improves game performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114949858B_ABST
    Figure CN114949858B_ABST
Patent Text Reader

Abstract

The present invention provides a collision detection method for character movement in a game, comprising the following steps: according to the radius of the game character, an obstacle expansion algorithm is used to expand a static obstacle to obtain a static obstacle expansion body; each grid covered by it is written into a grid index; for a dynamic obstacle, it is expanded to obtain a dynamic obstacle expansion body, and the grid index of each grid covered by it is refreshed during the game; when the game character needs to move, according to its position and velocity vector, the obstacle that collides is detected, and the collision point and the moving direction after the collision are calculated. The present invention is a method suitable for games, for detecting collisions between characters and obstacles and determining the moving direction of the characters after the collision occurs, and the scheme is relatively simple while taking efficiency into consideration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a collision detection method, in particular to a collision detection method for character movement in a game. Background Art

[0002] In most games, characters will move and there will be many obstacles, so it is necessary to perform collision detection between characters and obstacles and determine the direction of character movement after a collision occurs.

[0003] In the traditional solution, the game engine is used to provide the results of physical collisions and confirm the direction of the character's movement after the collision. However, it has the following problems: large amount of calculation, deep binding with the game engine, huge engineering and difficult modification, and not suitable for customized requirements. Summary of the invention

[0004] In view of the defects of the prior art, the present invention provides a collision detection method for character movement in a game, which can effectively solve the above problems.

[0005] The technical solution adopted by the present invention is as follows:

[0006] The present invention provides a collision detection method for character movement in a game, comprising the following steps:

[0007] Step 1: The map in the game scene is in grid form and has multiple grids;

[0008] Step 2: Display multiple static obstacles in the map. For any static obstacle, represented as static obstacle Static_obs(i), perform the following operations:

[0009] Step 2.1, the radius of the game character is R0; according to the radius of the game character R0, the obstacle expansion algorithm is used to expand the static obstacle Static_obs(i) to obtain the static obstacle expansion body E Static_obs(i);

[0010] Step 2.2, for each grid Grid covered by the static obstacle expansion body E Static_obs(i), write the grid index, which is: the ID of the static obstacle S_obs(i);

[0011] Step 3: During the game, for dynamic obstacles, represented by dynamic obstacle Move_obs(j), the following operations are performed in real time:

[0012] Step 3.1, using the obstacle expansion algorithm in advance to expand the dynamic obstacle Move_obs(j) to obtain the dynamic obstacle expansion body E Move_obs(j) and save it;

[0013] Step 3.2, assuming that the current position of the dynamic obstacle Move_obs(j) is u1, read the dynamic obstacle expansion body E Move_obs(j), and according to the current posture of the dynamic obstacle Move_obs(j), display the dynamic obstacle expansion body E Move_obs(j) at the current position u1 according to the current posture;

[0014] For each grid Grid covered by the dynamic obstacle expansion body E Move_obs(j), the grid index is written, and the grid index is: the ID of the dynamic obstacle Move_obs(j);

[0015] Step 3.3, when the dynamic obstacle Move_obs(j) moves, if it moves from position u1 to position u2, first clear the grid index written in step 3.2;

[0016] Then read the dynamic obstacle expansion body E Move_obs(j), and display the dynamic obstacle expansion body E Move_obs(j) at the current position u2 according to the current posture of the dynamic obstacle Move_obs(j);

[0017] For each grid Grid covered by the dynamic obstacle expansion body E Move_obs(j), the grid index is written, and the grid index is: the ID of the dynamic obstacle Move_obs(j);

[0018] This cycle is repeated continuously to realize the dynamic display of the dynamic obstacle Move_obs(j);

[0019] Step 4: During the game, when the game character role needs to move, assume that the current position of the center of mass of the game character role is point A, and its coordinates are (x A ,y A ), the game character radius is R0, and its velocity vector is Use the following method to determine the role of the game character according to the velocity vector The moving collision point and the moving direction after collision:

[0020] Step 4.1, pre-set the search range radius r;

[0021] Step 4.2, simplify the game character role into a point, and the location of the point is the location of the centroid of the game character role;

[0022] Taking the current position A as the starting point, according to the velocity vector Search for a motion path of length r in the direction of the motion path; determine whether there is a grid with a grid index written in the grid that the motion path passes through; if not, it means that the game character role is moving according to the velocity vector When moving to the next position, it will not collide with the static obstacle Static_obs(i) and the dynamic obstacle Move_obs(j);

[0023] If yes, then obtain all grid indexes in the grid Grid that the motion path passes through, and then obtain the IDs of all static obstacles S_obs(i) and / or the IDs of dynamic obstacles Move_obs(j). At this time, the obtained IDs of static obstacles S_obs(i) and / or the IDs of dynamic obstacles Move_obs(j) are collectively referred to as obstacle IDs;

[0024] Then proceed to step 4.3;

[0025] Step 4.3, for each obstacle ID obtained in step 4.2, the obstacle expansion body is displayed in the map;

[0026] For each obstacle expansion body, the following method is used to calculate the distance L: the intersection of the motion path and the obstacle expansion body is the possible collision point, and the distance between the current center of mass position of the game character role and the possible collision point is calculated as the distance L;

[0027] Then, the distance L corresponding to each obstacle expansion body is compared to obtain the obstacle expansion body corresponding to the minimum distance L, which is expressed as: obstacle expansion body E_obs(min);

[0028] Therefore, the intersection of the motion path and the obstacle expansion body E_obs(min) is the final collision point, expressed as: collision point dote(last);

[0029] The obstacle expansion body E_obs(min) forms a normal at the collision point dote(last). The line connecting the current center of mass of the game character role and the collision point dote(last) is the movement path of the game character role, which is located on one side of the normal. When the game character role moves to the collision point dote(last), it moves along the outer boundary of the obstacle expansion body E_obs(min) on the other side of the normal, which is the movement direction after the detected collision.

[0030] At this point, the collision point and the direction of movement after the collision are determined.

[0031] Preferably, the static obstacle expansion body E Static_obs(i) and the dynamic obstacle expansion body EMove_obs(j) are both obstacle polygonal shapes.

[0032] Preferably, in step 2.1, according to the radius R0 of the game character, an obstacle expansion algorithm is used to expand the static obstacle Static_obs(i) to obtain a static obstacle expansion body E Static_obs(i), which is specifically:

[0033] Step 2.1.1, simplify the static obstacle Static_obs(i) into an obstacle polygon;

[0034] Step 2.1.2, determine whether the obstacle polygon is a convex polygon. If so, directly perform obstacle expansion to obtain a static obstacle expansion body E Static_obs(i); if not, it indicates that the obstacle polygon is a concave polygon. The concave polygon is convexly decomposed into multiple convex polygons. For each convex polygon, obstacle expansion is performed independently to obtain multiple static obstacle expansion bodies, and then the multiple static obstacle expansion bodies are merged to obtain the final static obstacle expansion body E Static_obs(i).

[0035] Preferably, for convex polygons, the following method is used to perform obstacle expansion:

[0036] Step 2.1.2.1, assume that the convex polygon is an n-gon with n vertices, and the n vertices are arranged clockwise and are represented as: B1, B2, ..., B n ; Therefore, arranged clockwise, the obtained n edge vectors are expressed as follows:

[0037] The game character is a circle with a radius of R0; the inscribed hexagon of the game character is obtained; the six vertices of the inscribed hexagon are arranged clockwise, and are expressed as: K1, K2, ..., K6; therefore, the six edge vectors obtained by arranging them clockwise are expressed as:

[0038] 6 edge vectors The direction and length of remain unchanged, and the six edge vectors are moved so that the starting points of the six edge vectors converge to a point K0, thereby obtaining a hexagonal expansion body EK, which has a center point K0 and six edge vectors arranged in a clockwise direction, respectively:

[0039] Step 2.1.2.2, first the edge vector To expand, the expansion method is:

[0040] S1.1) Edge vector The starting point is point B1; the hexagonal expansion body EK is moved parallel to make the center point K0 of the hexagonal expansion body EK coincide with point B1;

[0041] Point B1 is the edge vector The end point, the opposite side vector Extend it, and the extension point is represented as B"1, thereby obtaining the first reference line vector

[0042] Point B1 is the edge vector The starting point of the edge vector As the second reference line vector;

[0043] S1.2) Six edge vectors of the hexagonal expansion body EK In the above example, the extreme value is greater than the first reference line vector and is less than or equal to the second reference line vector The edge vector set, assuming that the edge vector set has a total of f edge vectors, the f edge vectors are sorted clockwise, and are expressed as follows: Among them, g1,g2,...,gf∈[1,2,...,6];

[0044] Translate edge vector Make the edge vector The starting point K0 coincides with point B1; then, the edge vector is translated make The starting point K0 and the edge vector The end point K g1 Coincident, and so on, until the opposite side vector is completed The translation operation makes the edge vector End to end;

[0045] Click K gf Rename it to point C1;

[0046] S1.3) Starting from point C1, draw the edge vector Make the edge vector With edge vector Parallel and equal in length, point C2 is the opposite side vector The end point after expansion is performed;

[0047] This completes the side vector The end point is point C2; the edge vector from point B1 to point C2 is the edge vector after extension;

[0048] Step 2.1.2.3, opposite side vector To expand, the expansion method is:

[0049] S2.1) moving the hexagonal expansion body EK in parallel so that the center point K0 of the hexagonal expansion body EK coincides with the point C2;

[0050] S2.2) Point C2 is the edge vector The end point, the opposite side vector Extend it, and the extension point is represented as C"2, thereby obtaining the first reference line vector

[0051] Take point C2 as the starting point and make the edge vector The parallel side vector is used as the second reference line vector;

[0052] S2.3) The six edge vectors of the hexagonal expansion EK In the above example, the extreme value is greater than the first reference line vector and is less than or equal to the set of edge vectors between the second reference line vectors, so that the edge vectors of the obtained edge vector set are sorted clockwise and connected end to end, the starting point after the connection coincides with point C2, and the end point after the connection is named point C3;

[0053] S2.4) Starting from point C3, draw an edge vector so that the edge vector With edge vector Parallel and equal in length, point C4 is the opposite side vector The end point after expansion is performed;

[0054] This completes the side vector The end point is point C4; the edge vector from point C2 to point C4 is the edge vector after expansion;

[0055] And so on until the opposite side vector To expand;

[0056] Step 2.1.2.4 finally forms the static obstacle expansion body E Static_obs(i).

[0057] The collision detection method for character movement in the game provided by the present invention has the following advantages:

[0058] It is a method suitable for games, which detects collisions between characters and obstacles and determines the direction of character movement after a collision. The solution is relatively simple, meets customization needs, and takes efficiency into consideration. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 A schematic diagram of the flow of a collision detection method for character movement in a game provided by the present invention;

[0060] Figure 2 A schematic diagram of a collision detection method for character movement in a game provided by the present invention;

[0061] Figure 3 A schematic diagram of the convex solution of a concave polygon into multiple convex polygons provided by the present invention;

[0062] Figure 4 A schematic diagram of the principle of obstacle expansion of a convex polygon provided by the present invention;

[0063] Figure 5 A schematic diagram of a hexagon inscribed in a circle provided by the present invention;

[0064] Figure 6 This is a schematic diagram of the deformed arrangement of the six side vectors of the inscribed hexagon provided by the present invention;

[0065] Figure 7 A schematic diagram of an obstacle provided by the present invention before expansion;

[0066] Figure 8 This is a schematic diagram of the obstacle after expansion provided by the present invention. DETAILED DESCRIPTION

[0067] In order to make the technical problems, technical solutions and beneficial effects solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0068] The invention provides a lightweight method suitable for games, for detecting collisions between characters and obstacles and for determining the moving direction of the characters after the collision occurs.

[0069] refer to Figure 1 The present invention provides a method for detecting a collision of a character moving in a game, comprising the following steps:

[0070] Step 1: The map in the game scene is in grid form and has multiple grids;

[0071] Step 2: Display multiple static obstacles in the map. For any static obstacle, represented as static obstacle Static_obs(i), perform the following operations:

[0072] Step 2.1, the radius of the game character is R0; according to the radius of the game character R0, the obstacle expansion algorithm is used to expand the static obstacle Static_obs(i) to obtain the static obstacle expansion body E Static_obs(i);

[0073] Step 2.2, for each grid Grid covered by the static obstacle expansion body E Static_obs(i), write the grid index, which is: the ID of the static obstacle S_obs(i);

[0074] Step 3: During the game, for dynamic obstacles, represented by dynamic obstacle Move_obs(j), the following operations are performed in real time:

[0075] Step 3.1, using the obstacle expansion algorithm in advance to expand the dynamic obstacle Move_obs(j) to obtain the dynamic obstacle expansion body E Move_obs(j) and save it;

[0076] Step 3.2, assuming that the current position of the dynamic obstacle Move_obs(j) is u1, read the dynamic obstacle expansion body E Move_obs(j), and according to the current posture of the dynamic obstacle Move_obs(j), display the dynamic obstacle expansion body E Move_obs(j) at the current position u1 according to the current posture;

[0077] For each grid Grid covered by the dynamic obstacle expansion body E Move_obs(j), the grid index is written, and the grid index is: the ID of the dynamic obstacle Move_obs(j);

[0078] Step 3.3, when the dynamic obstacle Move_obs(j) moves, if it moves from position u1 to position u2, first clear the grid index written in step 3.2;

[0079] Then read the dynamic obstacle expansion body E Move_obs(j), and display the dynamic obstacle expansion body E Move_obs(j) at the current position u2 according to the current posture of the dynamic obstacle Move_obs(j);

[0080] For each grid Grid covered by the dynamic obstacle expansion body E Move_obs(j), the grid index is written, and the grid index is: the ID of the dynamic obstacle Move_obs(j);

[0081] This cycle is repeated continuously to realize the dynamic display of the dynamic obstacle Move_obs(j);

[0082] Step 4: During the game, when the game character role needs to move, assume that the current position of the center of mass of the game character role is point A, and its coordinates are (x A ,y A ), the game character radius is R0, and its velocity vector is Use the following method to determine the role of the game character according to the velocity vector The moving collision point and the moving direction after collision:

[0083] Step 4.1, pre-set the search range radius r;

[0084] Step 4.2, simplify the game character role into a point, and the location of the point is the location of the centroid of the game character role;

[0085] Starting from the current position A, according to the velocity vector Search for a motion path of length r in the direction of the motion path; determine whether there is a grid with a grid index written in the grid that the motion path passes through; if not, it means that the game character role is moving according to the velocity vector When moving to the next position, it will not collide with the static obstacle Static_obs(i) and the dynamic obstacle Move_obs(j);

[0086] If yes, then obtain all grid indexes in the grid Grid that the motion path passes through, and then obtain the IDs of all static obstacles S_obs(i) and / or the IDs of dynamic obstacles Move_obs(j). At this time, the obtained IDs of static obstacles S_obs(i) and / or the IDs of dynamic obstacles Move_obs(j) are collectively referred to as obstacle IDs;

[0087] Then proceed to step 4.3;

[0088] Step 4.3, for each obstacle ID obtained in step 4.2, the obstacle expansion body is displayed in the map;

[0089] For each obstacle expansion body, the following method is used to calculate the distance L: the intersection of the motion path and the obstacle expansion body is the possible collision point, and the distance between the current center of mass position of the game character role and the possible collision point is calculated as the distance L;

[0090] Then, the distance L corresponding to each obstacle expansion body is compared to obtain the obstacle expansion body corresponding to the minimum distance L, which is expressed as: obstacle expansion body E_obs(min);

[0091] Therefore, the intersection of the motion path and the obstacle expansion body E_obs(min) is the final collision point, expressed as: collision point dote(last);

[0092] refer to Figure 2 , the obstacle expansion body E_obs(min) is the normal at the collision point dote(last), and the line connecting the current center of mass position of the game character role and the collision point dote(last) is the movement path of the game character role, which is located on one side of the normal; when the game character role moves to the collision point dote(last), it moves along the outer boundary of the obstacle expansion body E_obs(min) on the other side of the normal, which is the detected movement direction after the collision; the principle here is: the game rules require that the character cannot overlap with the obstacle and can only walk along the edge of the obstacle, that is, walk close to the edge, thereby determining the movement direction after the collision.

[0093] At this point, the collision point and the direction of movement after the collision are determined.

[0094] In the present invention, the static obstacle expansion body E Static_obs(i) and the dynamic obstacle expansion body EMove_obs(j) are both obstacle polygonal shapes.

[0095] In the present invention, the expansion algorithm for the static obstacle Static_obs(i) is the same as the expansion algorithm for the dynamic obstacle Move_obs(j). The following is a detailed introduction of the process of expanding the static obstacle Static_obs(i) as an example:

[0096] In step 2.1, according to the game character radius R0, the obstacle expansion algorithm is used to expand the static obstacle Static_obs(i) to obtain the static obstacle expansion body E Static_obs(i), which is specifically:

[0097] Step 2.1.1, simplify the static obstacle Static_obs(i) into an obstacle polygon;

[0098] Step 2.1.2, determine whether the obstacle polygon is a convex polygon. If so, directly perform obstacle expansion to obtain a static obstacle expansion body E Static_obs(i); if not, it indicates that the obstacle polygon is a concave polygon. The concave polygon is convexly decomposed into multiple convex polygons. For each convex polygon, obstacle expansion is performed independently to obtain multiple static obstacle expansion bodies, and then the multiple static obstacle expansion bodies are merged to obtain the final static obstacle expansion body E Static_obs(i).

[0099] like Figure 4 As shown, 1 represents the game character, which is a circle; 2 represents the hexagon inscribed in the circle of the game character; 3 represents the simplified point of the game character; 4 represents the unexpanded obstacle; and 5 represents the expanded body of the obstacle.

[0100] Among them, for convex polygons, the following method is used to expand obstacles:

[0101] Step 2.1.2.1, assume that the convex polygon is an n-gon with n vertices, and the n vertices are arranged clockwise and are represented as: B1, B2, ..., B n ; Therefore, arranged clockwise, the obtained n edge vectors are expressed as follows: like Figure 7 As shown, when the convex polygon is a rectangle, it has four vertices, namely: B1, B2, B3, and B4.

[0102] The game character is a circle with a radius of R0; the inscribed hexagon of the game character is obtained; the six vertices of the inscribed hexagon are arranged clockwise, and are expressed as: K1, K2, ..., K6; therefore, the six edge vectors obtained by arranging them clockwise are expressed as: refer to Figure 5 , which are the six side vectors of the hexagon inscribed in the circle.

[0103] 6 edge vectors The direction and length of remain unchanged, and the six edge vectors are moved so that the starting points of the six edge vectors converge to a point K0, thereby obtaining a hexagonal expansion body EK, which has a center point K0 and six edge vectors arranged in a clockwise direction, respectively: refer to Figure 6 , which is the hexagonal expansion body EK.

[0104] Step 2.1.2.2, reference Figure 8 , first the side vector To expand, the expansion method is:

[0105] S1.1) Edge vector The starting point is point B1; the hexagonal expansion body EK is moved parallel to make the center point K0 of the hexagonal expansion body EK coincide with point B1;

[0106] Point B1 is the edge vector The end point, the opposite side vector Extend it, and the extension point is represented as B"1, thereby obtaining the first reference line vector

[0107] Point B1 is the edge vector The starting point of the edge vector As the second reference line vector;

[0108] S1.2) Six edge vectors of the hexagonal expansion body EK In the above example, the extreme value is greater than the first reference line vector and is less than or equal to the second reference line vector The edge vector set, assuming that the edge vector set has a total of f edge vectors, the f edge vectors are sorted clockwise, and are expressed as follows: Among them, g1,g2,...,gf∈[1,2,...,6];

[0109] Translate edge vector Make the edge vector The starting point K0 coincides with point B1; then, the edge vector is translated make The starting point K0 and the edge vector The end point Kg1 Coincident, and so on, until the opposite side vector is completed The translation operation makes the edge vector End to end;

[0110] Click K gf Rename it to point C1;

[0111] In this step, for Figure 8 , the extreme value is greater than the first reference line vector and is less than or equal to the second reference line vector There are two edge vectors in the edge vector set, namely: edge vector and edge vector After the edge vectors are sorted clockwise, they are: and edge vector

[0112] Edge Vector and edge vector The beginning and the end are connected, the starting point coincides with point B1, and the end point is point C1.

[0113] S1.3) Starting from point C1, draw the edge vector Make the edge vector With edge vector Parallel and equal in length, point C2 is the opposite side vector The end point after expansion is performed;

[0114] This completes the side vector The end point is point C2; the edge vector from point B1 to point C2 is the edge vector after expansion;

[0115] Step 2.1.2.3, opposite side vector To expand, the expansion method is:

[0116] S2.1) moving the hexagonal expansion body EK in parallel so that the center point K0 of the hexagonal expansion body EK coincides with the point C2;

[0117] S2.2) Point C2 is the edge vector The end point, the opposite side vector Extend it, and the extension point is represented as C"2, thereby obtaining the first reference line vector

[0118] Take point C2 as the starting point and make the edge vector The parallel side vector is used as the second reference line vector;

[0119] S2.3) The six edge vectors of the hexagonal expansion EK In the above example, the extreme value is greater than the first reference line vector and is less than or equal to the set of edge vectors between the second reference line vectors, so that the edge vectors of the obtained edge vector set are sorted clockwise and connected end to end, the starting point after the connection coincides with point C2, and the end point after the connection is named point C3;

[0120] In this step, for Figure 8 , the extreme value is greater than the first reference line vector And in the set of edge vectors that are less than or equal to the second reference line vector, there is only one edge vector, namely, the edge vector

[0121] S2.4) Draw the edge vector starting from point C3 Make the edge vector With edge vector Parallel and equal in length, point C4 is the opposite side vector The end point after expansion is performed;

[0122] This completes the side vector The end point is point C4; the edge vector from point C2 to point C4 is the edge vector after expansion;

[0123] And so on until the opposite side vector To expand;

[0124] Step 2.1.2.4 finally forms the static obstacle expansion body E Static_obs(i).

[0125] The principle of the present invention is introduced below:

[0126] The present invention uses a hexagon inscribed in a circle with the same radius as the character as an expansion body to expand the obstacle polygon to obtain the obstacle expansion body. Then, the relationship between the character and the obstacle is simplified to the relationship between a point and the obstacle expansion body (which is a polygon).

[0127] For static obstacles, pre-calculate the polygonal data of the obstacle expansion body and write the grid index to the grid covered by its area. Pre-calculating and writing the polygonal data of the obstacle expansion body of static obstacles can improve the performance of subsequent collision detection.

[0128] For dynamic obstacles, during the game, the grids covered by the obstacle expansion are calculated in real time, and the grid index is refreshed, that is, the grid index of the grid covered by the old position is deleted, and the grid index of the grid covered by the new position is written. In this step, the shape of the obstacle expansion of the dynamic obstacle is calculated and saved in advance; then, during the game, only its position needs to be calculated in real time, thereby improving performance.

[0129] Therefore, during the game, the grid index covered by the path formed by the character's position and speed direction is obtained, and then the corresponding obstacle ID is retrieved. The position vector combining the character's center position and speed is used to calculate with each obstacle expansion body retrieved to obtain the collision point with each obstacle expansion body; the closest collision point is the detected collision point. Combined with the normal of the collision point position, the direction of the character's movement after the collision can be determined.

[0130] When calculating the expansion volume of an obstacle, if the obstacle is a concave polygon, first use a convex solution to convert it into multiple convex polygons, and then expand it. The specific method is: you can write a tool to arrange the points of the concave polygon and manually divide it into multiple convex polygons. You can also calculate automatically, and complete the convex solution according to the process of triangulating the concave polygon and then synthesizing the triangles into convex polygons. Figure 3 As shown, the hexagon surrounded by vertices W1-W2-W3-W4-W5-W6-W1 is a concave polygon (a concave polygon is defined as having an internal angle greater than or equal to 90 degrees, that is, a concave polygon), and its convex solution is two convex polygons, namely: the first convex polygon W1-W2-W3-W6 and the second convex polygon W6-W3-W4-W5. Then, the first convex polygon and the second convex polygon are expanded respectively. After the first convex polygon is expanded, the expanded body surrounded by W18-W19-W20-W21-W22-W23-W24-W25-W26-W27 is obtained; after the second convex polygon is expanded, the expanded body surrounded by W8-W9-W10-W21-W22-W13-W14-W15-W16-W7 is obtained.

[0131] Therefore, the present invention converts the relationship between the character and the obstacle into the relationship between a point and a polygon. Static obstacles and dynamic obstacles are processed separately. The collision detection efficiency is improved by pre-calculating the expansion of static obstacles and the expansion of dynamic obstacles, and refreshing the grid covered by the expansion of dynamic obstacles during the game.

[0132] The collision detection method for character movement in a game provided by the present invention has the following advantages:

[0133] It is a method suitable for games, which detects collisions between characters and obstacles and determines the direction of character movement after a collision. The solution is relatively simple and efficient.

[0134] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be considered as the scope of protection of the present invention.

Claims

1. A collision detection method for character movement in a game, characterized in that: The following steps are involved: Step 1: The map in the game scene is in grid form and has multiple grids; Step 2: Display multiple static obstacles in the map. For any static obstacle, represented as static obstacle Static_obs(i), perform the following operations: Step 2.1, the radius of the game character is R0; according to the radius of the game character R0, the obstacle expansion algorithm is used to expand the static obstacle Static_obs(i) to obtain the static obstacle expansion body E Static_obs(i); Step 2.2, for each grid Grid covered by the static obstacle expansion body E Static_obs(i), write the grid index, which is: the ID of the static obstacle S_obs(i); Step 3: During the game, for dynamic obstacles, represented by dynamic obstacle Move_obs(j), the following operations are performed in real time: Step 3.1, using the obstacle expansion algorithm in advance to expand the dynamic obstacle Move_obs(j) to obtain the dynamic obstacle expansion body E Move_obs(j) and save it; Step 3.2, assuming that the current position of the dynamic obstacle Move_obs(j) is u1, read the dynamic obstacle expansion body EMove_obs(j), and according to the current posture of the dynamic obstacle Move_obs(j), display the dynamic obstacle expansion body E Move_obs(j) at the current position u1 according to the current posture; For each grid Grid covered by the dynamic obstacle expansion body E Move_obs(j), the grid index is written, and the grid index is: the ID of the dynamic obstacle Move_obs(j); Step 3.3, when the dynamic obstacle Move_obs(j) moves, if it moves from position u1 to position u2, first clear the grid index written in step 3.2; Then read the dynamic obstacle expansion body E Move_obs(j), and display the dynamic obstacle expansion body E Move_obs(j) at the current position u2 according to the current posture of the dynamic obstacle Move_obs(j); For each grid Grid covered by the dynamic obstacle expansion body E Move_obs(j), the grid index is written, and the grid index is: the ID of the dynamic obstacle Move_obs(j); This cycle is repeated continuously to realize the dynamic display of the dynamic obstacle Move_obs(j); Step 4: During the game, when the game character role needs to move, assume that the current position of the center of mass of the game character role is point A, and its coordinates are (x A ,y A ), the game character radius is R0, and its velocity vector is Use the following method to determine the role of the game character according to the velocity vector The moving collision point and the moving direction after collision: Step 4.1, pre-set the search range radius r; Step 4.2, simplify the game character role into a point, and the location of the point is the location of the centroid of the game character role; Taking the current position A as the starting point, according to the velocity vector Search for a motion path of length r in the direction of the motion path; determine whether there is a grid with a grid index written in the grid that the motion path passes through; if not, it means that the game character role is moving according to the velocity vector When moving to the next position, it will not collide with the static obstacle Static_obs(i) and the dynamic obstacle Move_obs(j); If yes, then obtain all grid indexes in the grid Grid that the motion path passes through, and then obtain the IDs of all static obstacles S_obs(i) and / or the IDs of dynamic obstacles Move_obs(j). At this time, the obtained IDs of static obstacles S_obs(i) and / or the IDs of dynamic obstacles Move_obs(j) are collectively referred to as obstacle IDs; Then proceed to step 4.3; Step 4.3, for each obstacle ID obtained in step 4.2, the obstacle expansion body is displayed in the map; For each obstacle expansion body, the following method is used to calculate the distance L: the intersection of the motion path and the obstacle expansion body is the possible collision point, and the distance between the current center of mass position of the game character role and the possible collision point is calculated as the distance L; Then, the distance L corresponding to each obstacle expansion body is compared to obtain the obstacle expansion body corresponding to the minimum distance L, which is expressed as: obstacle expansion body E_obs(min); Therefore, the intersection of the motion path and the obstacle expansion body E_obs(min) is the final collision point, expressed as: collision point dote(last); The obstacle expansion body E_obs(min) forms a normal at the collision point dote(last). The line connecting the current center of mass of the game character role and the collision point dote(last) is the movement path of the game character role, which is located on one side of the normal. When the game character role moves to the collision point dote(last), it moves along the outer boundary of the obstacle expansion body E_obs(min) on the other side of the normal, which is the movement direction after the detected collision. So far, the collision point and the direction of movement after the collision are determined; Among them, in step 2.1, according to the game character radius R0, the obstacle expansion algorithm is used to expand the static obstacle Static_obs(i) to obtain the static obstacle expansion body E Static_obs(i), which is specifically: Step 2.1.1, simplify the static obstacle Static_obs(i) into an obstacle polygon; Step 2.1.2, determine whether the obstacle polygon is a convex polygon. If so, directly perform obstacle expansion to obtain a static obstacle expansion body E Static_obs(i); if not, it indicates that the obstacle polygon is a concave polygon. The concave polygon is convexly decomposed into multiple convex polygons. For each convex polygon, obstacle expansion is performed independently to obtain multiple static obstacle expansion bodies, and then the multiple static obstacle expansion bodies are merged to obtain the final static obstacle expansion body E Static_obs(i); Among them, for convex polygons, the following method is used to expand obstacles: Step 2.1.2.1, assume that the convex polygon is an n-gon with n vertices, and the n vertices are arranged clockwise and are represented as: B1, B2, ..., B n ; Therefore, arranged clockwise, the obtained n edge vectors are expressed as follows: The game character is a circle with a radius of R0; the inscribed hexagon of the game character is obtained; the six vertices of the inscribed hexagon are arranged clockwise, and are expressed as: K1, K2, ..., K6; therefore, the six edge vectors obtained by arranging them clockwise are expressed as: 6 edge vectors The direction and length of remain unchanged, and the six edge vectors are moved so that the starting points of the six edge vectors converge to a point K0, thereby obtaining a hexagonal expansion body EK, which has a center point K0 and six edge vectors arranged in a clockwise direction, respectively: Step 2.1.2.2, first the edge vector To expand, the expansion method is: S1.1) Edge vector The starting point is point B1; the hexagonal expansion body EK is moved parallel to make the center point K0 of the hexagonal expansion body EK coincide with point B1; Point B1 is the edge vector The end point, the opposite side vector Extend it, and the extension point is represented as B"1, thereby obtaining the first reference line vector Point B1 is the edge vector The starting point of the edge vector As the second reference line vector; S1.2) Six edge vectors of the hexagonal expansion body EK In the above example, the extreme value is greater than the first reference line vector and is less than or equal to the second reference line vector The edge vector set, assuming that the edge vector set has a total of f edge vectors, the f edge vectors are sorted clockwise, and are expressed as follows: Among them, g1,g2,...,gf∈[1,2,...,6]; Translate edge vector Make the edge vector The starting point K0 coincides with point B1; then, the edge vector is translated make The starting point K0 and the edge vector The end point K g1 Coincident, and so on, until the opposite side vector is completed The translation operation makes the edge vector End to end; Click K gf Rename it to point C1; S1.3) Starting from point C1, draw the edge vector Make the edge vector With edge vector Parallel and equal in length, point C2 is the opposite side vector The end point after expansion is performed; This completes the side vector The end point is point C2; the edge vector from point B1 to point C2 is the edge vector after expansion; Step 2.1.2.3, opposite side vector To expand, the expansion method is: S2.1) moving the hexagonal expansion body EK in parallel so that the center point K0 of the hexagonal expansion body EK coincides with the point C2; S2.2) Point C2 is the edge vector The end point, the opposite side vector Extend it, and the extension point is represented as C"2, thereby obtaining the first reference line vector Take point C2 as the starting point and make the edge vector The parallel side vector is used as the second reference line vector; S2.3) The six edge vectors of the hexagonal expansion EK In the above example, the extreme value is greater than the first reference line vector and is less than or equal to the set of edge vectors between the second reference line vectors, so that the edge vectors of the obtained edge vector set are sorted clockwise and connected end to end, the starting point after the connection coincides with point C2, and the end point after the connection is named point C3; S2.4) Draw the edge vector starting from point C3 Make the edge vector With edge vector Parallel and equal in length, point C4 is the opposite side vector The end point after expansion is performed; This completes the side vector The end point is point C4; the edge vector from point C2 to point C4 is the edge vector after expansion; And so on until the opposite side vector To expand; Step 2.1.2.4 finally forms the static obstacle expansion body E Static_obs(i).

2. The method for detecting collision of a character moving in a game according to claim 1, characterized in that: The static obstacle expansion body E Static_obs(i) and the dynamic obstacle expansion body E Move_obs(j) are both obstacle polygon shapes.