News Forums RAIN General Discussion and Troubleshooting Choosing a random waypoint in a waypoint network.

This topic contains 4 replies, has 2 voices, and was last updated by  RainIsEpic 1 year, 4 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #39444


    Question: Is it possible to create a behavior tree that selects a random waypoint from a Waypoint Network without creating a custom action script node? What would the behavior tree and expressions look like?

    I was thinking:

    Random Node
    - Expression Node [varRandomLoc = navigationtarget("Waypoint 1")]
    - Expression Node [varRandomLoc = navigationtarget("Waypoint 2")]
    - Expression Node [varRandomLoc = navigationtarget("Waypoint 3")]
    - Expression Node [varRandomLoc = navigationtarget("Waypoint 4")]

    But your navigationtarget method only works on GameObjects found in the hierarchy, not those in your Waypoint Network component.
    Is there a method other than navigationtarget, maybe waypointnetworktarget?

    So the only way I can think of doing this is by a custom action code to retrieve the waypoints.

    public override ActionResult Execute(RAIN.Core.AI ai)
      //Script tested on Unity 5.1 with Rain 2.1.11
      //Get all of the waypoints in the Waypoint Network
      WaypointSet tWaypointSet= NavigationManager.Instance.GetWaypointSet("LightBlueNetwork");
      //Choose the index of a random waypoint in the waypoint network.
      int tWaypointIndex = Random.Range(0, tWaypointSet.Waypoints.Count);
      //Get a reference to the specific cooridinates of the waypoint.
      Vector3 tRandomWP = tWaypointSet.Waypoints[tWaypointIndex].Position;
      //Now initialize the Path Target for the Waypoint Path Node.
      ai.WorkingMemory.SetItem<Vector3>("varLocation", tRandomWP);
      //This will be passed onto your specific Waypoint Path Target variable for use in the move node.
      return ActionResult.SUCCESS;

    Thanks in advance!



    At this moment you can’t get to the waypoints through expressions. This is something we would like to have, but at the moment you will have to go with your custom action.



    Ah ok, just trying to not reinvent the wheel.

    My followup question.

    If I go with using Navigation Targets, that means I have to use a Waypoint Network node correct? Do I really care about how many waypoints are in the associated network if I don’t actually have my NPC moving to any of those waypoints?

    It seems it would make more sense to have a third type of node called a NavigationTargetCollection that simply works with NavigationTargets rather than thinking it needs a Network.

    It seems that many tutorials make people think that Networks automatically influence the path to a Navigation target just by themselves.

    Does that make any sense?



    If you use navigation targets you can use a waypoint network if you like, but it isn’t a requirement. If you use just a move node the AI will use a RAIN navigation mesh (if available) and create a path to the target.

    The common use for a waypoint network is to indicate to the AI that there are paths you would like it to take, like sidewalks and crosswalks vs just picking the shortest path to the target. So waypoint networks do indeed influence the path to a navigation target, it isn’t automatic though, you have to tell your AI to move through a waypoint network node so that it takes the waypoints into account while heading to the navigation target.



    Ah Sigil, I see what was causing my confusion and why my Waypoint Network was being ignored.

    Under the Waypoint Path node I had a move node. But the move node was set to the “Path Target” when it should have been the “Move Target Variable”. The “Move Target Variable” gets updated magically with the Network waypoints. It’s amazing and saves several lines of code.

    Nowhere in the Chapter 2 of Unity AI Programming Essentials Packt Book did it say to do this.

    You say it’s not automatic, but it’s pretty dang close! Thanks for the awesome features

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.