@Ad1yar

Почему боты не хотят идти по точкам?

Бот не хочет идти по точкам, я уже не знаю что делать все перерыл везде такой же метод используют как и я
вот код:
public class NextBots2 : MonoBehaviour
{
    public NavMeshAgent navMeshAgent;
    public Transform player;

    public static int difficult = -1;

    public Transform door;

    public Transform[] points;

    [SerializeField] private int currentPoint;

    void Start()
    {
        currentPoint = -1;
        navMeshAgent = GetComponent<NavMeshAgent>();
    }

    void Update()
    {
        CheckPlayerOnRoom();

        if (currentPoint != -1)
        {
            navMeshAgent.SetDestination(points[currentPoint].position);
        }

        if (navMeshAgent.remainingDistance < 0.5f)
        {
            currentPoint++;
        }

        if (currentPoint >= points.Length)
        {
            currentPoint = 0;
        }

        print(currentPoint);

        difficult = Settings.diff;

        if (difficult == 0) navMeshAgent.speed = 5f;

        else if (difficult == 1) navMeshAgent.speed = 7f;

        else if (difficult == 2) navMeshAgent.speed = 9f;

        else if (difficult == 3) navMeshAgent.speed = 11f;
    }

    void CheckPlayerOnRoom()
    {
        if (Check.playerOnRoom && door.transform.rotation == Quaternion.Euler(0, -90, 0))
        {
            if (currentPoint == -1) currentPoint = 0;
        }

        else
        {
            currentPoint = -1;
            navMeshAgent.SetDestination(player.transform.position);
        }
    }
}
  • Вопрос задан
  • 258 просмотров
Решения вопроса 1
@Ad1yar Автор вопроса
решено вот код(лишнее убрал):
public NavMeshAgent navMeshAgent;
    public Transform player;

    public Transform[] points;

    [SerializeField] private int currentPoint;

    void Start()
    {
        currentPoint = 0;
        navMeshAgent = GetComponent<NavMeshAgent>();
    }

    void Update()
    {
        CheckPlayerOnRoom();

        if (navMeshAgent.remainingDistance < 1f)
        {
            currentPoint += 1;
            if (currentPoint >= points.Length) currentPoint = 0;
            navMeshAgent.SetDestination(points[currentPoint].position);
        }
    }

    void CheckPlayerOnRoom()
    {
        if (Check.playerOnRoom && door.transform.rotation == Quaternion.Euler(0, -90, 0))
        {
            if(currentPoint == 0) navMeshAgent.SetDestination(points[1].position);
        }

        else
        {
            currentPoint = 0;
            navMeshAgent.SetDestination(player.transform.position);
        }
    }
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы