Unity NavMeshAgent не достигает цели - передвигается - PullRequest
0 голосов
/ 31 мая 2019

Я создал простую сцену и сейчас пытаюсь заставить кролика переместиться в положение щелчка мыши на плоскости.

Итак, я добавил Rigidbody, Nav Mesh Agent и простой скрипт "Pathfinding" для кролика.

В Mesh Renderer для плоскостей установлено значение «Статическая навигация», «Генерировать OffMeshLinks» и «Проходимо»

Теперь, как только кролик приблизится к указанному месту назначения, он не остановится, а скорее "бегает" по очень маленькому кругу вокруг места назначения.

Вот мой сценарий

using UnityEngine;
using UnityEngine.AI;

public class Pathfinding : MonoBehaviour {

private NavMeshAgent agent;
private Animator animator;

// Use this for initialization
void Start() {
    agent = GetComponent<NavMeshAgent>();
    animator = GetComponent<Animator>();
}

// Update is called once per frame
void Update() {
    RaycastHit hit;

    if(Input.GetMouseButtonDown(0)) {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if(Physics.Raycast(ray, out hit)) {
            agent.SetDestination(hit.point);
            animator.SetInteger("AnimIndex", 1);
            animator.SetBool("Next", true);
        }
    }
}
}

и изображение моего кроличьего объекта;)

enter image description here

Ответы [ 2 ]

2 голосов
/ 31 мая 2019

Тормозной путь должен быть> 0

1 голос
/ 31 мая 2019

На самом деле я был не прав, обновление Unity не устранило проблему, но я понял, что проблема заключалась в том, что анимация "Root Transformation Position (XZ)" / Bake Into Pose была деактивирована.

Я также изменил свой скрипт на

using UnityEngine;
using UnityEngine.AI;

public class Pathfinding : MonoBehaviour {

private NavMeshAgent agent;
private Animator animator;

private bool run = false;

// Use this for initialization
void Start() {
    agent = GetComponent<NavMeshAgent>();
    animator = GetComponent<Animator>();
}

// Update is called once per frame
void Update() {
    RaycastHit hit;

    if(Input.GetMouseButtonDown(0)) {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if(Physics.Raycast(ray, out hit)) {
            Debug.Log("start");
            agent.SetDestination(hit.point);
            animator.SetInteger("AnimIndex", 1);
            animator.SetBool("Next", true);
            run = true;
        }
    }else if(agent.remainingDistance <= agent.stoppingDistance && run) {
        Debug.Log("stop");
        animator.SetInteger("AnimIndex", 0);
        animator.SetBool("Next", true);
        run = false;
    }


}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...