News › Forums › RAIN › General Discussion and Troubleshooting › Waypoint Network move target variable not working
This topic contains 5 replies, has 2 voices, and was last updated by prime 1 year, 3 months ago.
-
AuthorPosts
-
September 20, 2022 at 2:33 pm #33334
What am I doing wrong here? I have a waypoint network whose waypoints are generated at runtime. Then I have an AI that is looking for a random waypoint on the network route. I set the path and I can verify that it all works:
But then I add a move action and it fails:
Here is my code:
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Core; using RAIN.Action; using RAIN.Navigation; using RAIN.Navigation.Waypoints; [RAINAction] public class Wander_Alien : RAINAction { public override void Start(AI ai) { base.Start(ai); } public override ActionResult Execute(AI ai) { Vector3 randomWP = new Vector3(Random.Range(0,128),Random.Range(0,64),7); ai.WorkingMemory.SetItem<Vector3>("randomWP",randomWP); WaypointSet tWaypointSet=NavigationManager.Instance.GetWaypointSet("WPN_Alien"); ai.WorkingMemory.SetItem<int>("pathTarget",tWaypointSet.GetClosestWaypointIndex(randomWP)); return ActionResult.SUCCESS; } public override void Stop(AI ai) { base.Stop(ai); } }
Any suggestions would be greatly appreciated. Thanks!
- This topic was modified 1 year, 3 months ago by g4m3ninja.
September 20, 2022 at 2:35 pm #33335Sorry those screen shots didn’t come through… I’ll do it this way:
- This reply was modified 1 year, 3 months ago by g4m3ninja. Reason: images not working
September 21, 2022 at 2:17 pm #33339I also replaced the BT with one much simpler - a single move action just to make sure I have everything set up right for movement. That worked fine. Maybe I’m not understanding how Waypoint Network and the Waypoint Path node works. So here are some questions:
1) Will Waypoint Network work without a Nav Mesh?
2) I have Allow 3D movement checked and Valid Path Required unchecked. Is this right?
3) In the Waypoint Path node on the BT, if I properly assign the Waypoint Network and the Path Target, it should store the next sequential waypoint in the Move Target Variable. Do I have that right?- This reply was modified 1 year, 3 months ago by g4m3ninja.
September 23, 2022 at 11:34 pm #33349Hmmm. Answers…
1) Yes, waypoint networks/routes are independent of NavMesh.
2) I suspect you don’t want Allow 3D movement, unless you will be moving off the terrain. Leaving Valid Path Required unchecked is fine if you aren’t using a NavMesh.
3) This is probably the issue. The PathTarget and the MoveTarget need to be positions, not indices of waypoints. moveToWP will be assigned automatically, and you can use the result directly in your Move node, so you are fine there. However this line:ai.WorkingMemory.SetItem<int>("pathTarget",tWaypointSet.GetClosestWaypointIndex(randomWP));
should probably instead be
ai.WorkingMemory.SetItem<Vector3>("pathTarget", randomWP);
If you want an actual waypoint instead of a random position, then:
int tWaypointIndex = Random.Range(0, tWaypointSet.Waypoints.Count); Vector3 tRandomWP = tWaypointSet.Waypoints[tWaypointIndex].position; ai.WorkingMemory.SetItem<Vector3>("pathTarget", randomWP);
September 24, 2022 at 7:12 pm #33355Thanks, Prime. I tried implementing the changes above, but unfortunately I’m still having the same issue with the move action failing. Can’t figure out why.
September 25, 2022 at 10:36 pm #33356Feel free to send over a project if you want us to take a look at it.
-
AuthorPosts
You must be logged in to reply to this topic.