Search Unity

Owner of "nextOffMeshLink"

Discussion in 'Navigation' started by Apfelrippchen, Jul 7, 2020.

  1. Apfelrippchen

    Apfelrippchen

    Joined:
    Aug 1, 2014
    Posts:
    1
    Heyho,
    I'm currently trying to get my "Enemies" to run towards the Player and, if neccessary, destroy "destroyable" obstacles on the way if it is beneficial for the enemies.

    TLDR: Is it possible to access the GameObject/Owner of the next NavMeshLink/OffMeshLink a NavMeshAgent will use/traverse?​

    The situation: The Player can place Walls. These walls consist of a NavMeshObstacle and create a NavMeshLink on instantiation. This link allows the enemies to see the wall as traversable link with respect to increased cost in case of usage (destroying). The enemies start attacking the wall as soon as they are on the NavMeshLink. In this case they get the reference to the GameObject of the wall by using currentOffMeshLinkData. This works as intended and is ok.

    My problem: Some enemies have certain attack range. For these enemies it is possible to attack the Wall without standing on the NavMeshLink. But because they are not standing on the NavMeshLink, the call to "nextOffMeshLinkData.offMeshLink" results in null and i can not determine if the enemy is close enough to the wall to attack it.

    My questions:
    1. Is there a way to somehow get a reference to the GameObject of the next link (nextOffMeshLink) an enemy will pass on his Path?
    2. Is my approach for this mechanic (enemies can destroy obstacles if it benefits them) the right one?

    Thanks in advance! :)


    The image displays the NavMesh, which is cut by the obstacle (wall) and the NavMeshLink area (in light-blue under the wall)
    upload_2020-7-7_19-32-22.png

    Edit 1: Added TLDR
     
    Last edited: Jul 8, 2020