Obstacle detection method and device in game, electronic equipment and storage medium
Patent Information
- Application Number
- CN202311031979.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-15
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2043-08-15
AI Technical Summary
[0005]本申请提供一种游戏中的障碍物检测方法、装置、电子设备及计算机可读存储介质,以解决存在障碍物检测操作复杂,耗费巨大的计算资源的缺陷
[0023]本申请提供的游戏中的障碍物检测方法,通过使用三维动画软件编辑二维游戏场景中构成各场景物体的第一顶点,并根据各第一顶点生成障碍区域模型。通过障碍区域模型来模拟二维游戏场景中场景物体所占据的位置。根据障碍区域模型对应的障碍区域信息,针对各组前后连接的两个第一顶点进行插值,得到该两顶点之间的多个第二顶点。目标顶点包括第一顶点和第二顶点。之后,以第一虚拟角色所在的位置为极点,计算构成障碍区域模型的各目标顶点对应的极坐标,并计算第二虚拟角色所在位置对应的极坐标。其中,该极坐标反映了目标顶点或第二虚拟角色位于第一虚拟角色的哪个方位,以及与第一虚拟角色的距离。遍历各目标顶点对应的极坐标,判断在第一虚拟角色到第二虚拟角色的方位上,在各目标顶点对应的第一极坐标是否存在距离小于第一虚拟角色到第二虚拟角色之间的距离的第一极坐标。若存在,则确定在二维游戏场景中第一虚拟角色和第二虚拟角色之间存在障碍物;否则,则确定在二维游戏场景中第一虚拟角色和第二虚拟角色之间不存在障碍物。
Smart Images

