I have a simple scene like this:
scene
plane position: (0, 0, 0)
cube position: (0, 8, 0)
cube (1) position: (0, 8, 3)
And I attach the following mono script to the cube (1), and set the radius as 10 < /p>
using System.Collections;
using System.Collections.Generic;
using DefaultNamespace;
using UnityEngine;
using UnityEngine.AI;
public class TestNavMesh : MonoBehaviour
{
public bool Sample = false;
public float Radius = 10;
public int amount = 10000;
NavMeshType navMeshType = new NavMeshType();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Sample)
{
Sample = false;
NavMeshHit hit;
if(NavMesh.SamplePosition(transform.position, out hit, Radius, NavMesh.AllAreas))
{
Debug.Log("hit.position: " + hit.position);
Debug.DrawRay(gameObject.transform.position, hit.position - transform.position, Color.red, 5);
}
}
}
}
< /code>
Когда я запускаю сцену, если выборочная опция проверяется, она займет положение куба (1) в качестве центра, радиус как максимальное расстояние, найдите точку Navmesh, ближайшую к кубу (1) и нарисуйте линию. рисует линию от куба до самолета. Почему? На кубе есть более близкие точки.>
Подробнее здесь: https://stackoverflow.com/questions/794 ... -to-the-ta
NAVMESH.SamplePosition не возвращает ближайшую точку на Navmesh в цель? ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение