Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using A*Pathfinding on terrain created by scripts?

Discussion in 'Scripting' started by Testnia, Jul 30, 2014.

  1. Testnia

    Testnia

    Joined:
    Jul 4, 2014
    Posts:
    11
    Hi, I'm looking to use A* Path-finding as a method of navigating my game terrain. Trouble is, my terrain is built upon play using a script and A* grid does not detect this, therefore marking all nodes as "un-walkable".

    I'm wondering if anyone knows a solution for this or an alternative path finding method. I have tried enabling the terrain to spawn on edit more using ExexcuteInEditMode, but this does not seem to work either.

    The terrain was generated through a fantastic guide called Procedural Terrain Tutorial.

    Would greatly appreciate any help I'll be able to get.

    I've attached some screenshots for clarity :

    Snapshot.PNG
     
  2. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Just have a your terrain creation script call this when it's done creating the terrain!
    Code (CSharp):
    1. AstarPath.active.Scan()
     
  3. Testnia

    Testnia

    Joined:
    Jul 4, 2014
    Posts:
    11
    Hi thanks for the tip, I've included the code proposed and it seemed to have work although it required me to check 'Unwalkable when..." in the Height Testing menu. Do you suppose this will cause issues as I progress on? Thanks for the apt reply!
     
  4. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    No it basically just says that if the raycast didn't hit anything set the node to unwalkable there, say you had a lower ground that's 400 units below the ground level and you need to be able to walk there just increase the ray length.