CN114949858A - Collision detection method for character movement in game - Google Patents

Collision detection method for character movement in game Download PDF

Info

Publication number
CN114949858A
CN114949858A CN202210633831.7A CN202210633831A CN114949858A CN 114949858 A CN114949858 A CN 114949858A CN 202210633831 A CN202210633831 A CN 202210633831A CN 114949858 A CN114949858 A CN 114949858A
Authority
CN
China
Prior art keywords
point
obstacle
obs
vector
static
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210633831.7A
Other languages
Chinese (zh)
Inventor
陈永达
毕林
许艺清
李东君
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xiamen Feixin Network Technology Co ltd
Original Assignee
Xiamen Feixin Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xiamen Feixin Network Technology Co ltd filed Critical Xiamen Feixin Network Technology Co ltd
Priority to CN202210633831.7A priority Critical patent/CN114949858A/en
Publication of CN114949858A publication Critical patent/CN114949858A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/55Controlling game characters or game objects based on the game progress
    • A63F13/57Simulating properties, behaviour or motion of objects in the game world, e.g. computing tyre load in a car race game
    • A63F13/577Simulating properties, behaviour or motion of objects in the game world, e.g. computing tyre load in a car race game using determination of contact between game characters or objects, e.g. to avoid collision between virtual racing cars

Abstract

The invention provides a collision detection method for character movement in a game, which comprises the following steps: according to the radius of the game role, adopting an obstacle expansion algorithm to expand the static obstacle to obtain a static obstacle expansion body; writing each grid covered by the grid into a grid index; expanding the dynamic barrier to obtain a dynamic barrier expansion body, and refreshing the grid index of each grid covered by the dynamic barrier expansion body in the game process; when the game character needs to move, the obstacle with collision is detected according to the position and the velocity vector of the game character, and the collision point and the moving direction after collision are calculated. The invention is a method for detecting collision between a role and a barrier and determining the movement direction of the color after collision, which is suitable for games, has a simple scheme and simultaneously considers efficiency.

Description

