Search Unity

Shortest path to building

Discussion in 'Navigation' started by ardo314, Mar 13, 2018.

  1. ardo314

    ardo314

    Joined:
    Jul 7, 2012
    Posts:
    345
    My goal is to move a unit as close as possible to a building.

    The problem I'm facing is, that if i use the center of the building as the target position for NavMesh.CalculatePath the resulting path is invalid and no corners are provided because the area of the building is not walkable.

    Now I can use SamplePosition to find a point on the NavMesh but that doesn't yield the shortest path to that building.

    The only option I can think of is to calculate multiple paths to all the sides of the building but that seems rather wasteful.

    Any tips?
     
  2. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    I'm pretty sure that the NavMesh.SetDestination just finds the closest path, couldn't you just set the destination to the objects transform, and it will try to get as close to said object as possible?

    Sorry if this doesn't help - I'm in a bit of a pinch and can't post a full set of solutions.

    Kind Regards,

    Miggi124
     
  3. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I remember someone with a similar issue. Can you provide a little more info on your setup, specifically what components are on the building? I'm assuming you put a collider and a NavMeshObstacle on it, is that correct?