News Forums RAIN General Discussion and Troubleshooting Waypoint Path doesn't work…


This topic contains 3 replies, has 2 voices, and was last updated by  CodersExpo 1 year, 10 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #25927

    I have a 2 minute video I posted that shows the issue I’ve posted here, I assume with a bit more clarity.

    I built a WayPoint Route. With a start and end point.

    When working in the behavior tree, I can successfully get it to move around. with a “Choose Patrol Waypoints” (Ping Pong, Loop and One Way work)

    If I use a “Choose Path Waypoints” instead, it fails.

    For the Path, I create a Waypoint Network called “PathOther”, with 3 points. The last waypoint is called “End”
    I set the waypoint Network to “PathOther” I set the path Target to “End”, but it essentially freezes after 1 step.

    Any thoughts?



    Assigning the waypoint name to path target won’t work. You would want a vector3 position variable. Ideally, the navigation path is used for random pathing behavior.

    When you want your character to move along a predetermined path repeatedly, waypoint path works great. If you want your ai to wander around an area in a more unpredictable fashion, waypoint navigation is used.

    The variable assigned should be dynamic. You could create a variable vector3 path target position for the ai to move to and when he has arrived update the variable to a new position. The ai will use the path network as a guide while the final goal will always be the path target variable.

    If you haven’t watched the getting started tutorials, be sure to check them out here the 3rd and 4th video covers waypoint navigation and uses a script to generate a random value that is used in the Path Target field of the waypoint network node.

    I modified that script a bit to account for rough terrain by adjusting the Y coordinate ensuring it is always flush to the surface. Below is my modified script but I suggest watching the video and getting that example to work first.

    /*In this example be sure to add a navigation target component to your scene. Mine is named “PointPosition”
    This is good so you can visually see where the random point is being generated.
    Additionally, I’m setting ai.Kinematic.Position.y + 10f up high and then setting it flush with the surface to ensure
    the target node never ends up under the ground or to high up in the air for the character to move to.

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Core;
    using RAIN.Action;
    using RAIN.Navigation;
    using RAIN.Navigation.Graph;
    public class ChooseRandom : RAINAction
    	private RAIN.Navigation.Targets.NavigationTarget _target;
        public ChooseRandom()
            actionName = "ChooseRandom";
        public override void Start(AI ai)
    		_target = NavigationManager.Instance.GetNavigationTarget("PointPosition");
        public override ActionResult Execute(AI ai)
    		Vector3 loc =;
    		List<RAINNavigationGraph> found = new List<RAINNavigationGraph>();
    			loc = new Vector3(ai.Kinematic.Position.x + Random.Range(-5f, 5f),
    			                  ai.Kinematic.Position.y + 10f,
    			                  ai.Kinematic.Position.z + Random.Range(-5f, 5f));
    			found = NavigationManager.Instance.GraphsForPoints(
    		} while ((Vector3.Distance(ai.Kinematic.Position, _target.Position) < 2f) || (found.Count == 0));
    		ai.WorkingMemory.SetItem<Vector3>("wanderTarget", _target.Position);
            return ActionResult.SUCCESS;
        public override void Stop(AI ai)
    	private void setFlushToSurface(Vector3 targetPosition)
    		var v = RAIN.Utility.MathUtils.CastToCollider(targetPosition, Vector3.down, 0f, 1000f);
    		var vv = v - _target.Position;
    		if(vv.magnitude > 0f)
    			_target.Position = v;

    Hope this helps.


    Thanks, I had a few misconceptions about how this all worked. watching through more of that series really helped.



    It is a learning process for sure but hey we got your back! That’s what a community support forum does

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

You must be logged in to reply to this topic.