Collision detection method for character movement in game
Technical Field
The invention relates to a collision detection method, in particular to a collision detection method for character movement in a game.
Background
In many games, a character moves and there are many obstacles, and therefore, it is necessary to detect a collision between the character and an obstacle and to determine a movement direction of the character after the collision.
In conventional approaches, the angular movement orientation is confirmed after a collision using a game engine to provide the result of the physical collision. But has the following problems: the calculated amount is large, the game engine is deeply bound, the engineering is huge and difficult to modify, and the customized requirements are not met.
Disclosure of Invention
Aiming at the defects in the prior art, the invention provides a collision detection method for character movement in a game, which can effectively solve the problems.
The technical scheme adopted by the invention is as follows:
the invention provides a collision detection method for character movement in a game, which comprises the following steps:
step 1, a map in a game scene is in a Grid form and is provided with a plurality of Grid grids;
step 2, displaying a plurality of static obstacles in a map; for any static obstacle, it is expressed as: static obstacles Static _ obs (i), the following operations are performed:
step 2.1, the radius of the game role is R 0 (ii) a According to the radius R of the game role 0 Expanding a Static obstacle Static _ obs (i) by adopting an obstacle expansion algorithm to obtain a Static obstacle expansion body E Static _ obs (i);
step 2.2, writing a Grid index into each Grid covered by the Static obstacle expansion body E Static _ obs (i), wherein the Grid index is as follows: ID of static obstacle S _ obs (i);
and 3, in the game process, regarding the dynamic obstacle, namely the dynamic obstacle Move _ obs (j), performing the following operations in real time:
step 3.1, expanding the dynamic obstacle Move _ obs (j) by adopting an obstacle expansion algorithm in advance to obtain a dynamic obstacle expansion body E Move _ obs (j), and storing;
step 3.2, assuming that the current position of the dynamic obstacle Move _ obs (j) is u1, reading a dynamic obstacle expansion body E Move _ obs (j), and displaying the dynamic obstacle expansion body E Move _ obs (j) to the current position u1 according to the current posture of the dynamic obstacle Move _ obs (j);
for each Grid covered by the dynamic obstacle expander E Move _ obs (j), writing a Grid index, where the Grid index is: ID of dynamic obstacle Move _ obs (j);
step 3.3, when the dynamic obstacle Move _ obs (j) moves, if the dynamic obstacle moves from the position u1 to the position u2, the grid index written in the step 3.2 is cleared first;
reading the dynamic obstacle expansion body E Move _ obs (j), and displaying the dynamic obstacle expansion body E Move _ obs (j) to the current position u2 according to the current posture of the dynamic obstacle Move _ obs (j);
for each Grid covered by the dynamic obstacle expander E Move _ obs (j), writing a Grid index, where the Grid index is: ID of dynamic obstacle Move _ obs (j);
the above is circulated continuously, so as to realize the dynamic display of the dynamic barrier Move _ obs (j);
step 4, in the process of game, when the role needs to move, the centroid of the role is assumed to be located at the point A, and the coordinate is (x) A ,y A ) The radius of the game character is R 0 The velocity vector of which is
Figure BDA0003679789080000021
Determining a role velocity vector in accordance with a game character using the following method
Figure BDA0003679789080000022
Moving collision point and post-collision moving direction:
step 4.1, presetting a search range radius r;
step 4.2, simplifying the role of the game into points, wherein the positions of the points are the positions of the centroids of the role of the game;
starting from the current position A point according to the velocity vector
Figure BDA0003679789080000031
Searching for a motion path of length r; judging whether a Grid written with a Grid index exists in the Grid grids passed by the motion path; if not, it indicates that the role of the game is according to the velocity vector
Figure BDA0003679789080000032
When the mobile terminal moves to the next position, the mobile terminal does not collide with a Static obstacle Static _ obs (i) and a dynamic obstacle Move _ obs (j);
if yes, acquiring all Grid indexes in Grid grids passed by the motion path, and further acquiring IDs of all static obstacles S _ obs (i) and/or IDs of all dynamic obstacles Move _ obs (j), wherein the obtained IDs of the static obstacles S _ obs (i) and/or IDs of the dynamic obstacles Move _ obs (j) are collectively called as obstacle IDs at this time;
then step 4.3 is executed;
step 4.3, displaying an obstacle expansion body in a map for the obstacle corresponding to each obstacle ID obtained in the step 4.2;
for each obstacle expander, the distance L is calculated using the following method: calculating the distance between the current centroid position of the role of the game and the possible collision point as a distance L, wherein the intersection point of the motion path and the obstacle expansion body is the possible collision point;
then, the distance L corresponding to each obstacle expansion body is compared to obtain the obstacle expansion body corresponding to the minimum value of the distance L, and the distance L is expressed as: an obstacle expander E _ obs (min);
therefore, the intersection point of the movement path and the obstacle expanding body E _ obs (min), which is the finally determined collision point, is represented as: collision point dot (last);
the barrier expansion body E _ obs (min) is used as a normal line at the position of a collision point dot (last), and a connecting line between the current centroid position of the game role and the collision point dot (last) is a motion path of the game role and is positioned on one side of the normal line; when the role moves to the collision point dot (last), the outer boundary of the obstacle expander E _ obs (min) on the other side of the normal moves, namely the detected moving direction after the collision;
the collision point and the direction of movement after the collision are determined so far.
Preferably, the Static obstacle-extension body E Static _ obs (i) and the dynamic obstacle-extension body EMove _ obs (j), both of which are in the shape of an obstacle polygon.
Preferably, in step 2.1, the radius R of the game character is determined according to 0 Expanding the Static obstacle Static _ obs (i) by adopting an obstacle expansion algorithm to obtain a Static obstacle expansion body E Static _ obs (i), which specifically comprises the following steps:
step 2.1.1, simplifying a Static obstacle Static _ obs (i) into an obstacle polygon;
step 2.1.2, judging whether the barrier polygon is a convex polygon, if so, directly expanding the barrier to obtain a Static barrier expansion body E Static _ obs (i); if not, the obstacle polygon is a concave polygon, the concave polygon is convexly solved into a plurality of convex polygons, obstacle expansion is independently performed on each convex polygon, so that a plurality of Static obstacle expansion bodies are obtained, and then the plurality of Static obstacle expansion bodies are combined to obtain a final Static obstacle expansion body E Static _ obs (i).
Preferably, for convex polygons, the obstacle expansion is performed in the following manner:
step 2.1.2.1, assuming that the convex polygon is an n-polygon with n vertices, the n vertices are arranged clockwise, and are sequentially represented as: b is 1 ,B 2 ,...,B n (ii) a Therefore, in clockwise arrangement, the resulting n-edge vectors are sequentially represented as:
Figure BDA0003679789080000041
the game role is radius R 0 The circle of (a); obtaining a circle inscribed hexagon of the game role; the 6 vertexes of the circle inscribed hexagon are arranged clockwise, and are sequentially expressed as follows: k is 1 ,K 2 ,...,K 6 (ii) a Therefore, in clockwise arrangement, the resulting 6-edge vectors are sequentially represented as:
Figure BDA0003679789080000042
vector of 6 edges
Figure BDA0003679789080000043
The direction and length of the edge vector are kept unchanged, and the 6 edge vectors are moved to converge the starting points of the 6 edge vectors intoOne point K 0 This results in a hexagonal expansion body EK which has a center point K 0 The vectors with 6 edges are arranged in the clockwise direction and respectively are:
Figure BDA0003679789080000044
Figure BDA0003679789080000045
step 2.1.2.2, first align the edge vectors
Figure BDA0003679789080000046
And (3) expanding, wherein the expanding mode is as follows:
s1.1) edge vector
Figure BDA0003679789080000047
Is point B 1 (ii) a The hexagonal expansion body EK is moved in parallel to make the center point K of the hexagonal expansion body EK 0 And point B 1 Overlapping;
point B 1 Is an edge vector
Figure BDA0003679789080000051
End point, opposite side vector
Figure BDA0003679789080000052
Elongation is carried out, the elongation point is represented as B " 1 Thereby obtaining a first reference line vector
Figure BDA0003679789080000053
Point B 1 Is an edge vector
Figure BDA0003679789080000054
Starting point of (2), edge vector
Figure BDA0003679789080000055
As a second reference line vector;
s1.2) 6-sided vector of hexagonal expansion body EK
Figure BDA0003679789080000056
Wherein the extreme value is identified as being greater than the first reference line vector
Figure BDA0003679789080000057
And is less than or equal to the second reference line vector
Figure BDA0003679789080000058
The set of edge vectors of (1) is set to have f edge vectors, and the f edge vectors are sorted according to a clockwise order and are sequentially represented as follows:
Figure BDA0003679789080000059
wherein g1, g2, gf e [1,2, 6 ]];
Translation edge vector
Figure BDA00036797890800000510
Make the edge vector
Figure BDA00036797890800000511
Starting point K of 0 And point B 1 Overlapping; then, the edge vector is translated
Figure BDA00036797890800000512
Make it
Figure BDA00036797890800000513
Starting point K of 0 And the edge vector
Figure BDA00036797890800000514
End point K of g1 Coincidence, and so on, until the opposite side vector is completed
Figure BDA00036797890800000515
By shifting the edge vector
Figure BDA00036797890800000516
The heads and the tails are connected;
will point K gf Renamed as point C 1
S1.3) by point C 1 As a starting point, an edge vector is drawn
Figure BDA00036797890800000517
Make the edge vector
Figure BDA00036797890800000518
And the edge vector
Figure BDA00036797890800000519
Parallel and equal length, point C 2 Is a vector of opposite edge
Figure BDA00036797890800000520
Performing an expanded end point;
this completes the opposite side vector
Figure BDA00036797890800000521
End point is point C 2 (ii) a Point B 1 To point C 2 The passed edge vector is the expanded edge vector;
step 2.1.2.3, opposite side vector
Figure BDA00036797890800000522
And (3) expanding, wherein the expanding mode is as follows:
s2.1) moving the hexagonal expansion body EK in parallel to enable the center point K of the hexagonal expansion body EK 0 And point C 2 Overlapping;
s2.2) Point C 2 Is an edge vector
Figure BDA00036797890800000523
End point, opposite side vector
Figure BDA00036797890800000524
Elongation was carried out with the elongation point denoted C " 2 Thereby obtaining a first reference line vector
Figure BDA00036797890800000525
At point C 2 As a starting point, make an edge vector
Figure BDA00036797890800000526
Parallel edge vectors as second reference line vectors;
s2.3) 6-edge vector of hexagonal expansion body EK
Figure BDA00036797890800000527
Wherein the extreme value is identified as being greater than the first reference line vector
Figure BDA00036797890800000528
And the edge vectors are less than or equal to the edge vector set between the second reference line vectors, so that all the edge vectors of the obtained edge vector set are sorted according to a clockwise direction, and after the edge vectors are connected end to end, the starting point and the point C are connected end to end 2 The end points after the superposition and the head-to-tail connection are named as points C 3
S2.4) by point C 3 As a starting point, the edge vector is drawn so that the edge vector
Figure BDA0003679789080000061
And the edge vector
Figure BDA0003679789080000062
Parallel and equal length, point C 4 Is a vector of opposite edge
Figure BDA0003679789080000063
Performing an expanded end point;
this completes the opposite side vector
Figure BDA0003679789080000064
End point is point C 4 (ii) a Point C 2 To point C 4 The passed edge vector is the expanded edge vector;
and so on until the opposite side vector
Figure BDA0003679789080000065
Carrying out expansion;
and 2.1.2.4, finally forming a Static obstacle expander E Static _ obs (i).
The collision detection method for character movement in the game provided by the invention has the following advantages:
the method is suitable for games, the roles and the barriers are subjected to collision detection, and the color movement direction after collision is determined, the scheme is simple, the customization requirements are met, and meanwhile, the efficiency is considered.
Drawings
FIG. 1 is a schematic flow chart of a collision detection method for character movement in a game according to the present invention;
FIG. 2 is a schematic diagram of a collision detection method for character movement in a game according to the present invention;
FIG. 3 is a schematic diagram of a concave polygon convexly divided into a plurality of convex polygons according to the present invention;
FIG. 4 is a schematic view of the convex polygon for obstacle expansion according to the present invention;
FIG. 5 is a schematic diagram of a circular inscribed hexagon provided by the present invention;
FIG. 6 is a schematic diagram of a circle inscribed hexagon provided by the present invention after 6 edges of the circle inscribed hexagon are arranged in a deformed manner;
FIG. 7 is a schematic representation of the barrier provided by the present invention prior to expansion;
fig. 8 is a schematic view of the barrier of the present invention after expansion.
Detailed Description
In order to make the technical problems, technical solutions and advantageous effects solved by the present invention more clearly apparent, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The invention provides a method for detecting collision between a character and an obstacle and determining the movement direction of the character after collision, which is light and suitable for games.
Referring to fig. 1, the collision detection method for character movement in a game provided by the invention comprises the following steps:
step 1, a map in a game scene is in a Grid form and is provided with a plurality of Grid grids;
step 2, displaying a plurality of static obstacles in a map; for any static obstacle, it is expressed as: static obstacles Static _ obs (i), the following operations are performed:
step 2.1, the radius of the game role is R 0 (ii) a According to the radius R of the game role 0 Expanding a Static obstacle Static _ obs (i) by adopting an obstacle expansion algorithm to obtain a Static obstacle expansion body E Static _ obs (i);
step 2.2, writing a Grid index into each Grid covered by the Static obstacle expansion body E Static _ obs (i), wherein the Grid index is as follows: ID of static obstacle S _ obs (i);
and 3, in the game process, regarding the dynamic obstacle, which is expressed as a dynamic obstacle Move _ obs (j), performing the following operations in real time:
step 3.1, expanding the dynamic obstacle Move _ obs (j) by adopting an obstacle expansion algorithm in advance to obtain a dynamic obstacle expansion body E Move _ obs (j), and storing;
step 3.2, assuming that the current position of the dynamic obstacle Move _ obs (j) is u1, reading a dynamic obstacle expansion body E Move _ obs (j), and displaying the dynamic obstacle expansion body E Move _ obs (j) to the current position u1 according to the current posture of the dynamic obstacle Move _ obs (j);
for each Grid covered by the dynamic obstacle expander E Move _ obs (j), writing a Grid index, where the Grid index is: ID of dynamic obstacle Move _ obs (j);
step 3.3, when the dynamic obstacle Move _ obs (j) moves, if the dynamic obstacle moves from the position u1 to the position u2, the grid index written in the step 3.2 is cleared first;
reading the dynamic obstacle expansion body E Move _ obs (j), and displaying the dynamic obstacle expansion body E Move _ obs (j) to the current position u2 according to the current posture of the dynamic obstacle Move _ obs (j);
for each Grid covered by the dynamic obstacle expander E Move _ obs (j), writing a Grid index, where the Grid index is: ID of dynamic obstacle Move _ obs (j);
the dynamic display of the dynamic barrier Move _ obs (j) is realized by continuously circulating the steps;
step 4, in the process of game, when the role needs to move, the centroid of the role is assumed to be located at the point A, and the coordinate is (x) A ,y A ) The radius of the game character is R 0 The velocity vector of which is
Figure BDA0003679789080000081
Determining a role velocity vector in accordance with a game character using the following method
Figure BDA0003679789080000082
Moving collision point and post-collision moving direction:
step 4.1, presetting a search range radius r;
step 4.2, simplifying the role of the game into points, wherein the positions of the points are the positions of the centroids of the role of the game;
starting from the current position A point according to the velocity vector
Figure BDA0003679789080000083
Searching for a motion path of length r; judging whether a Grid written with a Grid index exists in the Grid grids passed by the motion path; if not, it indicates that the role of the game is according to the velocity vector
Figure BDA0003679789080000084
When the mobile terminal moves to the next position, the mobile terminal does not collide with a Static obstacle Static _ obs (i) and a dynamic obstacle Move _ obs (j);
if yes, acquiring all Grid indexes in Grid grids passed by the motion path, and further acquiring IDs of all static obstacles S _ obs (i) and/or IDs of all dynamic obstacles Move _ obs (j), wherein the obtained IDs of the static obstacles S _ obs (i) and/or IDs of the dynamic obstacles Move _ obs (j) are collectively called as obstacle IDs at this time;
then step 4.3 is executed;
step 4.3, displaying an obstacle expansion body in a map for the obstacle corresponding to each obstacle ID obtained in the step 4.2;
for each obstacle expander, the distance L is calculated using the following method: calculating the distance between the current centroid position of the role of the game and the possible collision point as a distance L, wherein the intersection point of the motion path and the obstacle expansion body is the possible collision point;
then, the distance L corresponding to each obstacle expansion body is compared to obtain the obstacle expansion body corresponding to the minimum value of the distance L, and the distance L is expressed as: an obstacle expander E _ obs (min);
therefore, the intersection point of the motion path and the obstacle expander E _ obs (min) is the finally determined collision point, and is represented as: collision point dot (last);
referring to fig. 2, the obstacle expander E _ obs (min) makes a normal line at the collision point dot (last), and a connection line between the current centroid position of the game role and the collision point dot (last) is a motion path of the game role and is located at one side of the normal line; when the role moves to the collision point dot (last), the outer boundary of the obstacle expander E _ obs (min) on the other side of the normal moves, namely the detected moving direction after the collision; the principle here is: the game rules require that the character cannot coincide with the barrier and can only walk along the edge of the barrier, namely, walk close to the edge, so as to determine the moving direction after collision.
The collision point and the direction of movement after the collision are determined so far.
In the present invention, the Static obstacle expander E Static _ obs (i) and the dynamic obstacle expander EMove _ obs (j) are both in the shape of an obstacle polygon.
In the present invention, the Static obstacle Static _ obs (i) is expanded, which is the same as the expansion algorithm for expanding the dynamic obstacle Move _ obs (j), and the following only takes the process of expanding the Static obstacle Static _ obs (i) as an example to describe in detail:
in step 2.1, according to the radius R of the game role 0 Expanding the Static obstacle Static _ obs (i) by adopting an obstacle expansion algorithm to obtain a Static obstacle expansion body E Static _ obs (i), which specifically comprises the following steps:
step 2.1.1, simplifying a Static obstacle Static _ obs (i) into an obstacle polygon;
step 2.1.2, judging whether the barrier polygon is a convex polygon, if so, directly expanding the barrier to obtain a Static barrier expansion body E Static _ obs (i); if not, the obstacle polygon is a concave polygon, the concave polygon is convexly solved into a plurality of convex polygons, obstacle expansion is independently performed on each convex polygon, so that a plurality of Static obstacle expansion bodies are obtained, and then the plurality of Static obstacle expansion bodies are combined to obtain a final Static obstacle expansion body E Static _ obs (i).
As shown in fig. 4, 1 represents a game character and is a circle; 2 represents the circle inscribed hexagon of the game role; 3 represents a point of game character simplification; 4 represents an unexpanded obstruction; and 5 represents an obstacle expander.
Wherein, for the convex polygon, adopt following mode, carry out the barrier expansion:
step 2.1.2.1, assuming that the convex polygon is an n-polygon with n vertices, the n vertices are arranged clockwise, and are sequentially represented as: b is 1 ,B 2 ,...,B n (ii) a Therefore, in clockwise arrangement, the resulting n-edge vectors are sequentially represented as:
Figure BDA0003679789080000101
as shown in fig. 7, when the convex polygon is a rectangle, it has four vertices: b is 1 ,B 2 ,B 3 ,B 4
The game role is radius R 0 The circle of (a); obtaining a circle inscribed hexagon of the game role; the 6 vertexes of the circle inscribed hexagon are arranged clockwise, and are sequentially represented as: k 1 ,K 2 ,...,K 6 (ii) a Therefore, in clockwise arrangement, the resulting 6-edge vectors are sequentially represented as:
Figure BDA0003679789080000102
referring to fig. 5, the vector is a 6-edge vector of the inscribed hexagon.
Vector of 6 edges
Figure BDA0003679789080000103
The direction and length of the vector are kept unchanged, and the 6 edge vectors are moved to converge the starting points of the 6 edge vectors into a point K 0 This results in a hexagonal expansion body EK having a center point K 0 The vectors with 6 edges are arranged in the clockwise direction and respectively are:
Figure BDA0003679789080000104
Figure BDA0003679789080000105
referring to fig. 6, a hexagonal expansion body EK is obtained.
Step 2.1.2.2, referring to FIG. 8, first align the edge vectors
Figure BDA0003679789080000106
And (3) expanding, wherein the expanding mode is as follows:
s1.1) edge vector
Figure BDA0003679789080000107
Is point B 1 (ii) a The hexagonal expansion body EK is moved in parallel to make the center point K of the hexagonal expansion body EK 0 And point B 1 Overlapping;
point B 1 Is an edge vector
Figure BDA0003679789080000108
End point, opposite side vector
Figure BDA0003679789080000109
Elongation is carried out, the elongation point is represented as B " 1 Thereby obtaining a first reference line vector
Figure BDA00036797890800001010
Point B 1 Is an edge vector
Figure BDA00036797890800001011
Starting point of (2), edge vector
Figure BDA00036797890800001012
As a second reference line vector;
s1.2) 6-sided vector of hexagonal expansion body EK
Figure BDA0003679789080000111
Wherein the extreme value is identified as being greater than the first reference line vector
Figure BDA0003679789080000112
And is less than or equal to the second reference line vector
Figure BDA0003679789080000113
The set of edge vectors of (1) is set to have f edge vectors, and the f edge vectors are sorted according to a clockwise order and are sequentially represented as follows:
Figure BDA0003679789080000114
wherein g1, g2, gf e [1,2, 6 ]];
Translation edge vector
Figure BDA0003679789080000115
Make the edge vector
Figure BDA0003679789080000116
Starting point K of 0 And point B 1 Overlapping; then, the edge vector is translated
Figure BDA0003679789080000117
Make it
Figure BDA0003679789080000118
Starting point K of 0 And the edge vector
Figure BDA0003679789080000119
End point K of g1 Coincidence, and so on, until the opposite side vector is completed
Figure BDA00036797890800001110
By shifting the edge vector
Figure BDA00036797890800001111
The heads and the tails are connected;
will point K gf Renamed as point C 1
In this step, for FIG. 8, the extreme value is greater than the first reference line vector
Figure BDA00036797890800001112
And is less than or equal to the second reference line vector
Figure BDA00036797890800001113
The edge vector set of (2) has two edge vectors in total, which are respectively: edge vector
Figure BDA00036797890800001114
Sum edge vector
Figure BDA00036797890800001115
After the opposite side vectors are ordered clockwise, the following are: edge vector
Figure BDA00036797890800001116
Sum edge vector
Figure BDA00036797890800001117
Edge vector
Figure BDA00036797890800001118
Sum edge vector
Figure BDA00036797890800001119
End to end, starting point and point B 1 Coincidence, the end point being point C 1
S1.3) by point C 1 As a starting point, an edge vector is drawn
Figure BDA00036797890800001120
Make the edge vector
Figure BDA00036797890800001121
And the edge vector
Figure BDA00036797890800001122
Parallel and equal length, point C 2 Is a vector of opposite edge
Figure BDA00036797890800001123
Performing an expanded end point;
this completes the opposite side vector
Figure BDA00036797890800001124
End point is point C 2 (ii) a Point B 1 To point C 2 The passed edge vector is the expanded edge vector;
step 2.1.2.3, opposite side vector
Figure BDA00036797890800001125
And (3) expanding, wherein the expanding mode is as follows:
s2.1) moving the hexagonal expansion body EK in parallel to enable the center point K of the hexagonal expansion body EK 0 And point C 2 Overlapping;
s2.2) Point C 2 Is an edge vector
Figure BDA00036797890800001126
End point, opposite side vector
Figure BDA00036797890800001127
Elongation was carried out with the elongation point denoted C " 2 Thereby obtaining a first reference line vector
Figure BDA00036797890800001128
At point C 2 As a starting point, make an edge vector
Figure BDA00036797890800001129
Parallel edge vectors as second reference line vectors;
s2.3) 6-edge vector of hexagonal expansion body EK
Figure BDA00036797890800001130
Wherein the extreme value is identified as being greater than the first reference line vector
Figure BDA0003679789080000121
And the edge vectors are less than or equal to the edge vector set between the second reference line vectors, so that all the edge vectors of the obtained edge vector set are sorted according to a clockwise direction, and after the edge vectors are connected end to end, the starting point and the point C are connected end to end 2 The end points after the superposition and the head-to-tail connection are named as points C 3
In this step, for FIG. 8, the extreme value is greater than the first reference line vector
Figure BDA0003679789080000122
And only one edge vector, namely the edge vector, in the edge vector set between the vectors of the second reference lines is less than or equal to
Figure BDA0003679789080000123
S2.4) by point C 3 As a starting point, an edge vector is drawn
Figure BDA0003679789080000124
Make the edge vector
Figure BDA0003679789080000125
And the edge vector
Figure BDA0003679789080000126
Parallel and equal length, point C 4 Is a vector of opposite edge
Figure BDA0003679789080000127
Performing an expanded end point;
this completes the opposite side vector
Figure BDA0003679789080000128
End point is point C 4 (ii) a Point C 2 To point C 4 The passed edge vector is the expanded edge vector;
according to the aboveAnd so on until the opposite side vector
Figure BDA0003679789080000129
Carrying out expansion;
and 2.1.2.4, finally forming a Static obstacle expander E Static _ obs (i).
The principle of the invention is described below:
the invention uses the circle inscribed hexagon with the same radius as the role as the expansion body to expand the polygon of the obstacle, thereby obtaining the obstacle expansion body. Then, the relationship between the character and the obstacle is simplified to a relationship between the point and an obstacle extension body (which is a polygon).
For static obstacles, the polygon data of the obstacle expansion body is calculated in advance, and a grid index is written in a grid covered by the area of the polygon data. The polygon data of the obstacle expansion body of the static obstacle is calculated in advance and written in, and the performance of subsequent collision detection can be improved.
For the dynamic barrier, in the game process, calculating the grid covered by the barrier expansion body in real time, and refreshing the grid index, namely: and deleting the grid index of the grid covered by the old position, and writing the grid index of the grid covered by the new position. In this step, the shape of the obstacle expander of the dynamic obstacle is pre-calculated and stored; then, during the game progress, the position thereof is calculated only in real time, thereby improving the performance.
Therefore, in the process of game, acquiring a character position and a grid index covered by a path formed by the speed direction of the character, searching out a corresponding obstacle ID, calculating by using a position vector formed by combining the position of the center of a circle of the character and the speed and each searched obstacle expander, and obtaining a collision point with each obstacle expander; and the collision point with the nearest distance is the detected collision point. And the moving direction of the color after collision can be determined by combining the normal line of the collision point position.
When calculating the obstacle expansion body, if the obstacle is a concave polygon, the obstacle is convexly solved into a plurality of convex polygons and then expanded. The specific method comprises the following steps: the points of the concave polygon can be arranged by a writing tool, and the convex polygon is artificially divided into a plurality of convex polygons. Or automatic calculation can be carried out, and convex solution is completed according to the flow of triangularization of the concave polygon and synthesis of the convex polygon by the triangle. As shown in FIG. 3, the 6-sided polygon defined by the vertices W1-W2-W3-W4-W5-W6-W1 is a concave polygon (the concave polygon is defined as having an interior angle greater than or equal to 90 degrees, i.e. a concave polygon), and is convexly decomposed into two convex polygons, which are: a first convex polygon W1-W2-W3-W6 and a second convex polygon W6-W3-W4-W5. Then, respectively expanding the first convex polygon and the second convex polygon to obtain an expansion body enclosed by W18-W19-W20-W21-W22-W23-W24-W25-W26-W27 after the first convex polygon is expanded; and expanding the second convex polygon to obtain an expansion body surrounded by W8-W9-W10-W21-W22-W13-W14-W15-W16-W7.
Therefore, the invention converts the relationship between the character and the obstacle into the relationship between the point and the polygon. And the static obstacles and the dynamic obstacles are treated separately. By pre-calculating the expansion body of the static barrier and the expansion body of the dynamic barrier and refreshing the grids covered by the expansion body of the dynamic barrier in the game running process, the collision detection efficiency is improved.
The collision detection method for character movement in the game provided by the invention has the following advantages:
the method is suitable for games, the role and the barrier are subjected to collision detection, and the color movement direction after collision is determined, the scheme is simple, and meanwhile, the efficiency is considered.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements should also be considered within the scope of the present invention.

