2019年3月20日星期三

High performance A* Pathfinding

AJ_Pathfinding

High-performance A* Pathfinding

Overview

Combination With the development of mobile games, we need to do more performance on mobile phones, but the performance of mobile phones is limited. Every important module should have as much performance as possible to improve the overall performance. In the pathfinding algorithm, the common a* has a large consumption performance when comparing large maps. Therefore, I have made a* a good improvement. This is already used as a simple tool class. The plugin includes a tool for blocking data generation and a Demo for pathfinding algorithm.

This article describes the basic usage of high performance "pathfinding" and its applications.


Quick Start
First, open the demo scene Demo/DemoSearch1 and run it.
You can see the following picture:



Multiple objects are randomly free to find paths. You can also click on the scene freely and let the main character object (red dot) run for pathfinding.
When the main character finds a path, it will output the time of the path finding in the output panel.
As can be seen from the figure, the frame rate is still high in the case of continuously performing pathfinding logic for more than 20 path finding objects.

Description of the parameters of the Inspector panel in DemoSearch1:

Scene PrefabIs: the pathfinding scene prefab to be loaded.
Block Data Json: Is the pathfinding data generated by the tool.
Cell Prefab: It is a prefabric body used to block the grid.
Move Count: Is the number of moving objects except the main character.
Move Speed: Is the global speed of movement.
Hero Prefab: It is the prefabric used by the protagonist.
Player Prefab: Is a prefab of other moving objects.
Hero Tail Prefab: When the main character moves, a trailing prefab is generated.
Player Tail Prefab: Is a trailing prefab when other moving objects move.
S Camera: Is the main camera, mainly used for the processing of click scenes.


Block data generation tool description:
Open the Demo/Tools scene
Mainly concerned about PlaneScene in Hierarchy.

LocationGO and Plane under PlaneScene
LocationGO is mainly used to mark the starting point of the lower left corner of the drawing blocking data.
Plane is a concrete scene.
Among the components of PlaneScene are two, BoxColider and ABlockTools.

The Size of the BoxColider must be the size of the scene that needs to draw the blocked data.
Some configuration properties of ABlockTools:
Scale Speed:When drawing blocking data, scroll the speed at which the axis in the mouse scales the scene.
Move Speed: Press the keyboard Ctrl+left mouse button to move the mouse when the scene is panning.
Map W and Map H: It is the width and height of the map, and it must be consistent with the Size of the BoxColider.
Map Org V2: It is used to determine the starting point of the lower left corner of the blocking data, referring to the coordinates of LocationGO.
Height Of Overlook: Is the height distance from the scene when the camera starts.
Cell W: It is the length of each block.
Cell Prefab: It is a prefabricated body that blocks the grid.
Frame Line Prefab: It is a prefabricated body of the border line.

After the Tools scene is running, you can block the drawing of data.
If the GameObject hooked by the ABlockTools component has generated blocking data in AJ_Pathfinding/Resources/AJ_BlockData, the data will be read and drawn on this basis.
Right click on the ABlockTools component in PlaneScene, pop up the tool box, select "Start drawing blockades" to start blocking rendering; if the blocked path has been drawn and saved, the existing blocking data will be loaded and rendered.

In drawing, press the left mouse button on the scene and move to generate blocking data; click the right mouse button to delete the blocking data; the mouse axis zooms the scene; Ctrl + left mouse button, move the mouse to pan the scene.
Once the drawing is complete, right click on the ABlockTools component in PlaneScene and select "Save the blockades data" to save. If you are not satisfied, you can choose "Clear the blockades data" to clear the current blocking data.


Description in DemoSearch2:
Open the Demo/DemoSearch2 scene and run it. Similar to DemoSearch1, the camera is added to this demo to better reflect the effects of the move.
In addition, two character models are sent, including standing and walking.


API description:
The main classes are: JOMapGrid2DData and AJFindRoad
JOMapGrid2DData is blocking data management class
Which provides conversion of grid coordinates and world coordinates
AJFindRoad is a pathfinding algorithm class
Which provides a pathfinding api

Eg.
//Create two principal objects
JOMapGrid2DData mapGridData = new JOMapGrid2DData();
AJFindRoad ajSearch = new AJFindRoad();
//Set basic information about the grid
mapGridData.SetMapData(float mapW,float mapH,float mapOffsetX,float mapOffsetY,int cellW);
//mapW and mapH are the width and height of the map.
//mapOffsetX and mapOffsetY are the coordinates of the lower left corner of the grid.
//cellW is the side length of each cell.
//Block by grid subscript settings
mapGridData.SetBlockIdx(int blockIdx, bool isBlock);
//Blocking by the xy coordinate of the grid
mapGridData.SetBlock(int cellx, int celly, bool isBlock)

//Call the pathfinding algorithm and return the path.
List<JOIntV2>
ajSearch.Search(int beginX, int beginY, int endX, int endY, JOMapGrid2DData mapData);

Among them beginX, beginY and endX, endY are the network coordinates of the start and end of the pathfinding respectively.
mapData is the above data including blocking information.
The function will return List<JOIntV2>. If it is null, it will not work. If it is found, it will return to the network path.

Can also refer to
Setting processing of JOMapGrid2D in Demo/Scrips/DemoSceneBase.
Calls to JOMapGrid2D and AJFindRoad in Demo/Scrips/MoveGO.


Future Content
1. Further optimize performance and increase the interface of the local update area
2. Increase support for frame synchronization
Welcome to contact us


Unity Asset Store URL:

    https://assetstore.unity.com/packages/slug/142391


没有评论:

发表评论