playMaker

Author Topic: Path Finding Issues [SOLVED]  (Read 799 times)

Athin

  • Full Member
  • ***
  • Posts: 102
    • View Profile
Path Finding Issues [SOLVED]
« on: May 20, 2018, 05:26:06 AM »
Hey everyone!

I'm having a hard time finding a solution to this one and was hoping for some help/guidance on it.  My issue is currently I have AI that when spawned, they will actively seek out a job. (Find a farm to get food, or lumber mill for Wood ect.)  Once they get hungry or tired, they will return home to refill and back to work they go.  Everything is working currently but the issue is pathing.  Since objects are dynamically placed in the world, I can't Bake the scene (That I know of) each time a new building is placed/destroyed.  I only have a simply Move to action to get the job done currently but that tends to lead to "wall humping"until they get around any object in their path.  Would anyone have any idea or direction I should look into this?

Thanks
« Last Edit: May 23, 2018, 05:57:59 PM by djaydino »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • View Profile
Re: Path Finding Issues
« Reply #1 on: May 20, 2018, 08:12:21 AM »
You can now dynamically bake navmesh at runtime with Unity. I made a video here about how to do it:

Wolfride

  • Playmaker Newbie
  • *
  • Posts: 11
    • View Profile
Re: Path Finding Issues
« Reply #2 on: May 20, 2018, 04:25:20 PM »
If dynamic baking doesn't solve it, you could also tag the colliders of your walls/problem objects and parent a second, bigger collider to your NPCs. Make it a trigger. Because it is bigger than the physics collider, it will fire before contact with problem objects and only look for those.

With this there is a number of things you could do in order to get your characters back on track, most involving rerouting with raycasting. But it's a start if you just can't use the obvious solution linked above. :)

Athin

  • Full Member
  • ***
  • Posts: 102
    • View Profile
Re: Path Finding Issues
« Reply #3 on: May 21, 2018, 05:40:56 AM »
You can now dynamically bake navmesh at runtime with Unity. I made a video here about how to do it:

I followed this video and gave it a shot.  I believe this will work but I just can't seem to get it to work :(  I threw up a Local Nav Mesh Builder script over my terrain and place the Nav Mesh Source Tag on a house the player can build.  I don't seem to get any errors but the units still don't path around the house and proceed to go head first into the door X(.  I know the video is adding in the Navmesh but I'm assuming it will cut out the pieces when placing bigger objects? (Couldn't tell in the video).

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • View Profile
Re: Path Finding Issues
« Reply #4 on: May 21, 2018, 10:20:59 AM »
Make sure that it is working. Change to the navigation tab in the editor. This should show the navmesh areas. Blue by default. Then you can see if the navmesh has changed and if it changed correctly. (Keep the editor display open on one side, and the game display on another, with the navigation tab open).

Then you can figure out of you need to adjust your agents or the navmesh settings.

Athin

  • Full Member
  • ***
  • Posts: 102
    • View Profile
Re: Path Finding Issues
« Reply #5 on: May 22, 2018, 04:05:45 AM »
Playing around with it a bit more I can see that the system is working but not the way I was hoping.  It seems to not carve out an area around the newly place object from previously navmesh leading them to smack right into it.

I've attach a screen shot of the problem.  The big wall is baked into the scene where as the white platforms were dynamically created in the scene.  You can see my purple unit is still grinding into the platforms rather then going around them.

Sorry for all the questions.  Still fairly new to the whole pathing scene so got a bit of a learning curve I'm trying to get over.

Thanks


Athin

  • Full Member
  • ***
  • Posts: 102
    • View Profile
Re: Path Finding Issues [SOLVED]
« Reply #6 on: May 23, 2018, 04:41:57 AM »
Playing around with it I discovered my problem and how I fixed it so figured I'd post.  What was giving me so much trouble was the fact that I pre-baked the terrain and then added in the platforms dynamically.  It seems that anything pre-baked into the scene will not get altered dynamically.

I simply just undid the bake on the terrain and added the script tag onto it.  Now the ground will dynamically change while new prefabs are added! 

Thanks for the help guys!