Claims (4)

1. A collision detection method for character movement in a game is characterized by comprising the following steps:
step 1, a map in a game scene is in a Grid form and is provided with a plurality of Grid grids;
step 2, displaying a plurality of static obstacles in a map; for any static obstacle, it is expressed as: static obstacles Static _ obs (i), the following operations are performed:
step 2.1, the radius of the game role is R 0 (ii) a According to the radius R of the game role 0 Expanding a Static obstacle Static _ obs (i) by adopting an obstacle expansion algorithm to obtain a Static obstacle expansion body E Static _ obs (i);
step 2.2, writing a Grid index into each Grid covered by the Static obstacle expander E Static _ obs (i), wherein the Grid index is as follows: ID of static obstacle S _ obs (i);
and 3, in the game process, regarding the dynamic obstacle, namely the dynamic obstacle Move _ obs (j), performing the following operations in real time:
step 3.1, expanding the dynamic obstacle Move _ obs (j) by adopting an obstacle expansion algorithm in advance to obtain a dynamic obstacle expansion body E Move _ obs (j), and storing;
step 3.2, assuming that the current position of the dynamic obstacle Move _ obs (j) is u1, reading a dynamic obstacle expansion body E Move _ obs (j), and displaying the dynamic obstacle expansion body E Move _ obs (j) to the current position u1 according to the current posture of the dynamic obstacle Move _ obs (j);
for each Grid covered by the dynamic obstacle expander E Move _ obs (j), writing a Grid index, where the Grid index is: ID of dynamic obstacle Move _ obs (j);
step 3.3, when the dynamic obstacle Move _ obs (j) moves, if the dynamic obstacle moves from the position u1 to the position u2, the grid index written in the step 3.2 is cleared first;
reading the dynamic obstacle expansion body E Move _ obs (j), and displaying the dynamic obstacle expansion body E Move _ obs (j) to the current position u2 according to the current posture of the dynamic obstacle Move _ obs (j);
for each Grid covered by the dynamic obstacle expander E Move _ obs (j), writing a Grid index, where the Grid index is: ID of dynamic obstacle Move _ obs (j);
the dynamic display of the dynamic barrier Move _ obs (j) is realized by continuously circulating the steps;
step 4, in the process of game, when the role needs to move, the centroid of the role is assumed to be located at the point A, and the coordinate is (x) A ,y A ) The radius of the game character is R 0 The velocity vector of which is
Figure FDA0003679789070000021
Determining a role velocity vector in accordance with a game character using the following method
Figure FDA0003679789070000022
Moving collision point and post-collision moving direction:
step 4.1, presetting a search range radius r;
step 4.2, simplifying the role of the game into points, wherein the positions of the points are the positions of the centroids of the role of the game;
starting from the current position A point according to the velocity vector
Figure FDA0003679789070000023
The direction of (d) searches for a motion path of length r; judging whether a Grid written with a Grid index exists in the Grid grids passed by the motion path; if not, it indicates that the role of the game is according to the velocity vector
Figure FDA0003679789070000024
When the mobile terminal moves to the next position, the mobile terminal does not collide with a Static obstacle Static _ obs (i) and a dynamic obstacle Move _ obs (j);
if yes, acquiring all Grid indexes in Grid grids passed by the motion path, and further acquiring IDs of all static obstacles S _ obs (i) and/or IDs of all dynamic obstacles Move _ obs (j), wherein the obtained IDs of the static obstacles S _ obs (i) and/or IDs of the dynamic obstacles Move _ obs (j) are collectively called as obstacle IDs at this time;
then step 4.3 is executed;
step 4.3, displaying an obstacle expansion body in a map for the obstacle corresponding to each obstacle ID obtained in the step 4.2;
for each obstacle expander, the distance L is calculated using the following method: calculating the distance between the current centroid position of the role of the game and the possible collision point as a distance L, wherein the intersection point of the motion path and the obstacle expansion body is the possible collision point;
then, the distance L corresponding to each obstacle expansion body is compared to obtain the obstacle expansion body corresponding to the minimum value of the distance L, and the distance L is expressed as: an obstacle expander E _ obs (min);
therefore, the intersection point of the motion path and the obstacle expander E _ obs (min) is the finally determined collision point, and is represented as: collision point dot (last);
the barrier expansion body E _ obs (min) is used as a normal line at the position of a collision point dot (last), and a connecting line between the current centroid position of the game role and the collision point dot (last) is a motion path of the game role and is positioned on one side of the normal line; when the role moves to the collision point dot (last), the outer boundary of the obstacle expander E _ obs (min) on the other side of the normal moves, that is, the detected moving direction after the collision;
the collision point and the direction of movement after the collision are determined so far.
2. The collision detection method of character movement in a game according to claim 1, wherein the Static obstacle-extension body E Static _ obs (i) and the dynamic obstacle-extension body E Move _ obs (j), both of which are obstacle polygon shapes.
3. The method of claim 1, wherein in step 2.1, the collision detection method is based on the radius R of the game character 0 Expanding the Static obstacle Static _ obs (i) by adopting an obstacle expansion algorithm to obtain a Static obstacle expansion body E Static _ obs (i), which specifically comprises the following steps:
step 2.1.1, simplifying a Static obstacle Static _ obs (i) into an obstacle polygon;
step 2.1.2, judging whether the barrier polygon is a convex polygon, if so, directly expanding the barrier to obtain a Static barrier expansion body E Static _ obs (i); if not, the obstacle polygon is a concave polygon, the concave polygon is convexly solved into a plurality of convex polygons, obstacle expansion is independently performed on each convex polygon, so that a plurality of Static obstacle expansion bodies are obtained, and then the plurality of Static obstacle expansion bodies are combined to obtain a final Static obstacle expansion body E Static _ obs (i).
4. The method of claim 3, wherein the convex polygon is expanded by the following method:
step 2.1.2.1, assuming that the convex polygon is an n-polygon with n vertices, the n vertices are arranged clockwise, and are sequentially represented as: b is 1 ,B 2 ,...,B n (ii) a Therefore, in clockwise arrangement, the resulting n-edge vectors are sequentially represented as:
Figure FDA0003679789070000041
the game role is radius R 0 The circle of (a); obtaining a circle inscribed hexagon of the game role; the 6 vertexes of the circle inscribed hexagon are arranged clockwise, and are sequentially represented as: k 1 ,K 2 ,...,K 6 (ii) a Therefore, in clockwise arrangement, the resulting 6 edge vectors are sequentially represented as:
Figure FDA0003679789070000042
vector of 6 edges
Figure FDA0003679789070000043
The direction and length of the vector are kept unchanged, and the 6 edge vectors are moved to converge the starting points of the 6 edge vectors into a point K 0 This results in a hexagonal expansion body EK which has a center point K 0 The vectors with 6 edges are arranged in the clockwise direction and respectively are:
Figure FDA0003679789070000044
Figure FDA0003679789070000045
step 2.1.2.2, first align the edge vectors
Figure FDA0003679789070000046
And (3) expanding, wherein the expanding mode is as follows:
s1.1) edge vector
Figure FDA0003679789070000047
Is point B 1 (ii) a The hexagonal expansion body EK is moved in parallel to make the center point K of the hexagonal expansion body EK 0 And point B 1 Overlapping;
point B 1 Is an edge vector
Figure FDA0003679789070000048
End point, opposite side vector
Figure FDA0003679789070000049
Elongation is carried out, the elongation point is represented as B " 1 Thereby obtaining a first reference line vector
Figure FDA00036797890700000410
Point B 1 Is an edge vector
Figure FDA00036797890700000411
Starting point of (2), making the edge vector
Figure FDA00036797890700000412
As a second reference line vector;
s1.2) 6-sided vector of hexagonal expansion body EK
Figure FDA00036797890700000413
Wherein the extreme value is identified as being greater than the first reference line vector
Figure FDA00036797890700000414
And is less than or equal to the second reference line vector
Figure FDA00036797890700000415
The set of edge vectors of (1) is set to have f edge vectors in total, the f edge vectors are sorted according to a clockwise order and are sequentially represented as follows:
Figure FDA00036797890700000416
wherein g1, g2, gf e [1,2, 6 ]];
Translation edge vector
Figure FDA00036797890700000417
Make the edge vector
Figure FDA00036797890700000418
Starting point K of 0 And point B 1 Overlapping; then, the edge vector is translated
Figure FDA00036797890700000419
Make it possible to
Figure FDA00036797890700000420
Starting point K of 0 And the edge vector
Figure FDA00036797890700000421
End point K of g1 Coincidence, and so on, until the opposite side vector is completed
Figure FDA00036797890700000422
By shifting the edge vector
Figure FDA00036797890700000423
The heads and the tails are connected;
will point K gf Renamed as point C 1
S1.3) by point C 1 As a starting point, an edge vector is drawn
Figure FDA00036797890700000424
Make the edge vector
Figure FDA00036797890700000425
And the edge vector
Figure FDA00036797890700000426
Parallel and equal length, point C 2 Is a vector of opposite edge
Figure FDA0003679789070000051
Performing an expanded end point;
this completes the opposite side vector
Figure FDA0003679789070000052
End point is point C 2 (ii) a Point B 1 To point C 2 The passed edge vector is the expanded edge vector;
step 2.1.2.3, opposite side vector
Figure FDA0003679789070000053
And (3) expanding, wherein the expanding mode is as follows:
s2.1) moving the hexagonal expansion body EK in parallel to enable the center point K of the hexagonal expansion body EK 0 And point C 2 Overlapping;
s2.2) Point C 2 Is an edge vector
Figure FDA0003679789070000054
End point, opposite side vector
Figure FDA0003679789070000055
Elongation was carried out with the elongation point denoted C " 2 Thereby obtaining a first reference line vector
Figure FDA0003679789070000056
At point C 2 As a starting point, make an edge vector
Figure FDA0003679789070000057
Parallel edge vectors as second reference line vectors;
s2.3) 6-edge vector of hexagonal expansion body EK
Figure FDA0003679789070000058
Wherein the extreme value is identified as being greater than the first reference line vector
Figure FDA0003679789070000059
And the edge vectors are less than or equal to the edge vector set between the second reference line vectors, so that all the edge vectors of the obtained edge vector set are sorted according to a clockwise direction, and after the edge vectors are connected end to end, the starting point and the point C are connected end to end 2 The end point after the superposition and the head and the tail are connected is named as a point C 3
S2.4) by point C 3 As a starting point, an edge vector is drawn
Figure FDA00036797890700000510
Make the edge vector
Figure FDA00036797890700000511
And the edge vector
Figure FDA00036797890700000512
Parallel and equal length, point C 4 Is a vector of opposite side
Figure FDA00036797890700000513
Performing an expanded end point;
this completes the opposite side vector
Figure FDA00036797890700000514
End point is point C 4 (ii) a Point C 2 To point C 4 The passed edge vector is the expanded edge vector;
according to the kindPush until the opposite side vector
Figure FDA00036797890700000515
Carrying out expansion;
and 2.1.2.4, finally forming a Static obstacle expander E Static _ obs (i).
CN202210633831.7A 2022-06-06 2022-06-06 Collision detection method for character movement in game Pending CN114949858A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210633831.7A CN114949858A (en) 2022-06-06 2022-06-06 Collision detection method for character movement in game

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210633831.7A CN114949858A (en) 2022-06-06 2022-06-06 Collision detection method for character movement in game

