News › Forums › RAIN › General Discussion and Troubleshooting › Choosing a random waypoint in a waypoint network.
Tagged: waypoint network
This topic contains 4 replies, has 2 voices, and was last updated by RainIsEpic 1 month, 1 week ago.
-
AuthorPosts
-
November 11, 2022 at 1:54 pm #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")] //etc.
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!
November 11, 2022 at 2:16 pm #39447At 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.
November 11, 2022 at 5:00 pm #39453Ah 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?
November 12, 2022 at 10:47 am #39455If 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.
November 12, 2022 at 7:10 pm #39457Ah 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
-
AuthorPosts
You must be logged in to reply to this topic.