Steps to realize path finding:
1. Check static (ground and obstacles) for objects that are not moving in the scene,
Go to the window to bring up the Navigation window and click Bake to form a pathfinding (blue) grid.
2. For objects that need automatic path finding, add automatic path finding components.
Mesh Link bridging function, there is no grid connection between two points.
Nav Mesh Obstasle adds collisions to obstacles.
3. Add script
NavMeshAgent properties
Radius The collision radius of pathfinding
Height The collision height of the wayfinding
BaseOffset the location of the wayfinding collision
Speed The speed of the path finding object
Acceleration The acceleration when turning
AngularSpeed The angular velocity of the object when turning
StoppingDistance Stopping distance
AvoidancePriority
Baking properties for pathfinding
Radius refers to the radius between the path finding area and the obstacle
Height refers to the height between the path finding area and the ground
MaxSlope refers to the maximum slope baked in the pathfinding area
StepHeight refers to the height of the step
You can adjust these properties to set up slopes, stairs, etc.
Pathfinding system area mask
In addition to the system default three, you can customize the add area
Cost: Pathfinding area consumption. The larger the value, the greater the pathfinding area consumption.
When the consumption value of the path finding object is the same, it will choose the best (nearest) road to find the way, but if the consumption value of the path finding area is different, it will find the way according to the consumption value, the smaller the better.
Different roads can be designated corresponding areas
Bake wayfinding pavement
Find the object that needs wayfinding and set up an area that can walk on the wayfinding road
Check different pathfinding areas through code:
GetComponent<NavMeshAgent>().areaMask =9;
Each area of the path finding area is a power of 2
9 is Walkable area (1) + red area (8) = 9
Everything all areas-1
Nothing can't find path in any area 0
Space to switch walkable area↓
If there are more pathfinding objects, remember to add judgment in update to avoid double calculation. (For example, when the target is not moving)