About the problem of Unity's automatic pathfinding detection to reach the target point

The project needs to detect the arrival of the target point and stop the character animation walking problem

1. First use the following code to detect remainingDistance is 0

if(agent.remainingDistance < agent.stoppingDistance){
    
    
// 移动终止
Debug.log(“移动结束了”);
}

2. After searching for the post, change it to the following, but the target point is still not detected

if(!agent.pathPending && agent.remainingDistance < agent.stoppingDistance){
    
    
// 移动终止
Debug.log(“移动结束了”);
}

3. Finally, the following code can be successfully detected

if (!agent.pathPending && agent.remainingDistance < 0.5f)
        {
    
    
            print("移动结束");
            animator.SetBool("isMoving", false);
        }

Guess you like

Origin blog.csdn.net/crush_oo/article/details/130169224