News Forums Search Search Results for 'stop moving'

Viewing 15 results - 1 through 15 (of 99 total)
  • Author
    Search Results
  • #39825

    Sweet Alphonse
    Participant

    Eg. press X and all agents stop moving for X seconds, or run away from a set agent?

    Any ideas on where to start?

    Thanks

    #39717

    radiant
    Participant

    Managed to stop them attacking each other and got them working quite nice, they still seem to get stuck in the walls, im assuming its down to the method which chooses a new location for them. I have found the behaviour editor tree which is awesome but a bit confusing at first One other thing is that they dont seem to quite hit me, they attack kind of in front of me, how do I change the position they aim for? Moving the entity doesnt seem to do it.

    #39622

    In reply to: Custom RAINMotor


    Other-Jeff
    Participant

    I’m very close now. I see the path and the actor moves to the first border between the mesh node its in and the next mesh node, but then it sticks there, like itsg etting set back there after every move from the on.

    Do I need to do something to tell it to advance to the next target?

    Code below:

    using System;
    using RAIN.Core;
    using RAIN.Motion;
    using RAIN.Navigation.Pathfinding;
    using RAIN.Serialization;
    using UnityEngine;
    [RAINSerializableClass]
    public class UAMotor : RAINMotor
    {
        public AICharacterController controller;
        private RAINPath path;
        private float TurnAngle;
        private float AngleToTarget;
        private MoveLookTarget _cachedTarget;
        private MoveLookTarget GoodTarget = new MoveLookTarget();
        public override void AIInit()
        {
            base.AIInit();
            Allow3DMovement = false;
        }
        public override bool Allow3DMovement
        {
            get
            {
                return false;
            }
            set
            {
                //nop
            }
        }
        public override void ApplyMotionTransforms()
        {
            //NOP
        }
        /// <summary>
        /// Turn towards FaceTarget
        /// </summary>
        /// <returns></returns>
        public override bool Face()
        {
            if (IsFacing(FaceTarget.Orientation))
            {
                return true;
            }
            else
            {
                controller.targetRotation = Quaternion.LookRotation(FaceTarget.Position - controller.transform.position, new Vector3(0, 1, 0));
                return false;
            }
        }
        public override bool IsAt(Vector3 aPosition)
        {
            if ((controller.transform.position - aPosition).magnitude <= 0.1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public override bool IsAt(MoveLookTarget aTarget)
        {
            return IsAt(aTarget.Position);
        }
        public override bool IsFacing(Vector3 aPosition)
        {
            Vector3 facingVector = aPosition - controller.transform.position;
            float angle = Vector3.Angle(facingVector, controller.transform.forward);
            if (Mathf.Abs(angle) <= 0.1f)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public override bool IsFacing(MoveLookTarget aTarget)
        {
            return IsFacing(aTarget.Position);
        }
        public override bool Move()
        {
            // If we are at our target, we are done
            if (IsAt(MoveTarget))
                return true;
            TurnAngle = 0f;
            AngleToTarget = 0f;
            // The cached move target keeps us from using up extra allocations
            _cachedTarget = AI.Navigator.GetNextPathWaypoint(MoveTarget, Allow3DMovement, AllowOffGraphMovement, _cachedTarget);
            // After allowing the navigator to run, if we are done pathfinding
            // and we don't allow off graph movement, and we are at the last point in the path
            // then we are done
            if (!AllowOffGraphMovement && !AI.Navigator.IsPathfinding)
            {
                if (AI.Navigator.CurrentPath == null || !AI.Navigator.CurrentPath.IsValid)
                    return true;
                if (!AI.Navigator.CurrentPath.IsPartial && IsAt(AI.Navigator.CurrentPath.GetWaypointPosition(AI.Navigator.CurrentPath.WaypointCount - 1)))
                    return true;
            }
            // If we have a valid move target from our navigator, attempt to head towards it
            if (_cachedTarget.IsValid)
            {
                // Copy the position over so we can keep track of our last known good position
                GoodTarget.VectorTarget = _cachedTarget.Position;
                // Update our angle to target
                Vector3 tTurn = RAIN.Utility.MathUtils.GetLookAtAngles(AI.Kinematic.Position, _cachedTarget.Position, AI.Kinematic.Orientation);
                AngleToTarget = RAIN.Utility.MathUtils.WrapAngle(tTurn.y - AI.Kinematic.Orientation.y);
                DoDirectMovement(AI, _cachedTarget.Position, CloseEnoughDistance, CloseEnoughAngle, FaceBeforeMoveAngle, Allow3DMovement, Allow3DRotation);
            }
            // We don't have a valid move target from our navigator, and we don't allow off graph movement, so head to our last known good target
            else if (!AllowOffGraphMovement)
            {
                // Update our angle to target
                Vector3 tTurn = RAIN.Utility.MathUtils.GetLookAtAngles(AI.Kinematic.Position, GoodTarget.Position, AI.Kinematic.Orientation);
                AngleToTarget = RAIN.Utility.MathUtils.WrapAngle(tTurn.y - AI.Kinematic.Orientation.y);
                DoDirectMovement(AI, GoodTarget.Position, Mathf.Min(0.001f, CloseEnoughDistance), CloseEnoughAngle, FaceBeforeMoveAngle, Allow3DMovement, Allow3DRotation);
            }
            // We don't have a valid move target from our navigator, but we allow off graph movement, so head straight to our origina move target
            else
            {
                // Update our angle to target
                Vector3 tTurn = RAIN.Utility.MathUtils.GetLookAtAngles(AI.Kinematic.Position, MoveTarget.Position, AI.Kinematic.Orientation);
                AngleToTarget = RAIN.Utility.MathUtils.WrapAngle(tTurn.y - AI.Kinematic.Orientation.y);
                DoDirectMovement(AI, MoveTarget.Position, Mathf.Min(0.001f, CloseEnoughDistance), CloseEnoughAngle, FaceBeforeMoveAngle, Allow3DMovement, Allow3DRotation);
            }
            // And update our turn angle if we have angular velocity
            if (AI.Kinematic.Rotation.sqrMagnitude > 0f)
                TurnAngle = AngleToTarget;
            // We return false because we are still moving towards our target
            return false;
        }
        private void DoDirectMovement(AI aI, Vector3 position, float closeEnoughDistance, float closeEnoughAngle, float faceBeforeMoveAngle, bool allow3DMovement, bool allow3DRotation)
        {
            Vector3 direction = (position - AI.Body.transform.position).normalized;
            controller.inputMoveDirectionLocal = AI.Body.transform.InverseTransformDirection(direction);
        }
        public override void Stop()
        {
            controller.inputMoveDirectionLocal = Vector3.zero;
            controller.targetRotation = controller.transform.rotation;
        }
        public override void UpdateMotionTransforms()
        {
            AI.Kinematic.ParentTransform = Matrix4x4.identity;
            AI.Kinematic.Position = AI.Body.transform.position;
            AI.Kinematic.Orientation = AI.Body.transform.rotation.eulerAngles;
        }
    }

    strangegames
    Participant

    I’m having an issue where the AI seems to ignore the close enough distance in the move action as well as in the motor controller. This seems to happen if the move action is in a node that repeats. I setup a basic bt as follows:

    Para	(fail any, succeed all )
    	Detect	( repeat forever )
    	Select	( repeat never )
    		constraint  ( target != null,  repeat never )
    			move		( close enough distance = 10, repeat never )
    			expression	( test = 1,  return success )

    This works and the ai moves to the target and stops 10 units away. If however I change the Parallel to (fail any, success any), the AI moves all the way to the target. The move does return true for one frame but on the next frame it resumes running and moves all the way to the target before stopping and returning true. The expression is used for debugging and setting a breakpoint there shows the move does return true for one frame before resuming on the next frame an attempting to move all the way to the target.

    It seems like when the move first returns true, the tree resets and the move then begins executing again ignoring the fact that it’s close enough.

    I’ve found that setting the select to repeat as well as the constraint to repeat also causes the move to attempt to move past the close enough distance. It seems to be related to move not behaving well when it’s in a repeating node.

    One other thing I’ve noted is when the target’s collision mesh is enabled, the ai moves up to where it collides and doesn’t move further. When the target’s collision mesh is disabled, it moves all the way to the target’s center. In both cases, move doesn’t return true until about a quarter second after it stops moving. It’s like it keeps trying to move and only returns true after it can no longer move for a few frames.

    Is this a bug or am I doing something wrong?

    Thanks,
    Reggie

    • This topic was modified 2 months, 3 weeks ago by  Sigil. Reason: added code block
    #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


    Riscvul
    Participant

    Hello,

    I have been experimenting around with RAIN AI for a while now. I created a very simple chasing AI behaviour and then set it aside while I worked on other things. When I came back to it and copied my enemy it no longer worked.

    It calculates a path but doesn’t follow it. It seems like it gets stuck each time it tries to cross one of the navigation mesh polygons. If I toggle on and off the Allow 3D Movement box it will continue to move most of the time, otherwise it doesn’t do anything.

    It also no longer rotates to face my player. I am really confused as to what I broke, but even placing a new behaviour tree (The one from the tutorial video) does nothing to fix it. It still cannot navigate the mesh.

    Does anyone have any suggestions? I was really starting to like this solution but now I’m on the verge of chucking it out.

    Behaviour Tree and visual of path Issues

    • This topic was modified 3 months, 1 week ago by  Riscvul.

    Kirito
    Participant

    Hi guys,

    Yesterday I downloaded Rain AI and have been looking at some tutorials on youtube. After following a tutorial, I should have an AI that patrols and chases the player if the player gets detected.

    The problem that I encountered is the following:
    I’m using an first person controller script and it’s using the unity character controller (the script is from the asset store. I added an entity as a child of this player object. But when I move, the entity object does not move along with the player object. The entity object stays on the starting position of the player object while the player just moves around the scene. So what happens is: if the AI patrols and finds the entity, it moves towards the entity of the player. The ai stops moving afterwards because he is still detecting the entity. But.. the actual player object is somewhere else.

    I tried to check what happened if I made an object in another scene and adding an entity + rigidbody. In that scene, the entity does follow the player and the ai will work like it should behave.

    Anyone that can point out what I’m missing to make the entity move along with the character controller object?

    • This topic was modified 3 months, 3 weeks ago by  Kirito.
    • This topic was modified 3 months, 3 weeks ago by  Kirito.
    #39409

    In reply to: Mobile problems


    soul_assassin
    Participant

    Hi Sigil thanks for the response. I managed to get my tree running in the end apart from it would work fine 9 times out of ten and then the animation would stop on the walk animation although the zombie was still moving. After reading through the forums there was mention of using mecanim instead of legacy. So I spent my days off learning about Mecanim and rewriting my tree, works perfectly now, which is great. Chases after the player, idles, attacks etc. only problem I have now is when I generated a Navmesh he gets stuck still moving on any object in his way and kinda slides around it. Ive searched the forums and theres a post that says its to do with body transforms? Or do I need some sort of turn animation in my blend tree? At the moment I`m just using a speed variable which seems to work fine when there`s no navmesh, zombie turns fine. Any help would be appreciated, I feel a bit one step forward, two back at the mo.
    Thanks in advance for any help once again!
    Paul.


    wightwhale
    Participant

    Currently I have AI sliding while they’re attacking is there a good way to make the AI stay in place during the attack animation?
    http://i.imgur.com/179sXuv.png


    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 5 months ago by  JZTym.
    • This topic was modified 5 months ago by  JZTym. Reason: Added question

    Sigil
    Keymaster

    You are moving faster than me, but this is to be expected, as you can concentrate all your efforts on this one issue. I am just busy and it takes me awhile to get back around to the forums some times.

    So I mentioned it before, and I’ll say it again now, several things stand out to me as problems:

    1. The original behavior tree setup for attacking doesn’t need a constraint, a visual sensor, or any of that to work properly. It should play the whole attack and it shouldn’t attack from far away.
    2. The original attack action, and your new ConsumeFood action, don’t require ResetTrigger calls. A trigger doesn’t keep the animation playing or stop it from playing unless you setup your transitions that way.

    You shouldn’t need bools either… these are all signs that something isn’t setup quite right, either I assumed something and you did it differently, or vice versa. We need to figure out why these things aren’t working before trying to change them, otherwise whatever the problem is, it is going to come up again (like you are seeing with your attack being flaky).

    So let’s start with attacking, in the original tree, with your custom action (minus the ResetTrigger):

    ...
    sequencer
        move (move target: playerTarget)
        move (face target: playerTarget)
        mecanim parameter (parameter: Attack, parameter type: Trigger), value: true)
        custom action (class: AttackTarget, target: playerTarget)
    ...

    So this is all in a sequencer, which means the attack won’t happen until the first two move nodes return success. The first move won’t return success until you are within close enough distance… so if you are attacking from far away, what happened to make it return success?

    Let’s say it does work though, and he gets close enough but the animation is stuttering. First, the Attack parameter should be a trigger, and it should only be used to transition into the attack state. Second, the only way out of the attack state should be a transition when the attack is done. I believe the default settings on a transition out of the state would be the correct settings.

    I’ll be hanging around today, so let’s see if we can solve this problem.

    #38957

    ck
    Participant

    Something weird is going on on my end… I’ve created a brand new project, re-copied the motor code and created a behavior tree like the one above, but it still didn’t do the trick. Here’s the link to the repro project:
    https://www.dropbox.com/s/cpzijf7hoqzq3to/RainRepro.zip?dl=0

    The white capsule is using the BasicMotor, the red one - the NavMeshMotor and both of them are running the same behavior tree, but the red capsule never stops moving.

    #38950

    In reply to: AI Troubleshooting


    Joshichimaru3
    Participant

    Thankyou Sigil for all the assistance, I can also implement the attacking based of this distance system and stop him moving so with this it should solve all my problems. I’ll work on implementing it in the morning but as far as I can tell there shouldn’t be any issues. I’ll use your recommendation for approaching task in the future, even when I script I finish everything then test it sometimes makes finding the problem difficult.

    RAIN has allowed me to create an AI within my game that I otherwise would have been incapable of and I really appreciate all the work Rival Theory has put into developing it.

    #38725

    binary
    Participant

    Okay, its getting closer.
    The thing is, the trigger can issue a stop command which leaves the sensor sitting on the aspect. And it should still be able to be triggered by other (moving) aspects. So in this situation, in the current version it acts not like OnTriggerEnter but like OnTriggerStay in the first block. The detected aspect should be ignored until !IsDetected.

    Best what i could come up with, was adding flag to the aspect that gets set on detection and then it will be ignored.

    IList<RAINAspect> tAspects = ai.Senses.SenseAll();
            if (tAspects.Count == 0)
                return ActionResult.FAILURE;
            currentTrigger = null;
            for (int i = 0; i < tAspects.Count; i++){ 
                if(!((MyAspect)tAspects[i]).DidExecute){
                    currentTrigger = (MyAspect)tAspects[i];
                    break;
                }
            }
            if(currentTrigger == null){
                return ActionResult.FAILURE;
            }else if ( currentTrigger != null){
            currentTrigger.DidExecute = true;
    [...]
    }
    [...]

    This is not only not nice, but i also cant figure out, how and where to reset the aspect to undetected (currentTrigger.DidExecute = false; ).

    #38294

    vamuse
    Participant

    Sorry to reopen old topics. Following this tutorial now:

    I’m getting an error saying:
    Scripts/Climb.cs(84,54): error CS0200: Property or indexer `RAIN.Minds.BasicMind.BehaviorTreeAsset’ cannot be assigned to (it is read only)

    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.Targets;
    using RAIN.Minds;
    using RAIN.BehaviorTrees;
    [RAINAction]
    public class Climb : RAINAction {
    	private Vector3 _navPlatform = Vector3.zero;
    	private Vector3 _platformStart = Vector3.zero;
    	private Vector3 _newPostion;
    	private Vector3 _trigger = Vector3.zero;
    	private bool _isCloseEnough = false;
    	private float _platformHeight = 2.94f;
    	public Climb()
    	{
    		actionName = "Climb";
    	}
    	public override void Start (AI ai)
    	{
    		//Only initialize once
    		if(_navPlatform == Vector3.zero)
    		{
    			//Find the trigger position
    			_trigger = GameObject.Find ("LadderTrigger").transform.position;
    			//Get the start point to move to on the platform
    			_platformStart = NavigationManager.Instance.GetWaypointSet("PlatformRoute").Waypoints[0].position;
    			//Set the y to the height we need to be on top of the platform
    			_navPlatform = new Vector3(_trigger.x, _platformHeight, _trigger.z);
    			//Set flag climb
    			ai.WorkingMemory.SetItem<bool>("climb", true);
    			//Optional. Set root motion off
    			((RAIN.Animation.MecanimAnimator)ai.Animator).UnityAnimator.applyRootMotion = false;
    		}
    		base.Start (ai);
    	}
    	public override ActionResult Execute(AI ai)
    	{
    		//If the navigation platform was initialized
    		if (_navPlatform != Vector3.zero) 
    		{
    			//Check that we are first close to the ladder and move as needed
    			//To prevent trying to move back to the trigger point as we climb away
    			//Set the flag isCloseEnough to true
    			if(Vector3.Distance(ai.Kinematic.Position, _trigger) > .5f && !_isCloseEnough)
    			{
    				ai.Kinematic.Position = Vector3.MoveTowards(ai.Kinematic.Position, _trigger, 1f * Time.deltaTime);
    				return ActionResult.RUNNING;
    			}
    			//Move on the Y axis to climb to our height
    			else if(ai.Kinematic.Position.y < _platformHeight)
    			{
    				//We are now moving up and away from the trigger point
    				_isCloseEnough = true;
    				//Start climbing up
    				ai.Kinematic.Position = Vector3.MoveTowards(ai.Kinematic.Position, _navPlatform, .5f * Time.deltaTime);
    				return ActionResult.RUNNING;
    			}
    			//We are at the top. Move onto the mesh
    			else if(Vector3.Distance (ai.Kinematic.Position, _platformStart) > 1.5f)
    			{
    				ai.Kinematic.Position = Vector3.MoveTowards(ai.Kinematic.Position, _platformStart, 1f * Time.deltaTime);
    				return ActionResult.RUNNING;
    			}
    			//Finally, load the ai mind with a new behavior tree asset and initialize
    			else
    			{
    				var btAsset = Resources.Load<BTAsset>("PlatformWalk");
    				((BasicMind)ai.Mind).BehaviorTreeAsset = btAsset;
    				ai.Mind.AIInit();
    				//Setting root motion back on the move
    				((RAIN.Animation.MecanimAnimator)ai.Animator).UnityAnimator.applyRootMotion = true;
    			}
    		}
    		//ai.WorkingMemory.SetItem<bool>("climb", false);
    		return ActionResult.SUCCESS;
    	}
    	public override void Stop(AI ai)
    	{
    		base.Stop (ai);
    	}
    }

    Thanks in advance!!!

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