News Forums Search Search Results for 'waypoints'

Viewing 15 results - 16 through 30 (of 347 total)
  • Author
    Search Results
  • #39279

    Sigil
    Keymaster

    To answer your previous questions:

    1) Repeat forever essentially means that if the node ever returns anything other then running it will reset and start again. So if you have something like this:

    sequencer
        sequencer (repeat forever)
            timer (seconds: 5)
            expression (expresson: debug("times up"), returns: success)
        expression (expression: debug("never gonna get here"), returns: success)

    It will display “times up” in the console every 5 seconds, and much like the message says, it will never get to the second expression.

    2) Yes, repeat until success will repeat the node until it returns success, but I think you got that figured out based on your message.

    Repeating can be useful if you want to hold the AI in a state until something happens. I often use this pattern when waiting to detect the player:

    sequencer
        parallel (succeed: any, fail: any, tie breaker: fail)
            detect (repeat: until success, aspect: "player")
            waypoint patrol (waypoint route: "waypoints", move target variable: waypointTarget)
                move (move target: waypointTarget)
        expression (expression: debug("detected the player"))

    So this tree will patrol until the AI detects a “player” aspect. So if the player never comes around, it will patrol forever.

    Check out the starter kit to see more examples of similar behavior and come back with any questions.


    JZTym
    Participant

    Hello, everyone!

    Been trying to create a simple traffic system using RAIN AI.

    I plan to make cars travel along a set of waypoints that I intend to use as the “road”.
    I also wanted it so that they stop when they detect another car in front of them
    However, I’ve been having problems trying to get the AI to continue moving to the next waypoint.

    Somehow when they are less than halfway through to the next waypoint and they are interrupted
    by the car in front, they return to their previous waypoint. When they are more than halfway
    through, they skip the current waypoint and moves to the next.

    I’m having a hard time looking for more information in the wiki and would like some help.

    Thanks in advance!

    Here is a gif depicting my problem.
    Waypoint Patrol bug.

    Here is a picture of the behavior tree I used.
    Behavior tree

    Here is the XML export of my Behavior Tree.

    <behaviortree version="1.1" repeatuntil="" name="Car2BT" debugbreak="False">
    	<sequencer usepriorities="False" repeatuntil="" name="root" debugbreak="False">
    		<parallel tiebreaker="fail" succeed="all" repeatuntil="" priority="" name="parallel" fail="any" debugbreak="False">
    			<detect sensor=""Car Sensor"" repeatuntil="running" name="detect car" matchtype="best" entityobjectvariable="frontCarForm" debugbreak="False" consistent="True" aspectvariable="frontCarAspect" aspectobjectvariable="frontCarMountPoint" aspect=""Car"" />
    			<waypointpatrol waypointsetvariable=""TrafficPath"" waypointactiontype="patrol" traversetype="loop" traverseorder="forward" repeatuntil="" pathtargetvariable="" name="waypointpatrol" movetargetvariable="moveTarget" debugbreak="False">
    				<selector usepriorities="False" repeatuntil="" name="selector" debugbreak="False">
    					<constraint repeatuntil="" priority="" name="stop - car detected" debugbreak="False" constraint="frontCarAspect != null" />
    					<constraint repeatuntil="" priority="" name="move - no car detected" debugbreak="False" constraint="frontCarAspect == null">
    						<move turnspeed="" repeatuntil="" name="move" movetarget="moveTarget" movespeed="10" facetarget="" debugbreak="False" closeenoughdistance="" closeenoughangle="" />
    					</constraint>
    				</selector>
    			</waypointpatrol>
    		</parallel>
    	</sequencer>
    </behaviortree>
    • This topic was modified 3 months, 2 weeks ago by  JZTym.
    • This topic was modified 3 months, 2 weeks ago by  JZTym. Reason: Added question
    #39022

    In reply to: Behavior Tree Re-use


    Sigil
    Keymaster

    We use variables in the behavior tree to define things that will change from AI to AI. I think the video is a bit dated, but for quick references, we often just use the names of the routes (in quotes) to link them in trees (for simple AI).

    Something along the lines of this:

    waypoint patrol (waypoint route: "Waypoint Route", move target variable: waypointTarget)
        move (move target: waypointTarget)

    But in your 50 AI case, with 50 different routes you’d have a lot of trees. Instead you could use a variable, defined in each AI’s memory, to tell it what route to go to:

    waypoint patrol (waypoint route: myPersonalRoute, move target variable: waypointTarget)
        move (move target: waypointTarget)

    You’d go to the memory tab on the AI, add a GameObject variable named myPersonalRoute, and drag the Waypoint Route of choice onto it. That’s one way at least. Another, even more automated way, would be to make a Custom Action for your AI that chooses the closest waypoint route. Something like this might work:

    using RAIN.Action;
    using RAIN.Navigation.Waypoints;
    using UnityEngine;
    [RAINAction]
    public class GetClosestWaypointRoute : RAINAction
    {
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
            // This could get slow in large scenes, might need to 
            // store this ahead of time in some component
            WaypointRig[] tRigs = GameObject.FindObjectsOfType<WaypointRig>();
            WaypointRig tClosestRig = null;
            float tClosestRigDistance = float.MaxValue;
            // This could also get slow over large networks and large scenes,
            // some speed ups are coming in the next version of RAIN
            for (int i = 0; i < tRigs.Length; i++)
            {
                // We only patrol routes, as networks are for path preference
                if (tRigs[i].WaypointSet.SetType != WaypointSet.WaypointSetType.Route)
                    continue;
                // Closest waypoint
                Waypoint tClosestWaypoint = tRigs[i].WaypointSet.GetClosestWaypoint(ai.Kinematic.Position);
                // And make sure its the closest out of all of them
                float tDistance = (tClosestWaypoint.Position - ai.Kinematic.Position).sqrMagnitude;
                if (tDistance < tClosestRigDistance)
                {
                    tClosestRig = tRigs[i];
                    tClosestRigDistance = tDistance;
                }
            }
            // If we found a set we want to use, take it
            if (tClosestRig != null)
            {
                ai.WorkingMemory.SetItem<WaypointRig>("myPersonalRoute", tClosestRig);
                return ActionResult.SUCCESS;
            }
            // Didn't find a route
            return ActionResult.FAILURE;
        }
    }

    You could change the parameters of this as well, it could be the furthest WaypointRig, or a WaypointRig with a component on it, or a WaypointRig with a certain name. Lots of options.


    Sigil
    Keymaster

    Well… have you gotten your hex generation working? The part that puts your prefabs out and lines them up appropriately.

    In addition to that placement, you’d also need to make sure that you inform each hex of its neighbors as you place it, that way when you come back around to create your waypoints you will already know where your neighbors are.

    I can help you work through some of the details with a little pseudo code if need be, just need to know what you have.

    #39002

    Thrisboss
    Participant

    Hi, I would like to know how I could make an AI (animal) wander around inside my navigation mesh? (without waypoints, I mean it would be completely random )
    Thank you.

    • This topic was modified 4 months, 1 week ago by  Thrisboss.
    #38909

    Sigil
    Keymaster

    Glad it worked out. This is already fixed internally and will be in the next release of RAIN. So you shouldn’t have to worry about it after that (in fact, moving the GameObject for a set of waypoints can be useful in many ways).

    #38889

    Sigil
    Keymaster

    Normally the AI will try to grab the closest waypoint along a path it is close to. We try to select this intelligently for the most part, so it won’t always be the first waypoint in some cases.

    That said, there is a bug in the current version of RAIN where the position of the Waypoint Route’s GameObject messes with the first waypoint selected. Try grabbing the Waypoint Route’s GameObject and setting its transform position to 0,0,0 and then moving the waypoints back to their proper location (without moving the GameObject). This should work around that particular bug.

    Let me know if this isn’t the case for you.


    GamesOfEdan
    Participant

    I’m attempting to write a custom MoveTo action. As a result I’m seeing some confusing results in the internal AI navigation.

    I’m asking the Navigator for a valid path to the active MoveTarget (eg. the player) using ai.Navigator.GetPathToMoveTarget(), and then navigate the set of ‘waypoint nodes’ defined in the resulting path.

    If I call ai.Motor.IsAt() beforehand, then the subsequent ai.Navigator.GetPathToMoveTarget() returns a valid path and is successful.
    This works & returns a valid path

    However, if I don’t call ai.Motor.IsAt(), then the exact same scenario fails to return a valid path.
    This fails and returns no valid path

    I basically want to ask the Navigtor “Give me a new valid path from my current location to the target”, and then navigate the waypoints via an enumerator. Is there some other way I should be attempting to do this?

    Sincerely.

    #38831

    In reply to: Speed Issues with AI


    Sigil
    Keymaster

    For your first problem: If you have Use Root Motion checked, RAIN leaves all movement to the animations that are playing, so it is either something in the state machine, or something about the values that RAIN is forwarding to the state machine. What values are you forwarding from the Mecanim Motor and are they what you expect on the state machine side? Check the state machine while the game is running and see what the parameters are coming across as.

    For your second problem: The first time the waypoint patrol node is executed it picks a waypoint to start heading to, if all of its children return success, it picks the next waypoint and resets its children so it can go again. If it has no children or there are no waypoints it just returns success without doing anything. You can add any node you like within the waypoint patrol, so usually it makes sense to create your logic as a child, but if you need to run it externally, you could do something like this (untested):

    parallel
       waypoint patrol (move target variable: myWaypoint)
          expression (expression: nextWaypoint = false, return value: success)
          expression (repeat until success, expression: nextWaypoint == true, return value: evaluate)
       sequencer (repeat forever)
          move (move target: myWaypoint)
          expression (nextWaypoint = true, return value: success)
    #38821

    KingKrawl
    Participant

    Ok I dont know if this goes in here but I cant seem to get my NPC to go to a Waypoint route!!! what am i doing wrong?

    any help is greatly appreciated

    <behaviortree version=”1.1″ repeatuntil=”” name=”Guard” debugbreak=”False”><sequencer usepriorities=”False” repeatuntil=”running” name=”Patrol and Idle” debugbreak=”False”><parallel tiebreaker=”fail” succeed=”all” repeatuntil=”” priority=”” name=”Patrol” fail=”any” debugbreak=”False”><waypointpatrol waypointsetvariable=”"PatrolRoute"” waypointactiontype=”patrol” traversetype=”loop” traverseorder=”forward” repeatuntil=”” pathtargetvariable=”” name=”Route” movetargetvariable=”” debugbreak=”False”><parallel tiebreaker=”fail” succeed=”all” repeatuntil=”” name=”Move” fail=”any” debugbreak=”False”><animate repeatuntil=”” name=”animate” debugbreak=”False” animationstate=”Walk” /><move turnspeed=”” repeatuntil=”” name=”Walk Patrol” movetarget=”” movespeed=”” facetarget=”” debugbreak=”False” closeenoughdistance=”” closeenoughangle=”” /></parallel></waypointpatrol><timer waitforsec=”30″ returnvalue=”success” name=”timer” debugbreak=”False” /></parallel><parallel tiebreaker=”fail” succeed=”all” repeatuntil=”” priority=”” name=”Pause” fail=”any” debugbreak=”False”><timer waitforsec=”15″ returnvalue=”success” name=”timer” debugbreak=”False” /><animate repeatuntil=”” name=”animate” debugbreak=”False” animationstate=”idle” /></parallel></sequencer></behaviortree>

    #38746

    Sigil
    Keymaster

    There are lots of ways to do these things, and no, you don’t have to technically parent something to make it respect its up direction. The alternatives generally involve doing the exact thing parenting does, only manually, creating your own matrices, transforming every point/direction/rotation by it before using it, etc.

    You’ll have to test, but a lot of things (outside of physics in particular) will obey parent transformations (rotations, scale, etc). RAIN particularly looks for parents though, so when it resolves paths, waypoints, AI movement, etc it realizes it and takes it into account. When an AI gets a point to move to (in world coordinates) it transforms it into its own local space (whatever it is parented to).

    On the other side, when a Navigation Mesh provides a point to move to, it does it relative to its parent as well. So it creates a path locally (rotated, scaled, whatever), and whenever an AI or someone else asks for a point, it transforms it into world space so it makes sense.

    This is probably more detail then you need to know, but since you are heading into this area it may help. As for moving from object to object, at any point you can take a GameObject and reparent it. So imagine playing an animation where the AI starts to walk up a wall sideways, and then right at the end of the animation, you reparent it, assuming the position it had moved to. You can change parents by reassigning the transform parent (gameObject.transform.parent = newTransformParent).

    Here’s a project (with a *slightly* upgraded RAIN to account for a visualization bug) that shows the setup for the parenting.

    #38738

    christougher
    Participant

    Haven’t been able to re-test yet. But I appreciate your response!

    Also, do the waypoint networks need to be a child of either the environment or the navmesh? As is the waypoint networks I use are all ‘dropped to the surface’ of the environment. As far as picking waypoints I’m using the custom action found here http://rivaltheory.com/forums/topic/walk-waypoint-network-beginner/#post-35120 It doesn’t seem like that would require off graph movement though…

    I’m very excited about the ability for things to walk on walls and ceilings. I mentioned CoreGameKit because I use it’s pooling system so the prefabs are spawned/despawned within its poolspawner game object. It has nothing to do with raycasting and changing parents. So if an object is to despawn once it’s due to die I believe it needs to remain inside that PoolManager (which is several gameobjects deep in the CG Kit system).

    Is having an object as a child of the target environment the only way for it to respect it’s up direction?

    And if the pathfinding involves changing ‘up’ (i.e. walking on one wall to the room to the other wall to the floor) any thoughts on how that can be done? Changing parent objects somehow?

    Hmmm… another thought. Does the AI simply get ‘up’ from whatever object it is parented to regardless of whether it has anything to do with Rain or navigation? Like even my poolmanager?? That would opens up some possibilities of having that rotated…

    Sorry, lots of questions without any time right now for me to test them right now myself. Hopefully tonight I can tackle some myself. Looking forward to that link!

    #38691

    Sigil
    Keymaster

    So a quick list of what will work and won’t in 2D for RAIN:

    AI - partially works
    — BasicMemory - works
    — BasicMind - works, move node won’t work unless motor is replaced
    — BasicMotor - won’t work in 2D, would need to be replaced
    — BasicNavigator - won’t work in 2D, would need to be replaced
    — BasicSenses - sensors work except for line of sight which uses the 3D raycast
    Entity - works
    Waypoints - works, but won’t be useful unless motor is replaced
    Navigation Targets - works, but won’t be useful unless motor is replaced
    Navigation Mesh - won’t work, doesn’t pick up 2D colliders

    As for replacing the motor and navigator, I haven’t attempted this just yet, I’m not sure what I would do for navigation in fact. A 2D physics motor seems straight forward, but I’m not sure I can put one together right now. Perhaps someone else has created one at this point though.


    Martin Cmar
    Participant

    In my journey called “test if everything in RAIN can be created programatically”, I am facing another problem.

    So far, I have accomplished these things from the code (with help of this great community!):
    *attach AI rig
    *create route
    *create behavior tree that will follow the route and set it to the actor

    heres what the script looks like now:

    using UnityEngine;
    using System.Collections;
    using RAIN;
    public class RAINTest : MonoBehaviour
    {
    	GameObject m_AIParent;
    	RAIN.Core.AIRig m_AIRig;
    	void Start()
    	{
    		// AI parent GameObject
    		m_AIParent = new GameObject("AI");
    		m_AIParent.transform.parent = gameObject.transform;
    		m_AIParent.transform.localPosition = Vector3.zero;
    		// attach AI rig
    		m_AIRig = m_AIParent.AddComponent<RAIN.Core.AIRig>();
    		m_AIRig.AI.Body = gameObject;
    		/* NOT WORKING
    		// animation setup
    		m_AIRig.AI.Animator = new RAIN.Animation.MecanimAnimator();
    		// motor setup
    		RAIN.Motion.MecanimMotor mecanimMotor = new RAIN.Motion.MecanimMotor();
    		m_AIRig.AI.Motor = mecanimMotor;
    		mecanimMotor.UseRootMotion = false;
    		RAIN.Motion.MecanimMotor.MotorParameter velocityXParameter = new RAIN.Motion.MecanimMotor.MotorParameter();
    		velocityXParameter.motorField = RAIN.Motion.MecanimMotor.MotorField.VelocityX;
    		mecanimMotor.AddForwardedParameter(velocityXParameter);
    		RAIN.Motion.MecanimMotor.MotorParameter velocityZParameter = new RAIN.Motion.MecanimMotor.MotorParameter();
    		velocityZParameter.motorField = RAIN.Motion.MecanimMotor.MotorField.VelocityZ;
    		mecanimMotor.AddForwardedParameter(velocityZParameter);
    		*/
    		// create route dynamically
    		GameObject route = new GameObject("route");
    		route.transform.position = Vector3.zero;
    		// attach waypoint rig
    		RAIN.Navigation.Waypoints.WaypointRig waypointRig = route.AddComponent<RAIN.Navigation.Waypoints.WaypointRig>();
    		// it's a route
    		waypointRig.WaypointSet.SetType = RAIN.Navigation.Waypoints.WaypointSet.WaypointSetType.Route;
    		// random color
    		//waypointRig.WaypointSet.NetworkColor = RAINEditor.RAINEditorUtility.PickRandomVisualColor();
    		// waypoints
    		RAIN.Navigation.Waypoints.Waypoint wp0 = new RAIN.Navigation.Waypoints.Waypoint();
    		wp0.Position = new Vector3(3,0,0);
    		RAIN.Navigation.Waypoints.Waypoint wp2 = new RAIN.Navigation.Waypoints.Waypoint();
    		wp2.Position = new Vector3(-3,0,0);
    		// add 'em to the route
    		waypointRig.WaypointSet.AddWaypoint(wp0);
    		waypointRig.WaypointSet.AddWaypoint(wp2);
    		waypointRig.Serialize();
    		// create behavior tree dynamically
    		RAIN.BehaviorTrees.BTWaypointNode tRoot = new RAIN.BehaviorTrees.BTWaypointNode()
    		{ 
    			waypointSetVariable = RAIN.Representation.ExpressionParser.Parse("route"),
    			waypointActionType = RAIN.BehaviorTrees.BTWaypointNode.WaypointActionType.PATROL,
    			traverseType = RAIN.BehaviorTrees.BTWaypointNode.WaypointTraverseType.PINGPONG,
    			traverseOrder = RAIN.BehaviorTrees.BTWaypointNode.WaypointTraverseOrder.FORWARD,
    			moveTargetVariable = "waypointTarget"
    		};
    		tRoot.AddChild(new RAIN.BehaviorTrees.Actions.MoveAction()
    		{
    			moveTargetExpression = RAIN.Representation.ExpressionParser.Parse("waypointTarget")
    		});
    		// set it
    		RAIN.Minds.BasicMind basicMind = m_AIRig.AI.Mind as RAIN.Minds.BasicMind;
    		basicMind.BehaviorRoot = tRoot;
    		m_AIRig.Serialize();
    	}
    	void Update()
    	{
    	}
    }

    you can attach this script to capsule e.g. and even it has no AI before the game start, it will work properly, everything will be created programatically at runtime.

    “SO WHAT IS YOUR PROBLEM?!”
    the problem is when I want to have fully animated character (a soldier) instead of simple capsule.
    When the AI rig is created, the AI has basic motor and basic animator set as default, and I want to change them both to mecanim variants. (see the commented out section of code named “NOT WORKING”).

    just to make you sure: when I do the same thing by “clicking in unity editor”, everything’s fine, and the soldier is animating as he walks.

    “SO WHAT DOES THE CODE DO?!”
    when I comment out the problematic section of code, these two errors starts rolling:

    NullReferenceException: Object reference not set to an instance of an object
    RAIN.Motion.MecanimMotor.UpdateMotionTransforms ()
    RAIN.Core.AI.Pre ()
    RAIN.Core.AIRig.AIUpdate ()
    RAIN.Core.AIRig.Update ()

    and

    NullReferenceException: Object reference not set to an instance of an object
    RAIN.Animation.MecanimAnimator.UpdateAnimation ()
    RAIN.Core.AI.Post ()
    RAIN.Core.AIRig.AILateUpdate ()
    RAIN.Core.AIRig.LateUpdate ()

    “HAVE YOU CAME UP WITH SOMETHING ALREADY?!”
    yes, I have noticed that when you do the same thing (changing the animator or motor or both at runtime) with ordinary created AI (I mean: by “clicking in Unity editor”), you got the same errors. so my final question is simply:

    how to change motor and animator at runtime?

    • This topic was modified 5 months, 3 weeks ago by  Martin Cmar.
    #38668

    ToastDispatch
    Participant

    Hello,

    First time working with RAIN AI and I’m working on a 2D hockey game, like the old NES or NHL 94 games.

    Just trying to get started simply, and my AI won’t go to a waypoint target, here is a shot of my behavior tree.

    I’ve got the move target set to “Center Point” and a Waypoint Target in the heiarchy with the name “Center Point”, but he doesn’t go to it.

    I’m working in Unity 4.6.

    I was working on this a few months ago and followed some pages on the Wiki about Waypoints, but now it seems those pages have been removed from the Wiki?

    Any help would be greatly appreciated, I can’t seem to find any up to date tutorials about RAIN AI and half the pages in the Wiki are missing or not yet added.

    • This topic was modified 5 months, 3 weeks ago by  ToastDispatch.
Viewing 15 results - 16 through 30 (of 347 total)