Figure CN117224936B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to an obstacle detection method, apparatus, electronic device, and computer-readable storage medium in a game. Background Technology
[0002] With the rapid development of the gaming industry, 2D games have also seen rapid growth, with increasingly grand game scenes and more interesting gameplay mechanics. For example, the interaction between two virtual objects in a game can be designed by detecting whether there are obstacles between them.
[0003] In existing technology, a method for determining whether an obstacle exists between any two virtual characters in a 2D game scene includes the following steps: obtaining the positions of the two virtual characters, and connecting the two positions to obtain one or more rays. Then, sequentially traversing all scene objects in the 2D game scene, determining whether the scene object intersects with any of the aforementioned rays when traversing any scene object. Specifically, this can be achieved by determining whether the ray intersects with the shape corresponding to the scene object. If the scene object intersects with the aforementioned ray, it is determined that an obstacle exists between the two virtual characters. Otherwise, it is determined that no obstacle exists between the two virtual characters.
[0004] However, in 2D game scenes, where the number of scene objects is large and their shapes are complex, existing technologies suffer from the drawback of complex obstacle detection operations that consume huge amounts of computing resources. Moreover, this calculation is performed by the CPU, which can easily lead to a decrease in the game's frame rate due to the huge consumption of computing resources, thus causing game lag. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, and computer-readable storage medium for obstacle detection in games, in order to solve the shortcomings of complex obstacle detection operations and huge computational resource consumption.
[0006] In a first aspect, embodiments of this application provide an obstacle detection method in a game, the method comprising:
[0007] Obtain the obstacle area model corresponding to the game scene. The obstacle area model includes an outer closed shape and an inner region. The inner region includes all scene object models in the game scene. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. The scene object model is a model used to represent the horizontal cross-sectional shape of the scene object, which is formed by connecting multiple first vertices corresponding to the scene objects in the game scene.
[0008] On the line connecting two of the first vertices corresponding to the scene object, a plurality of second vertices are determined.
[0009] Using the position of the first virtual character in the obstacle area model as the pole, calculate the first polar coordinates corresponding to each target vertex in the obstacle area model and the second polar coordinates corresponding to the position of the second virtual character in the obstacle area model, wherein the target vertex includes the first vertex and the second vertex;
[0010] Based on the first polar coordinates and the second polar coordinates, determine whether there are obstacles between the first virtual character and the second virtual character.
[0011] Secondly, embodiments of this application provide an obstacle detection device for games, the device comprising:
[0012] The acquisition module is used to acquire the obstacle area model corresponding to the game scene. The obstacle area model includes an outer closed shape and an inner region. The inner region includes all scene object models in the game scene. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. The scene object model is a model formed by connecting multiple first vertices corresponding to scene objects in the game scene, and is used to represent the horizontal cross-sectional shape of the scene object.
[0013] The first determining module is used to determine a plurality of second vertices on the line connecting two first vertices among the first vertices corresponding to the scene object;
[0014] The processing module is used to calculate the first polar coordinates corresponding to each target vertex in the obstacle area model and the second polar coordinates corresponding to the position of the second virtual character in the obstacle area model, with the position of the first virtual character in the obstacle area model as the pole. The target vertex includes the first vertex and the second vertex.
[0015] The second determining module is used to determine whether there is an obstacle between the first virtual character and the second virtual character based on the first polar coordinates and the second polar coordinates.
[0016] Thirdly, embodiments of this application provide an electronic device, the electronic device comprising:
[0017] The memory and the processor are coupled;
[0018] The memory is used to store one or more computer instructions;
[0019] The processor is used to execute one or more computer instructions to implement the obstacle detection method in the game as described in any of the first aspects above.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium storing one or more computer instructions, characterized in that the instructions are executed by a processor to implement the obstacle detection method in a game as described in any of the first aspects above.
[0021] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the obstacle detection method in a game as described in any of the first aspects above.
[0022] Compared with the prior art, this application has the following advantages:
[0023] The obstacle detection method in this application uses 3D animation software to edit the first vertices of the objects constituting each scene in a 2D game scene, and generates obstacle region models based on these first vertices. These obstacle region models simulate the positions occupied by scene objects in the 2D game scene. Based on the obstacle region information corresponding to the obstacle region model, interpolation is performed on each pair of connected first vertices to obtain multiple second vertices between them. Target vertices include both first and second vertices. Then, using the position of the first virtual character as the pole, the polar coordinates corresponding to each target vertex constituting the obstacle region model are calculated, as well as the polar coordinates corresponding to the position of the second virtual character. These polar coordinates reflect the location of the target vertex or the second virtual character relative to the first virtual character, and their distance from the first virtual character. The polar coordinates corresponding to each target vertex are iterated through to determine if there exists a first polar coordinate at the position from the first virtual character to the second virtual character that is less than the distance between the first and second virtual characters. If such a first polar coordinate exists, it is determined that an obstacle exists between the first and second virtual characters in the 2D game scene; otherwise, it is determined that no obstacle exists between the first and second virtual characters in the 2D game scene.
[0024] Compared to existing technologies, the embodiments of this application require fewer computational resources. Furthermore, considering that ray detection methods in 3D animation software are typically implemented by the CPU—because ray detection requires accurate collision detection and calculation of objects in the game scene, and the CPU is better suited for handling such computational tasks—the embodiments of this application utilize a GPU with parallel computing capabilities. This accelerates the computation speed, reduces the CPU's processing burden, and thus ensures smooth game operation. Attached Figure Description
[0025] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0026] Figure 1 This is a flowchart illustrating the obstacle detection method in a game provided in the second embodiment of this application;
[0027] Figure 2 This is a schematic diagram of the polar coordinate system provided in the first embodiment of this application;
[0028] Figure 3 This is a schematic diagram of the horizontal cross-sectional shape of scene objects in the game scene provided in the first embodiment of this application;
[0029] Figure 4 This is a schematic diagram of the obstacle area model of the game scene provided in the first embodiment of this application;
[0030] Figure 5 This is one of the schematic diagrams of the distance texture map provided in the second embodiment of this application;
[0031] Figure 6 This is a second schematic diagram of the distance texture map provided in the second embodiment of this application;
[0032] Figure 7 This is a schematic diagram of the obstacle detection device in the game provided in the second embodiment of this application;
[0033] Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in the third embodiment of this application.
[0034] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation
[0035] To make the objectives, advantages, and features of this application clearer, the application will be described clearly and completely below in conjunction with the accompanying drawings and specific embodiments. In the following description, many specific details are set forth to provide a full understanding of this application. However, the described embodiments are only some, not all, of the embodiments of this application, and all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this application.
[0036] It should be noted that in the description of this application, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance, or a specific order or sequence. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances. Furthermore, in the description of this application, unless otherwise stated, the term "multiple" refers to two or more. The term "and / or" describes the relationship between related roles, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related roles are in an "or" relationship. The terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.
[0037] To facilitate understanding of the technical solution of this application, the relevant concepts involved in this application will be introduced first.
[0038] A 2D game scene refers to the virtual environment in a 2D game, which is typically composed of a series of two-dimensional elements such as plane graphics, images, and text. Unlike 3D game scenes, the elements in a 2D game scene can only move within a single plane and do not have a three-dimensional effect.
[0039] The prior art involved in this application and the problems existing in the prior art are described below:
[0040] In existing technology, a method for determining whether an obstacle exists between two virtual characters includes the following steps: obtaining the positions of the two virtual characters, and connecting the two positions to obtain one or more rays. Then, sequentially traversing all scene objects in the two-dimensional game scene, determining whether the scene object intersects with any of the aforementioned rays when traversing any scene object. Specifically, this can be achieved by determining whether the ray intersects with the shape corresponding to the scene object. If the scene object intersects with the aforementioned ray, it is determined that an obstacle exists between the two virtual characters. Otherwise, it is determined that no obstacle exists between the two virtual characters.
[0041] However, in 2D game scenes with a large number of objects and complex shapes, existing technologies suffer from drawbacks such as complex obstacle detection operations that consume enormous computational resources. Since this calculation is performed by the CPU, the high computational cost can easily lead to a decrease in game frame rate, causing game stuttering. For example, when a 2D game scene includes two virtual characters (e.g., one voice source virtual character and one preset virtual character) and M complex-shaped scene objects, traversing all scene objects once and connecting the voice source virtual character and the preset virtual character with Y different rays requires M*Y ray detections. Similarly, when a 2D game scene includes N+1 virtual characters (e.g., one voice source virtual character and N preset virtual characters) and M complex-shaped scene objects, obstacle detection needs to be performed for each of the N preset virtual characters and the voice source virtual character, requiring M*Y*N ray detections. Therefore, when simultaneously detecting obstacles between the voice source virtual character and multiple preset virtual characters, the computational load doubles.
[0042] In view of the problems existing in the prior art, this application provides an obstacle detection method in a game, a corresponding obstacle detection device in a game, an electronic device that can implement the obstacle detection method in the game, and a computer-readable storage medium. The following embodiments provide a detailed description of the above-mentioned method, device, electronic device, and computer-readable storage medium.
[0043] It should be noted that the above-described exemplary scenario of obstacle detection between virtual characters in a 2D game scene is merely one example among many scenarios in which the obstacle detection method provided in this application can be applied, and this exemplary scenario does not constitute a limitation. In practical applications, this obstacle detection method in games can also be used to detect obstacles between virtual characters in 3D game scenes.
[0044] To make the objectives and technical solutions of this application clearer and more intuitive, the methods provided by the embodiments of this application will be described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for explaining this application and are not intended to limit this application. It is understood that the following embodiments may exist independently, and the embodiments and features described below may be combined with each other where there is no conflict between the various embodiments provided in this application. For the same or similar content, it will not be repeated in different embodiments. Furthermore, the timing of the steps in the following method embodiments is merely an example and not a strict limitation. In some cases, the steps shown or described may be performed in a different order.
[0045] This application provides a method, apparatus, electronic device, and computer storage medium for obstacle detection in games. Specifically, the obstacle detection method in games according to one embodiment of this application can be executed by a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet, laptop, touch screen, game console, personal computer (PC), or other terminal device. The terminal can also include a client, which can be a game application client, a browser client carrying a game program, or an instant messaging client. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms.
[0046] Below, in conjunction with Figure 1 The obstacle detection method in the game provided in the first embodiment of this application will be described. Figure 1 This is a flowchart illustrating the obstacle detection method in a game provided in the second embodiment of this application.
[0047] like Figure 1 As shown, the method includes steps S101-S104:
[0048] S101. Obtain the obstacle area model corresponding to the game scene. The obstacle area model includes an outer closed shape and an inner region. The inner region includes all scene object models in the game scene. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. The scene object model is a model used to represent the horizontal cross-sectional shape of the scene object, which is formed by connecting multiple first vertices corresponding to the scene objects in the game scene.
[0049] In this embodiment of the application, the outer closed shape of the obstacle area model is a closed area obtained by connecting the scene object models corresponding to some scene objects. The scene object model is formed by connecting multiple first vertices corresponding to the scene objects, and is used to represent the horizontal cross-sectional shape of the scene objects.
[0050] It should be noted that when using 3D animation software (such as Unity, Maya, 3ds Max, etc.) to create 2D game scenes, the creators need to define the first vertex of each scene object within the 2D game scene, as well as the connection relationships between these first vertices. This is because, when creating a 2D game scene, each scene object is typically composed of multiple first vertices, and the connection relationships between these first vertices determine the shape of each scene object.
[0051] In this embodiment, the obstacle region model corresponding to the game scene includes an outer closed shape and an inner region. The inner region includes scene object models corresponding to all scene objects in the game scene. Each scene object model is formed by connecting multiple first vertices of the scene objects in the game scene, representing the horizontal cross-sectional shape of the scene objects. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. Specifically, it iterates through the first vertices of all scene object models, finding the outermost vertex (e.g., the leftmost, rightmost, topmost, or bottommost vertex among all first vertices). Starting from any outermost first vertex, connect adjacent outermost first vertices in a counter-clockwise direction until returning to the starting outermost first vertex. This results in a closed outline shape, i.e., the outer closed shape. The entire inner region of the outer closed shape is the inner region corresponding to the obstacle region model.
[0052] In the embodiments of this application, the game scene can be a two-dimensional game scene or a three-dimensional game scene, and this application does not limit it in any way.
[0053] S102. On the line connecting two first vertices among the vertices corresponding to the scene object, determine multiple second vertices.
[0054] S103. Using the position of the first virtual character in the obstacle area model as the pole, calculate the first polar coordinates corresponding to each target vertex in the obstacle area model and the second polar coordinates corresponding to the position of the second virtual character in the obstacle area model. The target vertices include the first vertex and the second vertex.
[0055] The following is a detailed explanation of steps S102-S103.
[0056] In this embodiment of the application, taking a two-dimensional game scene as an example, in the obstacle area model drawn for the two-dimensional game scene, the internal area of the obstacle area model can be used to represent the obstacle area composed of the scene object models corresponding to each scene object in the two-dimensional game scene.
[0057] Understandably, the specific implementation for calculating the distance from scene objects in a 2D game scene to the first virtual character can be achieved by calculating the distances from multiple target vertices corresponding to the scene objects to the first virtual character. For each target vertex corresponding to the scene object, with the position of the first virtual character in the 2D game scene as the pole, the polar coordinates corresponding to each target vertex are calculated. In the polar coordinate system, the polar coordinate position of a target vertex is determined by its polar radius and polar angle. The polar radius represents the distance from the pole to the target vertex, while the polar angle represents the angle of counterclockwise rotation from the positive polar axis (usually the horizontal axis) to the target vertex. Therefore, in the polar coordinate system with the position of the first virtual character as the pole, the polar angle in the polar coordinates corresponding to the target vertex represents the azimuth angle of the target vertex relative to the first virtual character. This azimuth angle can be used to describe the orientation or direction of the target vertex in the scene object relative to the first virtual character; the polar radius in the polar coordinates corresponding to the target vertex represents the straight-line distance between the target vertex in the scene object and the first virtual character.
[0058] In this embodiment of the application, when determining whether there is an obstacle between the first virtual character and the second virtual character, the distance between the target vertex of each scene object and the first virtual character or the second virtual character can be calculated, with the first virtual character as the pole or the second virtual character as the pole.
[0059] In this embodiment, the position information of the first virtual character in the two-dimensional game scene and the obstacle region information corresponding to the obstacle region model are input into the GPU to calculate the distance from each target vertex in the obstacle region model to the first virtual character. The obstacle region information includes the position coordinates of all the first vertices constituting the obstacle region model. It should be noted that after inputting the obstacle region information corresponding to the obstacle region model into the GPU, the GPU will determine multiple second vertices on the line connecting two first vertices corresponding to the scene objects. Target vertices include both first and second vertices.
[0060] Optionally, multiple second vertices can be determined by interpolation along the line connecting two first vertices that are connected to the first vertices of the scene object. Specifically, multiple second vertices can be determined by interpolation along the line connecting the two first vertices according to a preset rule. The preset rule includes one or more of the following: First, linear interpolation, where second vertices are inserted gradually between two first vertices at the same ratio. For example, on the line connecting two first vertices of the scene object, interpolation is performed at preset intervals to obtain a second vertex. Second, a preset number of second vertices are inserted between two first vertices, either evenly or non-uniformly. For example, assuming there are two first vertices A(0,0) and B(10,0), four second vertices are inserted between them. The distance from A to B is divided into five equal parts, and a second vertex is inserted at the midpoint of each part. Example coordinates of the four interpolated second vertices: P1(2,0), P2(4,0), P3(6,0), P4(8,0). A weight array weights = [1, 0.8, 0.6, 0.4] is set according to a non-uniform distribution, where the interpolation point closer to the first vertex A has a higher weight, and the interpolation point closer to the first vertex B has a lower weight. According to the weight array, the weight is multiplied by the horizontal distance from the first vertex A, and the product is the x-coordinate of each interpolation point (i.e., the second vertex). Examples of the four second vertex coordinates obtained by interpolation: P1(2*weights[1],0) = (2,0), P2(4*weights[2],0) = (3.2,0), P3(6*weights[3],0) = (2.4,0), P4(8*weights[4],0) = (3.2,0). This is only an example, and the embodiments of this application do not limit this in any way.
[0061] Optionally, in this embodiment of the application, in order to determine the location of each target vertex within the first virtual character and its distance from the first virtual character, the polar coordinates of each target vertex in the obstacle area model are calculated with the location of the first virtual character as the pole. Wherein, as... Figure 2 As shown, the polar coordinates of a point P in a polar coordinate system with pole O are represented as (d, θ). In polar coordinates, the polar radius d is the distance from point P to pole O, and the polar angle θ is the angle between ray OP and the polar axis (i.e., the positive half of the x-axis). Figure 2 This is a schematic diagram of the polar coordinate system provided in the first embodiment of this application.
[0062] Below, we will provide an example of one possible implementation of the distance from each target vertex to the first virtual character in the computational obstacle region model.
[0063] One possible implementation involves calculating the first polar coordinates of each target vertex in the obstacle region model from its position to the pole, using the position of the first virtual character as the pole. For example, if the number of target vertices constituting the obstacle region model is N, then the first polar coordinates corresponding to these N target vertices can be found in Table 1.
[0064] Table 1
[0065] Target vertex 1 <![CDATA[(d 1,1 ,i 1,1 )]]> Target Vertex 2 <![CDATA[(d 1,2 ,i 1,2 )<!-- 6 --> ]]> … … Target vertex N <![CDATA[(d 1,N ,i 1,N )]]>
[0066] One possible implementation is to calculate the polar coordinates of the second virtual character's position in the obstacle area model, using the position of the first virtual character as the pole, for example, (d 1,0 ,θ 1,0 ).
[0067] It should be noted that, to determine whether there is an obstacle between the first and second virtual characters, one can use the position of the first virtual character as the pole and calculate the polar coordinates corresponding to each target vertex, and then calculate the pole corresponding to the position of the second virtual character. Alternatively, one can use the position of the second virtual character as the pole and calculate the polar coordinates corresponding to each target vertex, and then calculate the pole corresponding to the position of the first virtual character.
[0068] 104. Based on the first polar coordinate and the second polar coordinate, determine whether there is an obstacle between the first virtual character and the second virtual character.
[0069] Below, with reference to Table 1 and a specific example, we will provide an exemplary description of one possible implementation for determining whether there is an obstacle between the first virtual character and the second virtual character.
[0070] For example, the polar coordinates corresponding to the position of the second virtual character in the obstacle area model are (d 1,0 ,θ 1,0 ).
[0071] Step 1: Determine the position of the first virtual character in the obstacle area model as the pole, with a polar angle of θ. 1,0 In the direction of [the target vertex], does a target vertex exist? Specifically, this is achieved by checking Table 1 to see if there exists a polar angle in polar coordinates equal to θ. 1,0 If it exists, then the pole is determined with the location of the first virtual character as the pole and the polar angle as θ. 1,0 There exists a target vertex in the direction of θ, that is, at the polar angle θ. 1,0 If a target vertex exists in the direction of the object, then a scene object exists. Continue to step two below. Otherwise, determine the location of the first virtual character as the pole, with a polar angle of θ. 1,0 If there is no target vertex in the direction, i.e. there is no obstacle, stop the subsequent operation and do not execute step two below.
[0072] Step two, at a polar angle of θ 1,0 If a target vertex (i.e., a scene object) exists in the direction of the first virtual character, it is necessary to determine whether there are obstacles between the first and second virtual characters. Specifically, in Table 1, the polar angle is equal to θ. 1,0 In one or more polar coordinates, determine whether there exists a polar radius less than d. 1,0 If an obstacle exists, it is determined that there is an obstacle between the first virtual character and the second virtual character in the two-dimensional game scene; otherwise, it is determined that there is no obstacle between the first virtual character and the second virtual character in the two-dimensional game scene.
[0073] The obstacle detection method in the game provided in this application uses 3D animation software to edit the first vertices of the objects constituting each scene in a 2D game scene, and generates an obstacle region model based on each first vertices. The obstacle region model simulates the positions occupied by scene objects in the 2D game scene. Based on the obstacle region information corresponding to the obstacle region model, interpolation is performed on each pair of connected first vertices to obtain multiple second vertices between the two vertices. Target vertices include first vertices and second vertices. Then, taking the position of the first virtual character as the pole, the polar coordinates corresponding to each target vertex constituting the obstacle region model are calculated, and the polar coordinates corresponding to the position of the second virtual character are also calculated. These polar coordinates reflect the location of the target vertex or the second virtual character relative to the first virtual character, and its distance from the first virtual character. The polar coordinates corresponding to each target vertex are traversed to determine whether there exists a first polar coordinate at the position from the first virtual character to the second virtual character whose distance is less than the distance between the first and second virtual characters. If such a first polar coordinate exists, it is determined that an obstacle exists between the first and second virtual characters in the 2D game scene; otherwise, it is determined that no obstacle exists between the first and second virtual characters in the 2D game scene.
[0074] Compared to existing technologies, in this embodiment, by using the first virtual character as the pole, the polar coordinates corresponding to all target vertices in the obstacle region model (e.g., the number of target vertices is Q), and the polar coordinates corresponding to the location of the second virtual character, the required computation is Q+1. To simultaneously detect whether there are obstacles between the first virtual character and N different second virtual characters, the polar coordinates corresponding to all target vertices in the obstacle region model, with the location of the first virtual character as the pole, and the polar coordinates corresponding to the locations of the N second virtual characters are first calculated, requiring a computation of Q+N. Where there are M virtual scenes, the value of Q is typically within the range of [2*M, K*M]. Therefore, when simultaneously detecting whether there are obstacles between the first virtual character and N different second virtual characters, the maximum required computation is: Q+N = M*K+N. However, existing technologies, in a 2D game scene including N+1 virtual characters (such as one sound source virtual character and N preset virtual characters), M complex-shaped scene objects, and Y different rays connecting the sound source virtual character to each preset virtual character, require M*Y*N number of ray detections. To correctly detect whether there are obstacle zones between the sound source virtual character and each preset virtual character, existing technologies typically require at least Y different rays connecting the sound source virtual character to each preset virtual character, where Y≥K. Therefore, M*Y*N≥M*K+N. Thus, compared to existing technologies, the embodiments of this application require fewer computational resources. Furthermore, considering that ray detection methods in 3D animation software are usually implemented by the CPU, because ray detection requires accurate collision detection and calculation of scene objects in the game scene, and the CPU is better suited to handling such computational tasks. However, the calculations in the embodiments of this application are implemented by a GPU with parallel computing capabilities, accelerating the calculation speed, reducing the processing burden on the CPU, and thus ensuring the smoothness of game operation.
[0075] Based on the above embodiments, the obstacle detection method in the game provided in this application will be further described below.
[0076] The following is a detailed explanation of the two possible implementation methods of step S104.
[0077] One possible implementation involves iterating through all first polar coordinates when there is only one second polar coordinate corresponding to the second virtual character. If there exists a first polar coordinate whose first polar angle equals the polar angle of the second polar coordinate and whose first polar radius is smaller than the polar radius of the second polar coordinate, then an obstacle exists between the first and second virtual characters. Otherwise, no obstacle exists between the first and second virtual characters. The first polar coordinate includes both the first polar angle and the first polar radius. For example, if the second polar coordinate is P(2, 60°), and there are 5 first polar coordinates whose first polar angle equals the polar angle 60° of the second polar coordinate, these 5 first polar coordinates are: Q1(3, 60°), Q2(1.5, 60°), Q3(1.8, 60°), Q4(5.2, 60°), and Q5(1, 60°). If among the five first polar coordinates there is a first polar coordinate whose first polar radius is smaller than the second polar coordinate, such as Q2(1.5, 60°), Q3(1.8, 60°), and Q5(1, 60°), then it can be determined that there is no obstacle between the first virtual character and the second virtual character.
[0078] Another possible implementation involves multiple polar coordinates corresponding to the second virtual character. These polar coordinates include a second polar angle and a second polar radius. The angle range corresponding to the second virtual character is determined based on the second polar angle among these multiple polar coordinates. Specifically, the angle range from the smallest to the largest polar angle among the multiple polar coordinates is defined as the angle range corresponding to the second virtual character. The maximum angle within this range is the largest polar angle among the multiple polar coordinates, and the minimum angle is the smallest polar angle among the multiple polar coordinates. All first polar coordinates are iterated over. If a first polar angle falls within the aforementioned angle range and the first polar radius is smaller than the target second polar radius, an obstacle is determined to exist between the first and second virtual characters. Here, the first polar coordinates include a first polar angle and a first polar radius, the target second polar radius is the polar radius of the target second polar coordinate, and the target second polar coordinate is a polar coordinate whose polar angle equals the first polar angle.
[0079] Optionally, the specific implementation of step S101 includes steps S1011-S1012:
[0080] S1011. For each scene object in the game scene, draw multiple first vertices corresponding to the scene object, and connect the multiple first vertices to obtain at least one edge segment corresponding to the scene object. The combination of at least one edge segment is used to indicate the horizontal cross-sectional shape of the scene object.
[0081] In this embodiment, when using 3D animation software (such as Unity) to draw a 2D game scene, the operator needs to set the first vertices corresponding to each scene object contained in the 2D game scene, as well as the connection relationships between the first vertices. For each scene object in the game scene, multiple first vertices corresponding to the scene object are drawn, and lines are drawn between the first vertices with connection relationships to obtain at least one edge segment corresponding to the scene object. The combination of at least one edge segment is used to indicate the horizontal cross-sectional shape of the scene object.
[0082] S1012. Generate an obstacle area model corresponding to the game scene based on at least one edge line segment corresponding to each scene object. The obstacle area model is proportional to the game scene.
[0083] Below, on the combination Figure 3 and Figure 4 Taking a two-dimensional game scene as an example, steps S1011-S1012 will be explained in detail. Figure 3 This is a schematic diagram of the horizontal cross-sectional shape of scene objects in the game scene provided in the first embodiment of this application. Figure 4 This is a schematic diagram of the obstacle area model of the game scene provided in the first embodiment of this application.
[0084] In this embodiment, a game engine is used to edit the first vertices of the objects constituting each scene in a 2D game scene, and obstacle region models are generated based on each first vertex to obtain obstacle region information. Game engines include Unity, Maya, 3ds Max, etc. Unity is a cross-platform game engine that can be used to develop 2D and 3D games and other interactive content. Unity provides a visual editor that allows developers to easily create game scenes, add objects, and set materials and lighting.
[0085] The following section uses Unity as an example to explain the process of drawing obstacle area models for a 2D game scene using the Unity engine.
[0086] In Unity, the first vertex position refers to the coordinates of the first vertex of a texture in a 2D model within two-dimensional space. Each texture that makes up a 2D game scene is composed of many first vertices, and these first vertices connected together restore the shape of the texture. The editor allows modification of the positions of each first vertex, enabling adjustments to the texture shape. The editor's move, rotate, and scale tools can also be used to modify the position, rotation angle, or scaling ratio of the first vertices. For example, the Collider2D component can be used to create scene objects of any shape, thus making the game more interesting. Collider2D is a built-in component of the Unity engine, allowing direct creation and editing of the shapes of characters in 2D virtual games, offering high flexibility.
[0087] In this embodiment, the 2D game scene is composed of a series of planar graphics, images, text, and other textures. Textures are 2D elements and do not have a grid shape. To calculate the distance information between scene objects and virtual characters in the 2D game scene, this embodiment considers using the Unity engine to edit the corresponding scene object models for all scene objects in the 2D game scene. Specifically, S1, Collider2D is used to edit the first vertices of each scene object in the 2D game scene and set the connection relationships between the first vertices. S2, Based on the first vertices and the connection relationships between them, the scene object models corresponding to each scene object are drawn.
[0088] In this embodiment, based on the first vertex edited in step S1, some line segments can be created using the Unity engine. These line segments ultimately connect to form an obstacle region model corresponding to scene objects in the 2D game scene. This obstacle region model is used to represent the shape and position of scene objects in the 2D game scene. Furthermore, based on the obstacle region model, obstacle region information corresponding to the obstacle region model can be obtained. This obstacle region information includes the position coordinates of all the first vertices constituting the obstacle region model. It should be noted that during the drawing of the obstacle region model, the Unity engine connects two first vertices that have a connection relationship.
[0089] In the Unity engine, when using the Collider2D component to edit the first vertex of a scene object to draw the line segments that make up the object's shape, the first vertex information is usually stored as a parameter array. Each element in the array represents a first vertex on the line segment. This first vertex can be considered an endpoint of the line segment, but it is not always one of the two endpoints. If the line segment is not a complete closed shape or has an angle, then its number of first vertices may be greater than two. In this case, the vector corresponding to each first vertex is a sampling point on the line segment.
[0090] Optionally, the Collider2D component can be used in the Unity engine to edit the corresponding scene object models for all scene objects in the 2D game scene. Specifically, for each scene object in the 2D game scene, the Collider2D component is used to edit the first vertices that constitute its corresponding shape on the canvas. For example, if there is a rectangular scene object 1 in the 2D game scene, the Collider2D component is used to draw the first vertices corresponding to the four right angles of scene object 1 on the canvas at the same scale, and the shape information corresponding to these four points is edited to a rectangle using the Collider2D component. As another example, if there is a circular scene object 2 in the 2D game scene, multiple points are randomly sampled on scene object 2, such as 9 points, and the Collider2D component is used to draw the 9 points that constitute scene object 2 on the canvas at the same scale, and the shape information corresponding to these 9 points is edited to a circle using the Collider2D component. It should be noted that for scene objects with complex shapes such as circles or irregular shapes, the more shape sampling points of the scene object, the more accurately the shape can be described. A scene object model is constructed by connecting multiple first vertices corresponding to a scene object, and is used to represent the horizontal cross-sectional shape of the scene object. It should be noted that the finished image displays the edge segments corresponding to the scene object obtained by connecting multiple first vertices; you can refer to [the relevant documentation / reference]. Figure 3 As shown. It should be noted that, Figure 3 This is simply used to illustrate the scene object model corresponding to the scene objects generated using the Collider2D component in the Unity engine. Figure 3 It includes edge segments that describe the planar cross-sectional shape of objects in the scene.
[0091] In this embodiment, the closed region obtained by connecting the scene object models corresponding to each scene object is the obstacle region model. Based on the scene object models corresponding to each scene object in a two-dimensional game scene, a closed region model corresponding to the two-dimensional game scene, i.e., the obstacle region model, is generated, as follows: Figure 4 As shown.
[0092] Optionally, before step S104, the following step S201 is also included:
[0093] S201. Generate a distance texture map based on the first polar coordinates. The distance texture map is used to represent the distance between the target vertex and the first virtual character. The two dimensions of the distance texture map include the angle and the identifier of the first virtual character.
[0094] In this embodiment of the application, the distance texture map can be used to find the target vertex that is closest to the first virtual character in each direction with the first virtual character as the pole, and the distance between the target vertex and the first virtual character.
[0095] Correspondingly, the specific implementation of step S104 includes step S202:
[0096] S202. Based on the distance texture map and the second polar coordinates, determine whether there are obstacles between the first virtual character and the second virtual character.
[0097] Optionally, steps S201-S202 may be implemented in the following ways: steps S2011-S2016.
[0098] S2011. Group the first polar coordinates to obtain multiple first polar coordinate groups, and the first polar coordinates in the first polar coordinate groups have the same first polar angle.
[0099] S2012. For each first polar coordinate group, determine the pixel value corresponding to the first polar angle of the first polar coordinate group based on the smallest first polar diameter in the first polar diameter of the first polar coordinate group.
[0100] In this embodiment, the smallest first polar radius among the first polar radii corresponding to the first polar coordinate group is found. The distance between the two farthest target vertices in the obstacle region model (hereinafter referred to as: the first distance) is obtained. The ratio of the smallest first polar radius among the first polar radii corresponding to the first polar coordinate group to the first distance is determined as the pixel value corresponding to the first polar angle of the first polar coordinate group. The pixel value corresponding to the first polar angle of the first polar coordinate group is, in other words, the pixel value determined based on the first polar radius corresponding to the target vertex closest to the first virtual character at the azimuth angle of the first virtual character.
[0101] S2013. Generate a distance texture map based on each first polar angle and the pixel value corresponding to each first polar angle.
[0102] S2014. Determine the pixel value corresponding to the second polar angle from the distance texture map. The second polar angle is the polar angle of the second polar coordinate.
[0103] S2015. Calculate the first polar radius corresponding to the pixel value based on the pixel value corresponding to the second polar angle.
[0104] S2016. If the first polar radius corresponding to the pixel value is less than the second polar radius of the second polar coordinate, it is determined that there is an obstacle between the first virtual character and the second virtual character.
[0105] In this application embodiment, firstly, an exemplary implementation of storing the distances from all scene objects to the first virtual character in a texture map is described.
[0106] In one possible implementation, a texture map of dimension X*Y is first created to store the distance information from the target vertex to the first virtual character. Since the target vertex can represent an obstacle area in a two-dimensional game scene, this embodiment stores the pixel value corresponding to the first polar angle in the first polar coordinates of the target vertex closest to the first virtual character in each direction (or angle), with the position of the first virtual character in the obstacle model as the pole. The X dimension data can be angles; a larger X value indicates more angular information can be stored, thereby improving the accuracy of determining whether the object is occluded by scene objects. Y represents the distance information from the target vertex to Y virtual characters stored in the texture map. For example, in this application, only the pixel value corresponding to the first polar angle in the first polar coordinates of the target vertex closest to the first virtual character in each direction (or angle), calculated with the position of the first virtual character in the obstacle area model as the pole, is stored; therefore, the Y value of the texture in this application is 1. For example... Figure 5 As shown, a 16*1 texture map can represent 16 directions or angles and one first virtual character. Among them, Figure 5 This is one of the schematic diagrams of the distance texture map provided in the second embodiment of this application.
[0107] like Figure 5 As shown, a 16*1 texture map is displayed. This distance texture map can show: in 16 different directions or angle ranges, the pixel value represents the pixel value corresponding to the first polar angle in the first polar coordinates of the target vertex that is closest to the first virtual character in a certain direction or angle range. The pixel value corresponding to the first polar angle in the first polar coordinates of the target vertex is related to the distance between the target vertex and the first virtual character.
[0108] It should be noted that after calculating the polar coordinates (d, θ) of all target vertices in the obstacle area model, with the position of the first virtual character in the obstacle area model as the pole, data mapping is required for the polar radius and polar angle before storing the polar coordinates of each target vertex on the texture map. That is, the pixel value is the value of the polar radius mapped to the range [0, 1]. The polar angle needs to be mapped to [-π, π] first, and then to the clipping control [-1, 1]. This mapping is only briefly described here; the reasons and process of the mapping will be explained in detail later.
[0109] Before explaining the reasons and process of mapping in detail, we need to briefly introduce two important tools used in Unity to perform data calculations and data mapping.
[0110] Fragment shaders and vertex shaders are two distinct stages in the graphics rendering pipeline, with different responsibilities and handling different types of data. Specifically:
[0111] The vertex shader is the first stage in the graphics rendering pipeline. Its main task is to convert the input vertex data into coordinates in clip space. The vertex shader can transform and process the vertex's position, color, normals, etc., converting them from the model coordinate system to the view coordinate system, and calculating other necessary attributes such as lighting. Therefore, it primarily processes vertex data.
[0112] The fragment shader is the second stage after the vertex shader, and it is mainly responsible for coloring primitives (points, lines, triangles) in clip space. The fragment shader can calculate the color of each pixel, and effects such as texture mapping, shadows, reflections, and refractions are all processed in the fragment shader. Therefore, it mainly processes pixel data.
[0113] In summary, the vertex shader and fragment shader are responsible for processing different types of data. The vertex shader processes vertex data, while the fragment shader processes pixel data. Necessary rendering information is gradually added to the rendering pipeline through these two distinct steps, ultimately generating a texture map.
[0114] The reasons and process for data mapping to polar radius and polar angle in polar coordinates will be explained in the following examples.
[0115] One possible implementation involves obtaining the distance between the two farthest target vertices in the obstacle region model (hereinafter referred to as the "first distance"). In the fragment shader, for the target vertex closest to the first virtual character in each direction (or angle), the quotient of the polar radius in the polar coordinates of the target vertex and the first distance is determined as the pixel value corresponding to the polar angle in the polar coordinates of each target vertex (which can be understood as the pixel value determined based on the size of the first polar radius in the polar coordinates of the target vertex closest to the first virtual character in each direction (or angle)). This achieves mapping the polar radius in the polar coordinates of the target vertex to the range [0,1]. It should be noted that when using the GPU to draw texture information through the Unity engine, image processing libraries are usually used to process and render the texture. During processing and rendering, the pixel values used are usually floating-point numbers in the range [0,1]. Therefore, to facilitate calculation and rendering processing, the polar radius is usually mapped to the range [0,1] when drawing texture information. Furthermore, using values within the range [0,1] avoids overflow or underflow issues during calculation and rendering, thus improving data readability and maintainability. In summary, mapping the polar radius to the range [0,1] is a standard processing method that improves calculation and rendering efficiency while also facilitating secondary development and maintenance. Of course, values can be mapped to other ranges for processing and rendering if needed; this application does not impose any restrictions on this.
[0116] One possible implementation is to convert the world coordinates of the obstacle region model into angles in the vertex shader for each polar angle, and then map the angles [-π,π] to the clip space [-1,1], thus obtaining the numerical values after data mapping for each polar angle.
[0117] It should be noted that in computer graphics, target vertex information typically includes the position, color, and normal vector of each target vertex in the model. This target vertex information can be stored in a data structure or read from a file. In the vertex shader, each target vertex is transformed to clip space and rasterized to generate fragments. In this embodiment, the polar coordinates corresponding to the target vertex are displayed as a texture map.
[0118] To facilitate understanding distance texture maps, combined with Figure 6 This section displays a texture map storing the distances to the target vertices closest to the first virtual character in various directions (i.e., different angles). Figure 6 This is a second schematic diagram of the distance texture map provided in the second embodiment of this application.
[0119] like Figure 6As shown, this illustrates drawing a perpendicular line along the horizontal axis at 90°, with pixel value k; a perpendicular line along the horizontal axis at 180°, with pixel value p; a perpendicular line along the horizontal axis at 240°, with pixel value m; and a perpendicular line along the horizontal axis at 360°, with pixel value n. Since the pixel value corresponding to a certain polar angle represents the distance (i.e., the polar radius) between the target vertex closest to the first virtual character in the direction corresponding to the polar angle, with the first virtual character as the pole, it is necessary to convert the pixel values from [0, 1] back to the actual distance. For example, as... Figure 6 In the 90° direction, the corresponding pixel value is k. Therefore, in the direction corresponding to the first virtual character as the pole and a polar angle of 90°, the distance between the target vertex closest to the first virtual character and the first virtual character is k * first distance. Here, the first distance refers to the distance between the two farthest target vertices in the obstacle region model.
[0120] In this embodiment, by utilizing the parallel computing capabilities of the GPU, such as in Unity, the angles and distances of each target vertex relative to virtual character 1 are saved to a texture map in a rendered manner. When it is necessary to determine whether there is an obstacle between virtual character 1 and virtual character 2 (i.e., whether virtual character 1 is occluded by an obstacle), it is only necessary to calculate the angle and distance of virtual character 2 relative to the position of virtual character 1, then read the angle and distance information stored in the texture map, and compare the distances to determine whether there is an obstacle between the two virtual characters. Compared with the existing technology that uses the CPU for calculation, this embodiment uses the parallel processing capabilities of the GPU in calculating the polar coordinate distance between virtual character 1 and each target vertex, thereby greatly improving the calculation efficiency and rendering efficiency. This avoids the drawback of the CPU consuming huge computing resources to calculate whether there is an intersection, which leads to excessive time spent in one frame of the game determining whether the character is occluded by an obstacle, thus reducing the game frame rate and causing game stuttering.
[0121] Optionally, in response to a first sound event triggered by a first terminal corresponding to a first virtual character, if there are no obstacles between the first and second virtual characters, a sound signal corresponding to the first sound event is sent to a second terminal corresponding to the second virtual character, so that the second terminal plays sound according to the sound signal. It should be emphasized that the position of the virtual character that triggered the first sound event (i.e., the first virtual character) in the obstacle area model is taken as the pole. To determine whether there are obstacles between N second virtual characters and the first virtual character, it is only necessary to calculate the first polar coordinates corresponding to each vertex in the obstacle area model, and the second polar coordinates corresponding to the positions of the N second virtual characters in the obstacle area model, using the position of the first virtual character in the obstacle area model as the pole. Even if it is necessary to determine whether there are obstacles between the first virtual character and more second virtual characters (e.g., K second virtual characters), in this embodiment, only the second polar coordinates corresponding to the positions of the K second virtual characters in the obstacle area model need to be calculated. Therefore, using the position of the virtual character that triggered the first sound event (i.e., the first virtual character) in the obstacle area model as the pole can greatly reduce the amount of computation.
[0122] In this embodiment, an obstacle area model is created for scene objects in a 2D game scene using the Unity engine. Leveraging the parallel computing power of the GPU, the polar coordinates (including azimuth and distance) of each target vertex are calculated, centered on the first virtual character, and the polar coordinate distance information is recorded in a texture map. Then, the polar coordinates corresponding to the position of the second virtual character in the game scene are calculated, for example, (d...). 1,0 ,θ 1,0 Finally, the texture map is read, and the position of the first virtual character in the game scene is taken as the pole and the azimuth angle is θ. 1,0 In the direction of , is there a distance less than d from the first virtual character? 1,0 The scene objects, specifically, the texture information, are searched for objects with an azimuth angle of θ. 1,0 And the distance is less than d 1,0The distance information is determined. If an obstacle exists, it is determined that there is an obstacle between the first virtual character and the second virtual character in the 2D game scene; otherwise, it is determined that there is no obstacle between the first virtual character and the second virtual character in the 2D game scene. If there is no obstacle between the first virtual character and the second virtual character, the control sends a sound signal corresponding to the first sound event to the second terminal corresponding to the second virtual character, so that the second terminal plays the sound according to the sound signal. For example, in the 2D game scene, the player controlling the first virtual character controls the first terminal to trigger a first sound event, such as striking a gong or drum. If it is determined that there is no obstacle between the first virtual character and the second virtual character, the control sends a sound signal corresponding to the first sound event to the second terminal corresponding to the second virtual character, so that the second terminal plays the sound of striking the gong or drum according to the sound signal, thus allowing the player corresponding to the second virtual character to hear the sound of striking the gong or drum through the second terminal.
[0123] The obstacle detection device in the game provided in this application is described below. The obstacle detection device in the game described below can be referred to in correspondence with the obstacle detection method in the game described above.
[0124] Figure 7 This is a schematic diagram of the obstacle detection device in a game provided in the second embodiment of this application. Figure 7 As shown, the obstacle detection device in the game includes: an acquisition module 701, a first determination module 702, a processing module 703, and a second determination module 704.
[0125] The acquisition module is used to acquire the obstacle area model corresponding to the game scene. The obstacle area model includes an outer closed shape and an inner region. The inner region includes all scene object models in the game scene. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. The scene object model is a model formed by connecting multiple first vertices corresponding to scene objects in the game scene, and is used to represent the horizontal cross-sectional shape of the scene object.
[0126] The first determining module is used to determine a plurality of second vertices on the line connecting two first vertices among the first vertices corresponding to the scene object;
[0127] The processing module is used to calculate the first polar coordinates corresponding to each target vertex in the obstacle area model and the second polar coordinates corresponding to the position of the second virtual character in the obstacle area model, with the position of the first virtual character in the obstacle area model as the pole. The target vertex includes the first vertex and the second vertex.
[0128] The second determining module is used to determine whether there is an obstacle between the first virtual character and the second virtual character based on the first polar coordinates and the second polar coordinates.
[0129] Optionally, the number of second polar coordinates corresponding to the second virtual character is one; the second determining module is specifically used for:
[0130] Traverse all the first polar coordinates. If there is a first polar coordinate where the first polar angle is equal to the polar angle of the second polar coordinate and the first polar radius is smaller than the polar radius of the second polar coordinate, then it is determined that there is an obstacle between the first virtual character and the second virtual character. The first polar coordinate includes the first polar angle and the first polar radius.
[0131] Optionally, the number of second polar coordinates corresponding to the second virtual character is multiple, and the second determining module is specifically used for:
[0132] The angle range corresponding to the second virtual character is determined based on the second polar angle among the multiple second polar coordinates corresponding to the second virtual character;
[0133] Traverse all the first polar coordinates. If there is a first polar coordinate where the first polar angle is within the angle range and the first polar diameter is smaller than the target second polar diameter, it is determined that there is an obstacle between the first virtual character and the second virtual character. The first polar coordinate includes the first polar angle and the first polar diameter. The target second polar diameter is the polar diameter of the target second polar coordinate. The target second polar coordinate is the second polar coordinate where the polar angle is equal to the first polar angle.
[0134] Optionally, the first terminal corresponding to the first virtual character triggers a first sound event, wherein the first virtual character is a virtual character controlled by the first terminal, and the processing module is further configured to:
[0135] If there are no obstacles between the first virtual character and the second virtual character, the system controls the sending of a sound signal corresponding to the first sound event to the second terminal corresponding to the second virtual character, so that the second terminal plays a sound according to the sound signal.
[0136] Optionally, before determining whether there is an obstacle between the first virtual character and the second virtual character based on all the first polar coordinates and the second polar coordinates, the processing module is further configured to:
[0137] A distance texture map is generated based on the first polar coordinates. The distance texture map is used to represent the distance between the target vertex and the first virtual character. The two dimensions of the distance texture map include the angle and the identifier of the first virtual character.
[0138] The second determining module is specifically used for:
[0139] Based on the distance texture map and the second polar coordinates, it is determined whether there are obstacles between the first virtual character and the second virtual character.
[0140] Optionally, the first polar coordinates include a first polar angle and a first polar radius, and the processing module is specifically used for:
[0141] The first polar coordinates are grouped to obtain multiple first polar coordinate groups, and the first polar coordinates in the first polar coordinate groups have the same first polar angle;
[0142] For each of the first polar coordinate groups, the pixel value corresponding to the first polar angle of the first polar coordinate group is determined based on the smallest first polar radius among the first polar radii corresponding to the first polar coordinate group.
[0143] A distance texture map is generated based on each of the first polar angles and the pixel values corresponding to each of the first polar angles.
[0144] Optionally, the second polar coordinates include a second polar angle and a second polar radius, and the second determining module is specifically used for:
[0145] From the distance texture map, determine the pixel value corresponding to the second polar angle, where the second polar angle is the polar angle of the second polar coordinates;
[0146] Calculate the first polar diameter corresponding to the pixel value based on the pixel value corresponding to the second polar angle;
[0147] If the first polar radius corresponding to the pixel value is less than the second polar radius of the second polar coordinate, it is determined that there is an obstacle between the first virtual character and the second virtual character.
[0148] Optionally, the first determining module is specifically used for:
[0149] Multiple second vertices are determined by interpolation on the line connecting two first vertices corresponding to the first vertices of the scene object.
[0150] Optionally, the acquisition module is specifically used for:
[0151] For each scene object in the game scene, draw multiple first vertices corresponding to the scene object, and connect the multiple first vertices to obtain at least one edge line segment corresponding to the scene object; wherein, the combination of the at least one edge line segment indicates the horizontal cross-sectional shape of the scene object.
[0152] Based on at least one edge line segment corresponding to each scene object, an obstacle area model corresponding to the game scene is generated, and the obstacle area model is proportional to the game scene.
[0153] The obstacle detection device in the game provided in this embodiment can be used to execute the technical solution of the obstacle detection method embodiment in the game described above. Its implementation principle and technical effect are similar, and will not be described again in this embodiment.
[0154] Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in the third embodiment of this application, as shown below. Figure 8 As shown, the electronic device 800 of this embodiment includes: a processor 801 and a memory 802; wherein
[0155] Memory 802 is used to store instructions executed by the computer;
[0156] The processor 801 is configured to execute computer execution instructions stored in the memory to implement the various steps of the obstacle detection method in the game described in the above embodiments. For details, please refer to the relevant descriptions in the foregoing method embodiments.
[0157] Alternatively, the memory 802 can be either standalone or integrated with the processor 801.
[0158] When the memory 802 is set up independently, the electronic device also includes a bus 803 for connecting the memory 802 and the processor 801.
[0159] The fourth embodiment of this application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the technical solution corresponding to the obstacle detection method in the game in any of the above embodiments executed by the above electronic device.
[0160] The fifth embodiment of this application also provides a computer program product, which includes: a computer program stored in a readable storage medium, at least one processor of an electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program to cause the electronic device to execute the technical solution corresponding to the obstacle detection method in the game in any of the above embodiments.
[0161] It should be noted that for detailed descriptions of the apparatus, electronic equipment, computer-readable storage medium, and computer program products provided in the second, third, fourth, and fifth embodiments of this application, please refer to the relevant descriptions of the first embodiment of this application, which will not be repeated here.
[0162] Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of this application. Therefore, the scope of protection of this application should be determined by the scope defined in the claims of this application.
[0163] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.
[0164] The integrated modules implemented as software functional modules described above can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) or a processor to execute some steps of the methods described in the various embodiments of this application.
[0165] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.
[0166] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk or optical disc, etc.
[0167] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0168] The aforementioned storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.
[0169] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0170] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. An obstacle detection method in a game, characterized in that, The method includes: Obtain the obstacle area model corresponding to the game scene. The obstacle area model includes an outer closed shape and an inner region. The inner region includes all scene object models in the game scene. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. The scene object model is a model used to represent the horizontal cross-sectional shape of the scene object, which is formed by connecting multiple first vertices corresponding to the scene objects in the game scene. On the line connecting two of the first vertices corresponding to the scene object, a plurality of second vertices are determined. Using the position of the first virtual character in the obstacle area model as the pole, calculate the first polar coordinates corresponding to each target vertex in the obstacle area model and the second polar coordinates corresponding to the position of the second virtual character in the obstacle area model, wherein the target vertex includes the first vertex and the second vertex; Based on the first polar coordinates and the second polar coordinates, determine whether there are obstacles between the first virtual character and the second virtual character.
2. The method according to claim 1, characterized in that, The number of second polar coordinates corresponding to the second virtual character is one; The step of determining whether there is an obstacle between the first virtual character and the second virtual character based on all the first polar coordinates and the second polar coordinates includes: Traverse all the first polar coordinates. If there is a first polar coordinate where the first polar angle is equal to the polar angle of the second polar coordinate and the first polar radius is smaller than the polar radius of the second polar coordinate, then it is determined that there is an obstacle between the first virtual character and the second virtual character. The first polar coordinate includes the first polar angle and the first polar radius.
3. The method according to claim 1, characterized in that, The second virtual character has multiple second polar coordinates, including a second polar angle and a second polar radius; determining whether there is an obstacle between the first virtual character and the second virtual character based on all the first and second polar coordinates includes: The angle range corresponding to the second virtual character is determined based on the second polar angle among the multiple second polar coordinates corresponding to the second virtual character; Traverse all the first polar coordinates. If there is a first polar coordinate where the first polar angle is within the angle range and the first polar diameter is smaller than the target second polar diameter, it is determined that there is an obstacle between the first virtual character and the second virtual character. The first polar coordinate includes the first polar angle and the first polar diameter. The target second polar diameter is the polar diameter of the target second polar coordinate. The target second polar coordinate is the second polar coordinate where the polar angle is equal to the first polar angle.
4. The method according to claim 1, characterized in that, The first terminal corresponding to the first virtual character triggers a first sound event, wherein the first virtual character is a virtual character controlled through the first terminal, and the method further includes: If there are no obstacles between the first virtual character and the second virtual character, the system controls the sending of a sound signal corresponding to the first sound event to the second terminal corresponding to the second virtual character, so that the second terminal plays a sound according to the sound signal.
5. The method according to claim 1, characterized in that, Before determining whether there is an obstacle between the first virtual character and the second virtual character based on all the first polar coordinates and the second polar coordinates, the method further includes: A distance texture map is generated based on the first polar coordinates. The distance texture map is used to represent the distance between the target vertex and the first virtual character. The two dimensions of the distance texture map include the angle and the identifier of the first virtual character. The step of determining whether there is an obstacle between the first virtual character and the second virtual character based on all the first polar coordinates and the second polar coordinates includes: Based on the distance texture map and the second polar coordinates, it is determined whether there are obstacles between the first virtual character and the second virtual character.
6. The method according to claim 5, characterized in that, The first polar coordinates include a first polar angle and a first polar radius. The step of generating a distance texture map based on all the first polar coordinates includes: The first polar coordinates are grouped to obtain multiple first polar coordinate groups, and the first polar coordinates in the first polar coordinate groups have the same first polar angle; For each of the first polar coordinate groups, the pixel value corresponding to the first polar angle of the first polar coordinate group is determined based on the smallest first polar radius among the first polar radii corresponding to the first polar coordinate group. A distance texture map is generated based on each first polar angle and the pixel value corresponding to each first polar angle.
7. The method according to claim 6, characterized in that, The second polar coordinates include a second polar angle and a second polar radius. Determining whether an obstacle exists between the first virtual character and the second virtual character based on the distance texture map and the second polar coordinates includes: From the distance texture map, determine the pixel value corresponding to the second polar angle, where the second polar angle is the polar angle of the second polar coordinates; Calculate the first polar diameter corresponding to the pixel value based on the pixel value corresponding to the second polar angle; If the first polar radius corresponding to the pixel value is less than the second polar radius of the second polar coordinate, it is determined that there is an obstacle between the first virtual character and the second virtual character.
8. The method according to claim 1, characterized in that, On the line connecting two first vertices corresponding to the first vertices of the scene object, a plurality of second vertices are determined, including: Multiple second vertices are determined by interpolation on the line connecting two first vertices in the first vertex corresponding to the scene object.
9. The method according to claim 1, characterized in that, The process of obtaining the obstacle area model corresponding to the game scene includes: For each scene object in the game scene, draw multiple first vertices corresponding to the scene object, and connect the multiple first vertices to obtain at least one edge line segment corresponding to the scene object; wherein, the combination of the at least one edge line segment indicates the horizontal cross-sectional shape of the scene object. Based on at least one edge line segment corresponding to each scene object, an obstacle area model corresponding to the game scene is generated, and the obstacle area model is proportional to the game scene.
10. An obstacle detection device for games, characterized in that, The device includes: The acquisition module is used to acquire the obstacle area model corresponding to the game scene. The obstacle area model includes an outer closed shape and an inner region. The inner region includes all scene object models in the game scene. The outer closed shape is a closed shape obtained by connecting some scene object models in the game scene. The scene object model is a model formed by connecting multiple first vertices corresponding to scene objects in the game scene, and is used to represent the horizontal cross-sectional shape of the scene object. The first determining module is used to determine a plurality of second vertices on the line connecting two first vertices among the first vertices corresponding to the scene object; The processing module is used to calculate the first polar coordinates corresponding to each target vertex in the obstacle area model and the second polar coordinates corresponding to the position of the second virtual character in the obstacle area model, with the position of the first virtual character in the obstacle area model as the pole. The target vertex includes the first vertex and the second vertex. The second determining module is used to determine whether there is an obstacle between the first virtual character and the second virtual character based on the first polar coordinates and the second polar coordinates.
11. An electronic device, characterized in that, The electronic device includes: Processor; and A memory for storing a data processing program, which, when powered on and run by the processor, executes the obstacle detection method in the game as described in any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, The system contains a data processing program that is run by a processor to perform the obstacle detection method in the game as described in any one of claims 1-9.
Citation Information
Patent Citations
Virtual object display method in virtual scene, computer equipment and storage medium
CN112870707A
Virtual character movement control method and device, electronic equipment and storage medium
CN114870399A