Publications (1)

Publication Number Publication Date
CN114949858A true CN114949858A (en) 2022-08-30

Family

ID=82960386

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210633831.7A Pending CN114949858A (en) 2022-06-06 2022-06-06 Collision detection method for character movement in game

Country Status (1)

Country Link
CN (1) CN114949858A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115222806A (en) * 2022-09-20 2022-10-21 腾讯科技(深圳)有限公司 Polygon processing method, device, equipment and computer readable storage medium
CN116036601A (en) * 2023-01-28 2023-05-02 腾讯科技(深圳)有限公司 Game processing method and device, computer equipment and storage medium
CN116562027A (en) * 2023-05-12 2023-08-08 江苏大学 Two-dimensional continuous collision detection method for circle and line segment set

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115222806A (en) * 2022-09-20 2022-10-21 腾讯科技(深圳)有限公司 Polygon processing method, device, equipment and computer readable storage medium
CN115222806B (en) * 2022-09-20 2022-12-09 腾讯科技(深圳)有限公司 Polygon processing method, device, equipment and computer readable storage medium
CN116036601A (en) * 2023-01-28 2023-05-02 腾讯科技(深圳)有限公司 Game processing method and device, computer equipment and storage medium
CN116562027A (en) * 2023-05-12 2023-08-08 江苏大学 Two-dimensional continuous collision detection method for circle and line segment set
CN116562027B (en) * 2023-05-12 2023-11-28 江苏大学 Two-dimensional continuous collision detection method for circle and line segment set

