News Forums Search Search Results for 'constraint not working'

Viewing 15 results - 1 through 15 (of 49 total)
  • Author
    Search Results

  • klawd
    Participant

    First I want to congratulate, and thank, the developers for such a great product. I love what you are doing with Squad and Sentio and that you are keeping RAIN free. You guys rocks.

    My problem:
    I’m working on a game in my free time, and I opted to use RAIN because I needed a tool able to make Navigation Meshes at runtime (maps are generated procedurally). I then made my player controlled character use an AI rig to move, by getting its move variable from a raycast hit.
    The complications started when I decided to use a Sensor to detect obstacles (ie. a door equipped with an Entity component). The idea is to make the character stop before a door/obstacle, that’s been put dynamically on the NavMesh, and not keep running on its collider. The NavMesh generation filtrates the layer containing the doors, so that once the door collider is removed (ie. the door opened) the character is able to walk in the next room.

    I thought the BT like this:
    *root [parallel]
    -detect (on repeat forever) with player’s sensor and door’s aspect
    -selector (on repeat forever)
    —-constraint on door variable (== null)
    ——move to raycast hit point
    —-constraint on door variable (!= null)
    ——-move to character to the player gameobject position (aka stop where you sensed the door)

    If I click in the area in front of the door, the character moves there, and the door variable gets fired correctly (the second move action is never triggered though)
    But if I click in the next room, and there’s a closed door in between, the character go hugs this door’s collider while continuing to try and walk past it…

    I suspect that I’m using RAIN in a unorthodox manner, and not for what it was thought for, but the NavMesh generation at runtime makes RAIN essential to my project. I do plan on using RAIN also for the AIs of the game’s enemies component, and I would like to integrate it with everything else.
    Hope you guys can give me some directions.

    • This topic was modified 2 weeks, 4 days ago by  klawd.

    Ibrahim
    Participant

    Hello,

    I learned to build simple BTs that do simple tasks. But now when I tried to use BTs for my AI characters in the project I found difficulty building the BTs that will execute the behavior I wish to have. I have watched tutorials (all are very basic examples), and also read all the RAIN WIKI but still not able to build what I want.

    My game is about fire fighting: For instance, I want my AI (Team Leader) to check if the game started or not, once it started, he should query the GameController script about the first situation to handle, once he get this answer, he should send a message to all Firefighters to go to the fire truck, and once they are all inside it, the fire truck should move to the situation, and then he should command them to line up in front of the Truck, and so forth.. querying about the game from the game environment, receive and send information to other AIs and do some actions.

    Every other AI should also has its own BT, that controls his actions, receiving messages, doing actions, sensing and sending messages.

    I have started with the following BT for the Team Leader, but I it really seems weak and not working as expected (because of not understanding the nodes rules and how the sequence follow from one step to the next).

    <behaviortree version="1.1" repeatuntil="" name="FF_TL_BT" debugbreak="False"><sequencer usepriorities="False" repeatuntil="" name="TL_root" debugbreak="False"><constraint repeatuntil="" priority="" name="Game started? and there is at least one situation to handle?" debugbreak="False" constraint="gameStarted == true && numberOfSituations > 0"><constraint repeatuntil="" name="Far from situation?" debugbreak="False" constraint="distanceToSituation > 50"><sequencer usepriorities="False" repeatuntil="" name="sequencer" debugbreak="False"><action repeatuntil="" priority="" parametervalues="" parameters="" namespace="(global)" name="Send Message to FFs to go to FF Truck" debugbreak="False" classname="SendMessageToFFs" /></sequencer><parallel tiebreaker="fail" succeed="all" repeatuntil="" name="parallel" fail="any" debugbreak="False"><move turnspeed="" repeatuntil="" name="Move to my door in fire truck" movetarget="myDoor" movespeed="3" facetarget="myDoor" debugbreak="False" closeenoughdistance="" closeenoughangle="" /><animate repeatuntil="" name="animate" debugbreak="False" animationstate="Locomotion.WalkRun" /></parallel><constraint repeatuntil="" name="constraint" debugbreak="False" constraint="!ffDetector.active"><action repeatuntil="" parametervalues="" parameters="" namespace="(global)" name="Send message to FF Truck to go to currentsituation" debugbreak="True" classname="SendMessageToFFTruck" /></constraint></constraint></constraint></sequencer></behaviortree>

    Any help will be appreciated.

    #39926

    Cubiboy
    Participant

    Hello

    I try to finish my AI and setup 2 visual sensors to detect. To my Player I attached a Entity. In BT I wrote the Aspect and the
    sensor with quotes but it’s still not working. Also in a constraint happens an error: varHeroNearby != null && myHealth > 0

    Have you an idea to fix it?

    Thank you very much!

    #39326

    Alisaunder
    Participant

    ok I actually got it partially working this morning.

    This is the behavior tree.

    The first detect is my eyes
    the second detect is my firing range

    if he does not spot the player he follows a patrol route
    the move tells him to follow the Waypoint patrol

    the mecparam is my Speed Variable on my animator since I am using the speed attached to my animations.
    it’s value is 0.5 since 0 is idle, 0.5 is my walks, and 1 is my jogs

    the second constraint occurs if he is spotted
    I have him merely face the player then have change the mecparam to 1 which makes him job toward he player

    I haven’t gotten the third part to work yet which when firing range is detected he is supposed to stop and fire
    he isn’t stopping
    I set the mecparam value to 0 which should set him in the idle department but he keeps running until he is past the player then goes back to patrolling.

    #39197

    In reply to: Custom action


    Sigil
    Keymaster

    OK, well very likely what is happening is that your AI is working on moving towards the player. The move node will hold on to execution until it gets within close enough distance of its target.

    Try it out in the behavior tree debugger and you should see what is happening. Select your AI and change the drop down in the behavior tree to the Current AI (top option I think). When you press play it should light up with colors representing what is going on. What you will probably see in the first image is that the move node is yellow, and the expression isn’t lit yet.

    A few notes on your tree:

    When you have multiple items in a constraint it behaves like a sequencer. So it will wait until the first item returns success before moving on to the next. In your case it is waiting for the move node to finish before evaluating the expression.

    Your expression node is currently set to return the evaluated result, and since it is an assignment (PlayerInSight = true) it is returning whatever PlayerInSight equals when you’re done (obviously true in this case). While it works this time, it may not be what you intended, for instance if you were to do PlayerSpeed = 0 instead, it would have returned 0, which ends up being treated as a failure. Generally when you are doing an assignment you probably want to set it to return success or failure explicitly.

    Let me know if my first observation is off, otherwise come back if you have more questions.


    Mad_Mark
    Participant

    Okay, I repurposed the AttackTarget custom action using that EntityRig stuff. it appears to be working. w00t!
    Just adding the EntityRig stuff to ConsumeFood toggled the isActive too quick. AI didn’t run the eating animation, just paused and then returned to patrolling. Running 2 Zombies on the AI-rig to ensure that they both feed, and then return to patrolling their random locations works.

    How do I give the AI enough time to leave the area, say 30 - 60 seconds, then turn the foodTarget.isActive flag back on? Tried a timer, but of course that just pauses the active zombie… 8(
    To get on the same page, here is where I am at.
    BT:

    root
        sequencer
            parallel (fail: any, success: any, tie breaker: fail)
                detect (repeat: Until Success, aspect: "Player", form variable: playerTarget, Aspectvar: inRange = false)
                sequencer (repeat: Forever)
                    parallel (fail: any, success: any, tie breaker: fail)
                        detect (repeat: Until Success, aspect: "Food", form variable: foodTarget)
                        sequencer (repeat: Forever)
                            custom action (class: ChooseRandomLocation, target: moveTarget, distance: random(30, 60))
                            move (move target: moveTarget, moveSpeed: 1, FaceTarget: moveTarget, CloseEnuf: 3)
                            timer (seconds: random(1, 5))
                    move (move target: foodTarget, closeEnuf: 2)
                    mecanim parameter (parameter: Eat, parameter type: Trigger, value: true)
                    timer (seconds: random(5, 10))
                    custom action (Repeat Until: Success, Class: ConsumeFood, target: foodTarget, EatTime: 3)
            selector
                parallel (fail: any, success: any, tie breaker: fail)
                    sequencer (repeat: Until Failure)
                        expression (expression: playerTargetPosition = position(playerTarget), returns: Success)
                        detect (Sensor: "Sight", Aspect: "Player", AspectVar: inRange = false, FormVar: playerTarget)
                    sequencer
                        move (MoveTarget: playerTarget, MoveSpeed: 1.5, FaceTarget: playerTarget, CloseEnuf: 3)
                        move (FaceTarget: playerTarget)
                        detect (repeat: UntilSuccess, Sensor:"AttackRange", Aspect:"Player", FormVar: playerTarget, AspectVar: inRange = true)
                        CONSTRAINT:(inRange = true)
                            SEQ 
                                Mecanim parameter (parameter: Attack, parameter type: Trigger), value: true)
                                Custom action (class: AttackTarget, target: playerTarget)
                                Mecanim parameter (parameter: Attack, parameter type: Trigger), value: false) [Debug never fires]
                                Expression (inRange = false)
                parallel (fail: any, success: any, tie breaker: fail)
                    detect (repeat: Until Success, aspect: "Player", form variable: playerTarget, AspectVar: inRange = false)
                    move (move target: playerTargetPosition, MoveSpeed: 1.5, FaceTarget: playerTargetPosition)

    ChooseRandomLocation:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Navigation;
    using RAIN.Navigation.Graph;
    using RAIN.Navigation.NavMesh;
    using RAIN.Representation;
    [RAINAction]
    public class ChooseRandomLocation : RAINAction
    {
    	public Expression Target = new Expression ();
    	public Expression Distance = new Expression ();
    	public override ActionResult Execute (RAIN.Core.AI ai)
    	{
    		// Get any graphs at our AI's position
    		List<RAINNavigationGraph> tGraphs = NavigationManager.Instance.GraphForPoint (ai.Kinematic.Position);
    		if (tGraphs.Count == 0)
    			return ActionResult.FAILURE;
    		// Pretty much guaranteed it will be a navigation mesh
    		NavMeshPathGraph tGraph = (NavMeshPathGraph)tGraphs [0];
    		// Look for polys within the given distance
    		float tDistance = 20;
    		if (Distance.IsValid)
    			tDistance = Distance.Evaluate<float> (ai.DeltaTime, ai.WorkingMemory);
    		// We'll use the recently added oct tree for this
    		List<NavMeshPoly> tPolys = new List<NavMeshPoly> ();
    		tGraph.PolyTree.GetCollisions (new Bounds (ai.Kinematic.Position, Vector3.one * tDistance * 2), tPolys);
    		if (tPolys.Count == 0)
    			return ActionResult.FAILURE;
    		// Pick a random node
    		NavMeshPoly tRandomPoly = tPolys [UnityEngine.Random.Range (0, tPolys.Count - 1)];
    		// If the user set a Target variable, use it
    		if (Target.IsVariable)
    			ai.WorkingMemory.SetItem<Vector3> (Target.VariableName, tRandomPoly.Position);
    		// Otherwise just use some default
    		else
    			ai.WorkingMemory.SetItem<Vector3> ("randomLocation", tRandomPoly.Position);
    		return ActionResult.SUCCESS;
    	}
    }

    AttackTarget:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Entities;
    using RAIN.Representation;
    [RAINAction]
    public class AttackTarget : RAINAction
    {
    	public Expression Target = new Expression ();
    	public Expression AttackTime = new Expression ();
    	private Animator _animator = null;
    	private float _attackTime = 0.5f;
    	private bool _doneDamage = false;
    	public override void Start (RAIN.Core.AI ai)
    	{
    		base.Start (ai);
    		_animator = ai.Body.GetComponent<Animator> ();
    		if (AttackTime.IsValid)
    			_attackTime = Mathf.Clamp01 (AttackTime.Evaluate<float> (ai.DeltaTime, ai.WorkingMemory));
    		_doneDamage = false;
    	}
    	public override ActionResult Execute (RAIN.Core.AI ai)
    	{
    		if (!Target.IsValid)
    			return ActionResult.FAILURE;
    		// We'll just grab this here for reference later
    		AnimatorStateInfo tCurrentState = _animator.GetCurrentAnimatorStateInfo (0);
    		// If we haven't done damage yet, we're just starting out so
    		if (!_doneDamage) {
    			// There are many ways to do the timing for the attack, in this case
    			// I'll go the easy route and just wait until the attack time has been hit
    			if (tCurrentState.IsName ("Base Layer.Attack") &&
    				tCurrentState.normalizedTime >= _attackTime) {
    				// Here you should call out to your player and make them take damage in some way
    				GameObject tTarget = Target.Evaluate<GameObject> (ai.DeltaTime, ai.WorkingMemory);
    				_doneDamage = true;
    				_animator.ResetTrigger ("Attack");  // Added to try and set the animation to NOT play.
    				Debug.Log ("Successfully set ATTACK to false!");
    			}
    			// We'll always return running until we do damage
    			return ActionResult.RUNNING;
    		}
    		// In this case, we just need to wait for our animation to finish
    		// you may need to check for transitioning here too
    		if (tCurrentState.IsName ("Base Layer.Attack"))
    			return ActionResult.RUNNING;
    		// And we finished attacking
    		//_animator.ResetTrigger ("Attack");
    		return ActionResult.SUCCESS;
    	}
    }

    ConsumeFood:

    using UnityEngine;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using RAIN.Entities;
    using RAIN.Representation;
    using RAIN.Navigation;
    using RAIN.Motion;
    [RAINAction]
    public class ConsumeFood : RAINAction
    {
    	public Expression Target = new Expression ();
    	public Expression EatTime = new Expression ();
    	private Animator _animator = null;
    	private float _eatTime = 0.5f;
    	private bool _doneEating = false;
    	public override void Start (RAIN.Core.AI ai)
    	{
    		base.Start (ai);
    		_animator = ai.Body.GetComponent<Animator> ();
    		if (EatTime.IsValid)
    			_eatTime = Mathf.Clamp01 (EatTime.Evaluate<float> (ai.DeltaTime, ai.WorkingMemory));
    		_doneEating = false;
    	}
    	public override ActionResult Execute (RAIN.Core.AI ai)
    	{
    		if (!Target.IsValid)
    			return ActionResult.FAILURE;
    		// We'll just grab this here for reference later
    		AnimatorStateInfo tCurrentState = _animator.GetCurrentAnimatorStateInfo (0);
    		// If we haven't done damage yet, we're just starting out so
    		if (!_doneEating) {
    			// There are many ways to do the timing for the attack, in this case
    			// I'll go the easy route and just wait until the attack time has been hit
    			if (tCurrentState.IsName ("Base Layer.ZfeedingFull") &&
    				tCurrentState.normalizedTime >= _eatTime) {
    				// Here you should call out to your player and make them take damage in some way
    				GameObject tTarget = Target.Evaluate<GameObject> (ai.DeltaTime, ai.WorkingMemory);
    				_doneEating = true;
    				_animator.ResetTrigger ("Eat");  // Added to try and set the animation to NOT play.
    				Debug.Log ("Successfully set EAT to false!");
    				// Grab the entity rig off of our target (again assuming it was detected properly) and mark it inactive
    				EntityRig tEntityRig = tTarget.GetComponentInChildren<EntityRig> ();
    				tEntityRig.Entity.IsActive = false;
    				Debug.Log ("Successfully set FoodEntity.isActive to false!");  // Need a way to wait 60 seconds, then reactivate.
    			}
    			// We'll always return running until we do damage
    			return ActionResult.RUNNING;
    		}
    		// In this case, we just need to wait for our animation to finish
    		// you may need to check for transitioning here too
    		if (tCurrentState.IsName ("Base Layer.ZfeedingFull"))
    			return ActionResult.RUNNING;
    		// And we finished Eating
    		//_animator.ResetTrigger ("Eat");
    		//Debug.Log ("Second set FoodEntity.isActive to false!");  // Need a way to wait 60 seconds, then reactivate.
    		return ActionResult.SUCCESS;
    	}
    }

    inRange is used to initiate attacks using a second smaller visual sensor. Working so far….
    Mark


    Raptcha911
    Participant

    Hey I’m making a prototype project to show my client, the behavior of my game characters. I have two characters running towards each other following different patrol routes from opposite direction and I have two visual sensors on each of them, one for detecting from far away and one for detecting in close range. My behavior tree looks like this -

    And this BT is working fine..The far detector detects the enemy and moves towards it and when the enemy comes in the range of the close range detector, they start attacking each other..But the problem is that, once they start attacking each other, if I move any of the characters manually, out of range of the detectors, nothing changes. They are supposed to stop attacking and start patrolling again, but instead they just keep attacking thin air even when there nothing inside the sensors range. The form variable of the detect nodes do not become null when I move the characters outside the sensor’s bounds. So the control does not flow out of the ‘Constraint’ node which I use to defines attack animations. Please help! either I’m doing something wrong or the detect is not working properly..


    RinAldrin
    Participant

    Basically what I am trying to do is I have a NPC who when he sees and enemy he runs away then stops and looks back to see if he is being chased, if he isn’t then he returns to wandering. The problem is that if I have the primary detect set to repeat until success then after he flees he won’t start detecting again because the detect is not repeating now. However if I have it set to repeating forever then as soon as he stops seeing the enemy he instantly forgets as soon as it leaves the visual detector. So ether I need to set it up so that once he is safe it resets the detect so that he starts wandering again or I need to have the detect send the info to a separate var when he sees the enemy and then clear it once he is safe. Is there a way to do this within the UI or do I have to make a script if so where do I start?

    EDIT: After toying around more I managed to get it working for those who wish to know how I did it here is the export of the XML file.

    <behaviortree version="1.1" repeatuntil="" name="HumanAI" debugbreak="False">
    <sequencer usepriorities="False" repeatuntil="" name="root" debugbreak="False">
    <parallel tiebreaker="fail" succeed="all" repeatuntil="running" name="parallel" fail="any" debugbreak="False">
    <selector usepriorities="False" repeatuntil="running" name="selector" debugbreak="False">
    <constraint repeatuntil="" priority="" name="Wander" debugbreak="False" constraint="Enemies == null">
    <sequencer usepriorities="False" repeatuntil="" name="sequencer" debugbreak="False">
    <parallel tiebreaker="fail" succeed="all" repeatuntil="running" priority="" name="parallel" fail="any" debugbreak="False">
    <detect sensor=""Eyes"" repeatuntil="running" name="detect" matchtype="best" entityobjectvariable="Enemies" debugbreak="False" consistent="True" aspectvariable="" aspectobjectvariable="" aspect=""Enemy"" />
    <sequencer usepriorities="False" repeatuntil="running" name="sequencer" debugbreak="False">
    <action repeatuntil="success" priority="" parametervalues="UmFuZG9tKDQsOCkAdHJ1ZQBIV1A=" parameters="V2FuZGVyRGlzdGFuY2UAU3RheU9uR3JhcGgAV2FuZGVyVGFyZ2V0VmFyaWFibGU=" namespace="" name="action" debugbreak="False" classname="ChooseWanderPosition" />
    <move turnspeed="" repeatuntil="" priority="" name="move" movetarget="HWP" movespeed="HSpeed" facetarget="" debugbreak="False" closeenoughdistance="" closeenoughangle="" />
    <timer waitforsec="Random(4,8)" returnvalue="success" priority="" name="timer" debugbreak="False" />
    </sequencer></parallel></sequencer></constraint>
    <parallel tiebreaker="fail" succeed="all" repeatuntil="" priority="" name="Check for Enemies" fail="any" debugbreak="False">
    <sequencer usepriorities="False" repeatuntil="" name="sequencer" debugbreak="False">
    <action repeatuntil="success" priority="" parametervalues="MzIAWm9tYmxlcwB0cnVlAEZQ" parameters="RmxlZURpc3RhbmNlAEZsZWVGcm9tAFN0YXlPbkdyYXBoAEZsZWVUYXJnZXRWYXJpYWJsZQ==" namespace="" name="Run" debugbreak="False" classname="ChooseFleePosition" />
    <move turnspeed="" repeatuntil="" priority="" name="Run" movetarget="FP" movespeed="HSpeed" facetarget="" debugbreak="False" closeenoughdistance="" closeenoughangle="" />
    <move turnspeed="" repeatuntil="" priority="" name="Check" movetarget="" movespeed="" facetarget="Enemies" debugbreak="False" closeenoughdistance="" closeenoughangle="" />
    <move turnspeed="" repeatuntil="" priority="" name="Clear" movetarget="" movespeed="" facetarget="" debugbreak="False" closeenoughdistance="" closeenoughangle="" />
    <parallel tiebreaker="fail" succeed="any" repeatuntil="" priority="" name="parallel" fail="all" debugbreak="False">
    <timer waitforsec="Random(4.8)" returnvalue="failure" name="timer" debugbreak="False" />
    <detect sensor=""Eyes"" repeatuntil="success" name="detect" matchtype="best" entityobjectvariable="Enemies" debugbreak="False" consistent="True" aspectvariable="" aspectobjectvariable="" aspect=""Enemy"" />
    </parallel></sequencer></parallel></selector></parallel></constraint></sequencer></behaviortree>
    • This topic was modified 7 months, 1 week ago by  RinAldrin. Reason: Fixed
    • This topic was modified 7 months, 1 week ago by  RinAldrin. Reason: More cleaning
    #38641

    elm117
    Participant

    Hi! I’m pretty new to RAIN, in fact I started using it two days ago. I’ve been following tutorials to try to create a simple AI that patrols a Waypoint Route as it starts and whenever the AI sees the player starts to follow him.

    The AI has just one sensor called “Visual Sensor” and one variable in the memory called “FPS” related to the FPSController.
    The FPSController’s entity has the visual aspect “Player”.

    The Behaviour Tree for the AI is pretty simple, I’ll try to attach a pic below.
    It has a Parallel decision with a Detect option repeating forever, with a Form Variable called “seen”, and a Selector with two constraints. And here’s where I think there’s my issue.

    The first constraint is for when the AI sees the player (seen != null) and the other one for when it doesn’t (seen == null)

    Whenever I run the game and check the Behaviour Tree the “seen != null” constraint just doesn’t work.
    I tried not using a constraint for that option by adding a Sequence with the Move action for whenever the other constraint fails, but doesn’t work neither.

    I thought there might be a problem with constraints but the “seen == null” works, so the other should be working too.
    I’ve checked all the variables and I think they’re right.

    I’ve been searching for answers or similar issues around the forum and in other places, as well as the starter kit given in here but I just can’t figure out why it isn’t working.

    Thanks in advance!

    #38539

    Sigil
    Keymaster

    Well, since you are detecting an aspect anyways you probably don’t need the bool anymore. You can also move that if statement logic directly into the behavior tree.

    So your sensor behavior tree can become something like this:

    root
       detect (form variable: playerSeen)

    I used the Form Variable instead of Aspect, because that will store the Entity’s Form into the behavior tree, which is a GameObject we can easily use. I would use the Aspect Variable if I had a custom aspect and custom action to process it, but that’s a more advanced topic.

    In your bridge code you actually don’t need an if statement at all, and can just copy “playerSeen” from one memory to another:

    void Update()
    {
       Ai_Rig_Enemy.AI.WorkingMemory.SetItem("playerSeen", Ai_Rig_Static_Sensor.AI.WorkingMemory.GetItem("playerSeen")); 
    }

    And finally in your enemy behavior tree you can do the actual if statement you previously had in code, and you can move directly to the playerSeen variable:

    root
       constraint (expression: playerSeen != null)
          move (target: playerSeen)

    Does that make sense? I realize it is a bit of a different route, but it is simpler in the long run. There are a lot of ways to do things in RAIN (perhaps too many).

    #38521

    newarkinvaders
    Participant

    cheers guys , many thanks for yourhelp !

    I have got it working in a basic configuration on a new setup and now just need to work in the rest of my a.i for my game.

    One quick amendment i had to make .

    In “constraint” write Sensor_See_Player = true

    did not work for me . It set the enemy move straight away .

    I had to change it to Sensor_See_Player == true it then worked as id hoped .

    #38485

    Inokentych
    Participant

    You need to create communication between sensor ai and enemy character ai. So for example create in memory of Sensor AI bool “See Player”. Create in memory of Enemy Character bool “Sensor_See_Player”. Now make script and attach it to Enemy AI:

    using RAIN.Memory;
    public class Bridge_Enemy_And_Sensor()
    {
     public AIRig Ai_Rig_Enemy; // store reference to ai rig of enemy in field (assign reference via inspector)
     public AIRig Ai_Rig_Static_Sensor; // store reference to ai rig of static sensor in field (assign reference via inspector)
     private bool Sensor_See; // this bool only for visual comfort of code
     void Update()
     {
      Sensor_See = Ai_Rig_Static_Sensor.AI.WorkingMemory.GetItem("See_Player"); // there we get bool state of static sensor
      Ai_Rig_Enemy.AI.WorkingMemory.SetItem("Sensor_See_Player", Sensor_See); // there we assign to Enemy's bool state of sensor's bool "See_Player"
     }
    }

    Last thing you need to create correct behaviour trees for both Ais. For Static Sensor AI make behaviour tree containing “sequencer” node, then make childs of “sequencer” nodes: first “detect” second “expression”. In expression write: See Player = true. So when detect node success second node triggered and make bool true, then in script state of that bool grabbed and transfer to bool of Enemy’s AI. Now make behaviour tree for Enemy Character: “sequencer” and 2 child nodes: first “constraint”, second “move”. In “constraint” write Sensor_See_Player = true and choose repeat mode to “untill success”. So until “constraint” stay false second node “move” not start chase Player. Hope basics of working with rain you know.

    • This reply was modified 7 months, 3 weeks ago by  Inokentych.
    • This reply was modified 7 months, 3 weeks ago by  Inokentych.
    • This reply was modified 7 months, 3 weeks ago by  Inokentych.
    • This reply was modified 7 months, 3 weeks ago by  Inokentych.
    • This reply was modified 7 months, 3 weeks ago by  Inokentych.
    • This reply was modified 7 months, 3 weeks ago by  Inokentych.

    trojanrage
    Participant

    Hello! I am working with RAIN, and I am really enjoying it so far. So first off, thanks for all of the great work!
    I have searched for a lot of my other issues, but I am running into a bit of a wall on these ones, sorry if they were answered elsewhere.

    I have a couple questions, so first let me show you my tree:

    So here are my questions:
    1. The low HP constraint right now is either always on, and blocks the other constraints from triggering, or it has to wait for other constraints to finish. What would a better way to make sure that the low HP stuff always triggers when reached? I need the animal to take off running whenever it’s HP falls below a threshold. (Like even in the middle of it’s patrol)

    2. The “Restore HP” node is an action that restores the HP over time. It works to restore the HP until it gets enough to fix the constraint, but I want it to continue until the HP is full, but not be blocking. I had it set to repeat until true. I thought the best thing then would be for it to start a coroutine in a script. Is there a better idea, or just go with that?

    3. When moving to get back into attack range (setup is similar to the great tutorial vids (#2)), moving just out of range causes some jerky movement. I remeber seeing a post that movement isn’t acceleration based, but I think it was an older post. Is there a way to move just a little bit?

    I am sure I have more things, but this is already a wall of text I am sending, sorry!

    Thanks a lot!

    #37994

    syg
    Participant

    Ok here is how I did it. I used the navigation targets instead of the waypoint route and named them 1,2,3…
    Not sure it’s the best thing to do, but it worked.

    The behaviour tree looks like this:

    EXPRESSION (wp = 1) RETURN SUCCESS
    EXPRESSION (alive = false) RETURN SUCCESS
    SEQUENCER: REPEAT UNTIL SUCCESS
    - SELECTOR
    — CONSTRAINT (alive == true)
    — SEQUENCER: REPEAT UNTIL FAILURE
    —- MOVE (navigationtarget(wp))
    —- EXPRESSION (wp = wp+1)
    — SEQUENCER: REPEAT NEVER
    — EXPRESSION (wp = 1) RETURN SUCCESS
    — EXPRESSION (alive = true) RETURN FAILURE

    And my bot’s script:

    void OnEnable() 
    { 
      AI.WorkingMemory.SetItem("alive", false); 
    }

    Olin
    Participant

    Hi,

    I’m new to RAIN with some programming experience. I am really excited about RAIN but am really struggling to make it work sometimes. I have followed all four tutorials from CodersExpo and gone through the sample project which can be downloaded from the RAIN Tutorial section. I am definitely missing something but have wasted 3 days already trying to make the below bahavior tree work.

    Now. For starters the problem that I have is I can’t get RAIN working with basic behaviors like timers for example. Yes…

    I have a scene where the AI gets spawned in the corridor then it is heading to a nav target at the entrance of the hall and then it is heading to capture the flag nav target at the center of the hall. When AI gets there it detects the player and fires at him in rounds.

    Here my problems start.

    After detecting player the behavior tree of the AI should shoot endlessly at the player in rounds, 5 shots each, 1 second btw each shot and one 3 seconds btw each round. In parallel it is rotating to face the player. The AI behavior tree goes like this.

    [BT] AI logic
    *[SEL] selector
    **[CON] AI in the corridor
    ***[PAR] Move and animate in paraller - this is working. When AI gets to the hall set the inTheHall = true.
    **[CON] isInTheHall == true.
    ***[SEQ] sequencer
    ****[PAR] Move and animate to the nav target ‘flag’ at the center of the hall. When AI gets there…
    ****[PAR] paraller
    *****[ANIM] Stop
    *****[DETECT] Detect player. repeat = forever
    *****[SEL] check if aspect visible
    ******[CON] visible.
    *******[B] Behavior tree binding it handles shooting in rounds /* XML of the below at the end of this post */
    ********[PAR] parallel
    *********[ANIM] face target = player aspect
    *********[SEQ] sequencer. Fire 5 shots then 3 seconds break.
    **********[ITE] count = 5 /* Fire 5 shots */
    ***********[CUST ACN] custom action to spawn the shot prefab. This has been tested in a separate standalone [BT].
    ***********[TIMER] shot interval set to 1 second. Return = success This node is being executed endlessly and returns RUNNING
    **********[TIMER] round interval set to 3 seconds. Return = success. Tree execution never gets here because of the above

    WHAT AM I DOING WRONG ??? Please help.

    Using: UNITY 5.0.0f4 & RAIN 2.1.10.0

    The XML of the first [BT] tree for getting to the flag:

    <behaviortree version="1.1" repeatuntil="" name="BDLogic" debugbreak="False"><selector usepriorities="False" repeatuntil="" 
    name="selector" debugbreak="False"><constraint repeatuntil="" priority="" name="Not in Hall" debugbreak="False" 
    constraint="!isInTheHall"><parallel tiebreaker="succeed" succeed="any" repeatuntil="" name="parallel" fail="any" 
    debugbreak="False"><move turnspeed="" repeatuntil="" name="Target - Hall Entrance" 
    movetarget="navigationtarget("HallEntrance")" movespeed="3" facetarget="" debugbreak="False" closeenoughdistance="" 
    closeenoughangle="" /><animate repeatuntil="" name="WalkAnim" debugbreak="False" animationstate="" /></parallel><expression 
    returnvalue="evaluate" repeatuntil="" name="isInTheHall = true" expression="isInTheHall = true" debugbreak="False" />
    </constraint><constraint repeatuntil="" priority="" name="In the Hall" debugbreak="False" constraint="isInTheHall == true">
    <sequencer usepriorities="False" repeatuntil="" name="sequencer" debugbreak="False"><parallel tiebreaker="succeed" 
    succeed="any" repeatuntil="" priority="" name="Take the Flag" fail="all" debugbreak="False"><move turnspeed="" repeatuntil="" 
    name="Target - Flag" movetarget="navigationtarget("Flag")" movespeed="3" facetarget=""Flag"" debugbreak="False" 
    closeenoughdistance="1" closeenoughangle="" /><animate repeatuntil="" name="WalkAnim" debugbreak="False" animationstate="" />
    </parallel><parallel tiebreaker="fail" succeed="all" repeatuntil="" priority="" name="parallel" fail="any" debugbreak="False">
    <animate repeatuntil="" name="Stop" debugbreak="False" animationstate="" /><detect sensor=""eyes"" repeatuntil="running" 
    name="Detect Trooper" matchtype="best" entityobjectvariable="varCloneTrooper" debugbreak="False" consistent="True" 
    aspectvariable="aspCloneTrooper" aspectobjectvariable="" aspect=""aCloneTrooper"" /><selector usepriorities="False" 
    repeatuntil="" name="selector" debugbreak="False"><constraint repeatuntil="" priority="" name="varCloneTrooper != null" 
    debugbreak="False" constraint="varCloneTrooper != null"><treebinding repeatuntil="" name="BDShoot" debugbreak="False" 
    binding="BDShoot" /></constraint></selector></parallel></sequencer></constraint></selector></behaviortree>

    The XML of the second [B] tree for shooting in rounds:

    <behaviortree version="1.1" repeatuntil="" name="BDShootRounds" debugbreak="False"><parallel tiebreaker="fail" succeed="any" 
    repeatuntil="" name="parallel" fail="all" debugbreak="False"><move turnspeed="" repeatuntil="" name="Face Trooper" 
    movetarget="" movespeed="" facetarget="aspCloneTrooper" debugbreak="False" closeenoughdistance="" closeenoughangle="" />
    <sequencer usepriorities="False" repeatuntil="" name="sequencer" debugbreak="False"><iterator repeatuntil="" priority="" 
    name="FireRound" debugbreak="False" count="5"><timer waitforsec="1" returnvalue="success" name="Shot Interval" 
    debugbreak="False" /></iterator><timer waitforsec="3" returnvalue="success" priority="" name="Round Interval" 
    debugbreak="False" /><action repeatuntil="" priority="" parametervalues="MC41ADIANQ==" 
    parameters="U2hvdEludGVydmFsAFJvdW5kSW50ZXJ2YWwATWF4U2hvdHNQZXJSb3VuZA==" namespace="" name="Shoot Action" debugbreak="False" 
    classname="AIBDShoot" /></sequencer></parallel></behaviortree>
    • This topic was modified 10 months, 3 weeks ago by  Olin.
    • This topic was modified 10 months, 3 weeks ago by  Olin.
    • This topic was modified 10 months, 3 weeks ago by  prime.
    • This topic was modified 10 months, 3 weeks ago by  prime.
    • This topic was modified 10 months, 3 weeks ago by  prime.
    • This topic was modified 10 months, 3 weeks ago by  prime.
Viewing 15 results - 1 through 15 (of 49 total)