Z
Z
Zefirot2021-08-15 13:57:57
C++ / C#
Zefirot, 2021-08-15 13:57:57

Is it possible to get paths from NavMesh?

I have several static objects, other objects move between them, since there are obstacles between them, NavMesh is used to find the path, something like this (2D)

MeshAgentPath = new NavMeshPath();
NavMesh.CalculatePath(TargetA.transform.position, TargetB.transform.position, NavMesh.AllAreas, MeshAgentPath);
if(MeshAgentPath.status == NavMeshPathStatus.PathComplete){
  TargetCell = TargetB;
  MeshAgent = GetComponent<NavMeshAgent>();
  MeshAgent.updateRotation = false;
  MeshAgent.updateUpAxis = false;
  MeshAgent.SetDestination(TargetCell.transform.position);
  }
...............
void Update(){
  if(Vector3.Distance(transform.position, TargetCell.transform.position) > 0.5f){  
    .......
    }else{........ // end way

While there were few objects, then nothing, but when there were more than 100 objects constantly moving, the battery began to warm up on a weak phone, and it’s noticeable that it strains more ...

Considering that the objects between which other objects move are static, maybe somehow can you first get all possible paths between them from NavMesh and drive them somewhere into variables?
I think this would greatly unload the process, they do not need to constantly look for a path as they move, only initially.
Or if you can tell me what else can be done in this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2021-08-18
@Zefirot

You can store paths from

NavMeshPath.corners
public Vector3[] corners;

for example, in
Dictionary<GameObject, ListVector<Vector3>> // <цель, точки_пути>

When you call CalculatePath(), all this data is there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question