News Forums Search Search Results for 'waypoints'

Viewing 15 results - 1 through 15 (of 347 total)
  • Author
    Search Results
  • #39837

    Cyrawnis
    Participant

    Hello everyone,

    I’m fairly new to Rain, and I seem to be having trouble returning the velocity of an object’s rigidbody.

    What I am trying to do:
    - Create a cube as the navigator
    - Create Rain Navigation Mesh
    - Attach an ai and rigidbody to the cube
    - Use the ai to walk along a route set up by waypoints <- This is working properly
    - Use the rigidbody on the cube so that I can get the velocity of the cube <- Not working properly. It is always returning zero.
    - I need the velocity of the cube so that I can tell what direction it is going on the xz axis. I don’t care what direction it is facing, just the direction it is moving towards North, South, East, West.

    This will be used to position the second object at the same position as the cube and play animations depending on what direction the cube is moving. The position works, I just can’t get the velocity to work when using rain. It works with a regular navigation mesh with a nav mesh agent, but not a Rain mesh with a rigidbody.

    I appreciate the help,

    Cyrawnis

    • This topic was modified 1 day, 1 hour ago by  Cyrawnis.

    Coburn64
    Participant

    Hi there,

    I’ve been following the tutorials that a person on YouTube who goes by the username “CodersExpo” released for public viewing. I’ve been adapting his tutorial into a follower/companion AI for a brawler type game I’m working on.

    In his video, he uses two visual sensors to find the player. However, I would like to change this to using a expression (Vector3.Distance(a, b) ?) so that rather than using a visual sensor, if you’re within say 1 unit of the AI, it will pause it’s navigation towards you. This would stop AI jitter, where the AI will approach the target, back off a little, approach, back off, etc.

    I’m not sure how to do it though. Do I need to make a custom action to return a value, and if so, what would I write in the custom action code? He explains how to make a “wander” behavior which is good for NPCs that are just filler, but trying to modify that script just seems to break things. Here’s a code dump. A lot of it may be redundant, but I basically retyped it from his video. (It seems that it actually fails instead of success…?)

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using RAIN.Navigation;
    using RAIN.Navigation.Graph;
    [RAINAction]
    public class FollowPlayer : RAINAction
    {
        Vector3 playerPosition = Vector3.zero;
        float distanceBetweenMeAndPlayer = 0f;
        public override void Start(RAIN.Core.AI ai)
        {
            base.Start(ai);
        }
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
            playerPosition = ai.WorkingMemory.GetItem<Vector3>("varPlayer");
            var found = new List<RAINNavigationGraph>();
            do
            {
                found = NavigationManager.Instance.GraphsForPoints(ai.Kinematic.Position, playerPosition, ai.Motor.MaxHeightOffset, NavigationManager.GraphType.Navmesh);
            } while ((Vector3.Distance(ai.Kinematic.Position, playerPosition) < 0.5f) || (found.Count == 0));
            ai.WorkingMemory.SetItem<Vector3>("varFollowPlayerTarget", playerPosition);
            return ActionResult.SUCCESS;
        }
        public override void Stop(RAIN.Core.AI ai)
        {
            base.Stop(ai);
        }
    }

    The current setup is this:

    1. AI has 2 sensors - General Purpose (can see what’s in front of it) and Near (1 unit in front of the AI).
    2. AI Patrols a route defined using Waypoints.
    3. If AI can see the player, then it stops patrolling and paths a route to the player.
    4. If Player is inside the “near” sensor area, the AI will stop and look at the player.
    5. If Player walks outside the “near” sensor area, the AI will try to follow the player, but if the player gets too far away it will go back to patrolling.

    My intended setup is this:

    1. AI has one visual sensor so it can see things in front of it.
    2. AI patrols until it sees the player. It registers the player in memory as our target.
    3. AI calculates the distance between itself and the player.
    4. If distance above X units, then navigate to the player.
    5. If distance below/equal X units, then pause.

    Ultimately, I want the AI to be able to stay put, so I can for example, walk around it within 1 unit without it suddenly walking off because “Oh, player moved out of my range, I’m going back to patrol logic”.

    I’m still green with RAIN, but any snippets are welcome.

    Cheers!

    #39524

    GBCoder
    Participant

    I have just started using RAIN, and a similar thing is happening. I had my NPC following waypoints, but when I added the animation, they completely stopped.

    This happened when I added an animation state to the animator in the AI Rig. The it wouldn’t move any after I added the “Walk” animation. When I deleted it from the Animator, the NPC started workin as it should. (not animated though)

    Try removing those animations and see if maybe that’s what’s causing your problem also.

    -David

    #39457

    RainIsEpic
    Participant

    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

    #39455

    Sigil
    Keymaster

    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.

    #39453

    RainIsEpic
    Participant

    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?

    #39447

    Sigil
    Keymaster

    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.


    RainIsEpic
    Participant

    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!

    #39434

    kilfeather94
    Participant

    Sorry, I should have been more specific. I actually do have Line of Sight checked already. It doesn’t seem to work though. I’ve enabled and disabled the wall’s layer in the line of sight mask and it makes no difference. Also the enemy can’t seem to navigate around walls. He’ll just keep walking into the wall, even when patrolling waypoints.

    #39432

    RainIsEpic
    Participant

    Thanks to Virtual and Prime for the discussion.

    I wanted to summarize the Chapter 2 issues in Curtis Bennett’s book: Unity AI Programming Essentials.

    page 25 - Bennett says to create a Waypoint Network and how to link waypoints but forgets to tell you to rename it as PatrolNetwork.

    page 26 - He says the Waypoint expression should be:

    location = navigationtarget(Location1)

    however it should be

    location = navigationtarget("Location1")

    As discussed above, Location1 is a string literal being the name of a GameObject in the hierarchy. navigationtarget is the name of a method in the Rain framework, and it requires a string as a parameter.
    Documentation about this method can be found here Rival Theory navigationtarget documentation

    page 27 - Bennett forgets to tell you that you need to set the Returns property on the waypoints from Evaluate to Success. What’s funny is that they are bright green in the figure, but nowhere does Bennett indicate that this should be set.
    Also weird is that he names the Expression NodeType as “Choose Location 1″ but then mysteriously renames them the same as the expression location = navigationtarget(“Location1″) in the figure at the bottom of page 27. *shrug*

    Small Note: If you are using Mecanim and only have one animation, you should probably uncheck root animation, and there’s no need to add an animate action.

    Overall I’m glad I got the book, it introduced me to RAIN and that’s awesome.

    #39380

    inform880
    Participant

    I unexpectedly figured it out. I made a waypoint path and got the closest navtarget in that. Here’s the code in case anybody else needs to do this:

    public override void Start(RAIN.Core.AI ai)
    {
    	navTargets = NavigationManager.Instance.GetWaypointSet("escape");
    	gotoPos = navTargets.GetClosestWaypoint (ai.Kinematic.Position);
    	ai.Motor.MoveTo (gotoPos.Position);
            base.Start(ai);
    }
    • This reply was modified 2 months, 2 weeks ago by  inform880.

    inform880
    Participant

    Hi,

    I absolutely love RAIN and have had some reasonable success with it so far, but I’m having a problem finding navigation targets in my code. I am trying to make a custom action that goes to the closest navigation target. I’m missing the code that takes the navigation targets and puts it into my

    private WaypointSet navTargets

    variable. This is my custom action so far:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using RAIN.Navigation;
    using RAIN.Navigation.Waypoints;
    [RAINAction]
    public class GotoClosestWaypoint : RAINAction
    {
    	private WaypointSet navTargets;
    	private Waypoint gotoPos;
        public override void Start(RAIN.Core.AI ai)
        {
    		gotoPos = navTargets.GetClosestWaypoint (ai.Kinematic.Position);
    		ai.Motor.MoveTo (gotoPos.Position);
            base.Start(ai);
        }
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
    		if (ai.Kinematic.Position == gotoPos.Position)
    			return ActionResult.SUCCESS;
    		else
    			return ActionResult.RUNNING;
        }
        public override void Stop(RAIN.Core.AI ai)
        {
            base.Stop(ai);
        }
    }
    • This topic was modified 2 months, 2 weeks ago by  inform880.
    #39333

    Sigil
    Keymaster

    1) Dividing your navigation mesh up is a good idea, as most of the time AI doesn’t need to path across the entire world and spends most of it’s time in a dedicated area. When it does path across the world it’s usually a special case and should be treated as such. By default the AI will use any graph that it is on, so there isn’t a need to assign graphs in that sense.

    2) I think wide open spaces would be better served using sensors to detect random obstacles. You can use smaller navigation meshes in areas where it gets complicated.

    3) If you want to use a Navigation Mesh for your flying enemies you can. You should enable 3D movement on the motor (and 3D rotation if you desire) and they will fly directly to the waypoints but use the Navigation Mesh below.

    So in a couple places you mentioned assigning Navigation Meshes, the way RAIN supports this is through Graph Tags. On any RAIN component go to the component menu (gear icon in the upper corner of the component) and select Show Advanced. Now on the Basic Navigator you will see Graph Tags, and on any Navigation Mesh you will also see Graph Tags.

    An AI will walk on any Navigation Mesh that matches any of its tags (or if it has no tags), so if an AI has a “flying” tag he will only work on Navigation Meshes that also have a “flying” tag. If you want an AI to ignore a particular Navigation Mesh you will need to assign at least one tag to the AI that isn’t on the Navigation Mesh. So you could imagine you have several Navigation Meshes tagged “ground” and several tagged “air” with AI that have similar tags, this would isolate them to their respective graphs.


    FireproVoltron
    Participant

    Hello, I’m currently trying to use a Waypoint Network to move my enemy character around. The player will have the power to obstruct the path of the enemy in some way which I am trying to implement as deleting the connections between waypoints in the network. Unfortunately, when deleting these connections, the enemy character will continue on the path anyway.

    I’m trying to write a custom action to fix this so that each time the enemy reaches a node, they will check for a valid connection between the waypoint they are currently at and the one that lies next on the path. I have the check figured out, but I’m just wondering if there’s some easy way to have the enemy re-plan his path. Thank you for any help you can offer!


    alchi baucha
    Participant

    I have a Waypoint network; that is working fine. But what i wanted was to be able to make decisions on CHOOSING BETWEEN THE MULTIPLE NODES(Waypoints) that originates from the same node using the user input. Any help is deeply appreciated.

Viewing 15 results - 1 through 15 (of 347 total)