Laya commercial-level tutorial series-5 minutes to learn the pathfinding solution (A star pathfinding)

Personal profile :
game front-end development, 6 years of experience, focus on game development, proficient in unity3d, LayaAir engine, developed multiple products, more than 6 million users
Tencent classroom, Thai lesson online lecturer

Laya commercial grade tutorial-5 minutes Laya-A star pathfinding solution

Laya commercial grade tutorial series-A star pathfinding solution

The path finding function is an essential skill for developers. In this issue, we spend 5 minutes mastering how to use the path finding function in LAYA

First, we open the Laya project and the u3d project in the material package separately

The plug-in download address and case source code are at the bottom of the article

We open the prepared LAYA project and U3D project in the
material. The LAYA project only contains characters and scenes.
Our goal is to realize that the characters move around the obstacles and move to the clicked position.

Step 1: Import the pathfinding plugin

Step 2: Configure the pathfinding graph

Step 3: Call the pathfinding API

The pathfinding algorithm uses the pathfinding.js
github address: https://github.com/qiao/PathFinding.js/

The second step details:
Creating the scene Gameobject named astarMap, add components Pathfinder, add Grid Graph,
first set the length and width to 0,0, 0,0 center point (this step can not be omitted, the back will do a detailed explanation)
settings Change the length and width to 9X9
Insert picture description here
connections to four
Insert picture description here
non-walkable node configuration, set the collision testing Mask to obstacle, and add a collision body for the roadblock object, and set it to the obstacle layer.
Insert picture description here
Insert picture description here
Click to generate data

export data

Add the component
AstartExpLayaTool, click exp json (export json data)
Insert picture description here
to return to the code editor, and assign map dataInsert picture description here

Compile and run
Insert picture description here

Note:
Solve the problem that the WeChat platform cannot recognize the class library.
Insert picture description here
Edit the class library initialization process Insert picture description here
. The requirements for map production;
for performance reasons, the map and the world coordinates adopt a one-to-one correspondence relationship. The purpose is to reduce the coordinate conversion process.
So the
unit The grid size must be the default value 1, and the pathfinding map must be in the first quadrant. The
Insert picture description here
course materials can be downloaded from the group or official account
Insert picture description hereInsert picture description here

Guess you like

Origin blog.csdn.net/koljy111/article/details/108296954