Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

placement blocking @ runtime

Discussion in 'Navigation' started by sgtDaniele, Aug 3, 2022.

  1. sgtDaniele

    sgtDaniele

    Joined:
    Sep 7, 2021
    Posts:
    2
    Hello everyone,


    I am pretty new in this so please bear with me, I tries also to search online for this topic but unfortunately could not find something similar. I appreciate every bit of help.


    I am doing a project where waves of enemies go from point A to B.

    In the time the enemies spawn and walk, you can build on the Terrain, and the enemies still go to point B and do not collide with the buildings. My issue or what I cannot Figure out at the Moment is , how to make it possible so that the Player cannot block the way of the path completely . Meaning that at least 1 placement needs to be free so that the enemies can walk and evade collision with the Building.

    I tried to do it with navmesch at runtime, Works well just the blocking part I am stuck and do not know how to go about that. Is there a magic way to do this?


    Thank you so much for any advice


    Best Regards
     
  2. DejaMooGames

    DejaMooGames

    Joined:
    Apr 1, 2019
    Posts:
    108
    Whenever a player is about to build you could drop a nav mesh obstacle in the place they want to build and then use NavMesh.CalculatePath() and pass in your positions A and B. If the calculated path is partial the Ai is blocked and you can prevent your player from building there.
     
    sgtDaniele likes this.
  3. sgtDaniele

    sgtDaniele

    Joined:
    Sep 7, 2021
    Posts:
    2
    Thank you so much , I am going to try that.