Similar Documents

Publication Publication Date Title
CN114949858A (en) Collision detection method for character movement in game
CN110487279B (en) Path planning method based on improved A-Algorithm
CN111504325B (en) Global path planning method based on weighted A-algorithm of enlarged search neighborhood
CN113219998B (en) Improved bidirectional-RRT-based vehicle path planning method
CN107607120B (en) Unmanned aerial vehicle dynamic track planning method based on improved restoration type Anytime sparse A algorithm
Fu et al. Siamese anchor proposal network for high-speed aerial tracking
CN110231824B (en) Intelligent agent path planning method based on straight line deviation method
CN110006429A (en) A kind of unmanned boat path planning method based on depth optimization
Ho et al. Collision-free curvature-bounded smooth path planning using composite Bezier curve based on Voronoi diagram
CN115079705A (en) Routing planning method for inspection robot based on improved A star fusion DWA optimization algorithm
CN114161416B (en) Robot path planning method based on potential function
CN112669434A (en) Collision detection method based on grid and bounding box
CN112306067A (en) Global path planning method and system
CN112286202A (en) Mobile robot path planning method for non-uniform sampling FMT
CN114281084B (en) Intelligent vehicle global path planning method based on improved A-algorithm
CN113172631A (en) Mechanical arm autonomous obstacle avoidance method based on improved RRT algorithm
CN111561933A (en) Double-improved A-star shortest route planning method
CN114200931A (en) Mobile robot path smoothing method based on B-spline curve optimization
CN111721296A (en) Data driving path planning method for underwater unmanned vehicle
CN115167398A (en) Unmanned ship path planning method based on improved A star algorithm
CN115060281B (en) Global path guide point generation planning method based on voronoi diagram
CN113239072A (en) Terminal equipment positioning method and related equipment thereof
CN110975288B (en) Geometric container data compression method and system based on jump point path search
CN112987740B (en) Mobile robot path planning control method
CN114442629B (en) Mobile robot path planning method based on image processing

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination