News Forums Search Search Results for 'set variable'

Viewing 15 results - 1 through 15 (of 255 total)
  • Author
    Search Results
  • #34881

    In reply to: Pathfinding problem


    uservs
    Participant

    I set Step Up Height to some large value (100f) and problem was resolved.
    Today I downloaded RAIN 2.1.7.2 package and updated my project from 2.1.6.1. I found new problem with frequent mouse clicks. Each mouse click changes target for Move action through working memory Vector3 variable. After first target selection units are moving correctly. Next 1-2 quick clicks are provide a bug with path planning. Units try to move to the target directly. Unfortunately I cannot send full project for you. Maybe I can do a little test. This bug is new in 2.1.7.2 version. I tested this problem for 2.1.6.1 and bug was not detected.

    #34845

    prime
    Keymaster

    Character controller is pretty heavyweight. It chews up a lot of CPU, so we don’t use it unless we really need to.

    Threat information is set in the HealthElement ReceiveDamage method. The “playerThreat” variable itself is assigned in the player’s AI->Custom Elements->Health Element as the Broadcast Threat Variable.

    #34835

    prime
    Keymaster

    ai.Body will be the game object of the AI itself, so you don’t want that. If you are applying damage to an object that you detected with a sensor, and you are setting the Form Variable through the sensor, then

    GameObject tSensedObject = ai.WorkingMemory.GetItem<GameObject>("myFormVariable"); //whatever your variable name is, which should be used in the Form Variable field of the sensor
    tSensedObject.SendMessage("Damage", 1.0f, SendMessageOptions.DontRequireReceiver);
    #34831

    prime
    Keymaster

    That depends a lot on your behavior tree. Are you integrating that with other behaviors, or is that the main behavior of the tree?

    Regardless of exactly how you do it, the general approach would be to recognize the click, then set an AI.WorkingMemory variable that triggers the behavior in the behavior tree.

    #34809

    prime
    Keymaster

    Any changes you make to the behavior tree at runtime, including toggling the debug break option, does cause the behavior tree to reset. When it resets, it starts back at the top of the tree.

    The reason the detect isn’t nulling out the variable is that once it detects the target, it never runs again. In the sequencer, the Detect will run until it succeeds, then move on to the Move node. The Move node repeats forever, so the detect will never run again and will never get a chance to unset the variable (which is why using a parallel is necessary.)

    We’re already looking at numerous changes to the behavior editor, including limiting when the BT gets reset. Thanks for the suggestion on swapping the name of the node in the default case.

    #34805

    WiredEarp
    Participant

    I have a very basic AI test project. In this project, I have a Target and an Enemy. In the BT, I meant to use a PARALLEL for the header, but accidentally changed it using ‘switch to’ to a SEQ while playing around (its a bit of a gotchya that it doesn’t change the name of the node when you do this switch, although I can see why it has this behaviour. Perhaps if the node has the default name though, it should be switched to the correct name of the node on using ‘Switch To’, to avoid confusion).

    Anyway, using the SEQ, I noticed a strange behaviour. Specifically, I have this setup:

    SEQ (repeat forever)
    - DETECT (until success) - this sets a form variable DetectTargetPos
    - MOVE (forever)

    I would have expected the detect to null the DetectTargetPos once the target was out of detection range. However, this doesnt happen - if I move the target out of range of the Enemy, it still moves to the target. HOWEVER, if I click ‘Debug Break’ on any of these nodes, then the DetectTargetPos variable IS nulled (and so the enemy stops chasing). This happens even if I double click the Debug Break quickly enough that it doesn’t actually get hit, so doesn’t pause the game. So, behaviour when I double click ‘Debug Break’ is different to when I dont.

    I’ve moved my header node back to a PARALLEL which works fine for me, but would like to know exactly why using the Debug Break option is giving different behaviour when I use it to when I dont? I thought Debug Break was simply setting a breakpoint, but it seems to be forcing some sort of refresh?

    If necessary, I can upload my sample project, but it should be simple to replicate. I’m running RAIN 2.1.6.1 which I believe is the latest.

    #34766

    rainingrick
    Participant

    Continued to get odd movement!

    I watched this video (https://www.youtube.com/watch?v=YuaBBCL5PSs#t=11) and there doesn’t seem to be any character controller or rigid body used here?

    Could it be a problem with the nav mesh?

    I’ve also noticed that the minute I add a rigid body and character controller my character starts to get stuck a LOT!

    As a bit of background, I’m generating my NavMesh based on the code in this example: http://rivaltheory.com/wiki/rainelements/navmeshrig

    The general setup is:

    NavMesh
    I have several obstacles.

    My character has a behaviour tree which has a waypoint patrol variable which is set via

    aiRig.AI.WorkingMemory.SetItem<string>(“patrolRoute”, patrolName);

    The character set up is:

    Character

    Is there anyway to get source code so that I can debug!

    • This reply was modified 1 week, 6 days ago by  rainingrick.
    • This reply was modified 1 week, 6 days ago by  rainingrick.
    #34754

    In reply to: Constraints


    prime
    Keymaster

    First, you should probably use float instead of double. Especially for time.

    If you are trying to make the value of the timer variable available in AI Memory and accessible by the Behavior Tree Expressions, then you will need to do this in your custom action:

    ai.WorkingMemory.SetItem<float>("timer", timer);

    The AI mind doesn’t have a time variable. The right approach is to use WorkingMemory to store information.

    #34752

    In reply to: Constraints


    rbranch1
    Participant

    Im also having trouble setting my timer to a public instance variable in my custom action

    i said public double timer = 0.0;, set it to 80.0 in the execute function in the custom action, then tried to use a timer action, setting the time to “timer” ( i tried timer without quotes as well), and it doesnt work. Any suggestions? Im actually trying to utilize the ai mind. Is there a way I could set a mind variable to my timer data member? I tried ai.Body.Mind.time = timer; ai.Mind.time = timer; and ai.time = timer;

    • This reply was modified 2 weeks, 2 days ago by  rbranch1.
    #34745

    prime
    Keymaster

    This is a better Wander point chooser. User Repeat Until Success to ensure it chooses a valid wander position.

    using UnityEngine;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Action;
    using RAIN.Core;
    using RAIN.Representation;
    using RAIN.Navigation;
    [RAINAction("Choose Wander Position")]
    public class ChooseWanderPosition : RAINAction
    {
        /// <summary>
        /// Public Expressions are editable in the Behavior Editor
        /// WanderDistance is the max range to use when picking a wander target
        /// </summary>
        public Expression WanderDistance = new Expression();
        /// <summary>
        /// Public Expressions are editable in the Behavior Editor
        /// StayOnGraph is a boolean (true/false) that indicates whether the wander target must be on the nav graph
        /// </summary>
        public Expression StayOnGraph = new Expression();
        /// <summary>
        /// Public Expressions are editable in the Behavior Editor
        /// WanderTargetVariable is the name of the variable that the result will be assigned to
        /// *Don't use quotes when typing in the variable name
        /// </summary>
        public Expression WanderTargetVariable = new Expression();
        /// <summary>
        /// The default wander distance to use when the WanderDistance is invalid
        /// </summary>
        private float _defaultWanderDistance = 10f;
        public override ActionResult Execute(RAIN.Core.AI ai)
        {
            if (!WanderTargetVariable.IsVariable)
                throw new Exception("The Choose Wander Position node requires a valid Wander Target Variable");
            float tWanderDistance = 0f;
            if (WanderDistance.IsValid)
                tWanderDistance = WanderDistance.Evaluate<float>(ai.DeltaTime, ai.WorkingMemory);
            if (tWanderDistance <= 0f)
                tWanderDistance = _defaultWanderDistance;
            Vector3 tDirection = new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f));
            tDirection *= tWanderDistance;
            Vector3 tDestination = ai.Kinematic.Position + tDirection;
            if (StayOnGraph.IsValid && (StayOnGraph.Evaluate<bool>(ai.DeltaTime, ai.WorkingMemory)))
            {
                if (NavigationManager.Instance.GraphForPoint(tDestination, ai.Motor.DefaultStepUpHeight).Count == 0)
                    return ActionResult.FAILURE;
            }
            ai.WorkingMemory.SetItem<Vector3>(WanderTargetVariable.VariableName, tDestination);
            return ActionResult.SUCCESS;
        }
    }
    #34740

    prime
    Keymaster

    To do this, I would:
    1) Create a set of lanes I’m going to allow my horses to run in. Not real lanes, but rather a set of virtual arcs around the track that I can assign horses to.
    2) Assign the move target to each horse as a position along an arc, a short distance in front of the horse. If the horse switches “lanes” then I would just move the target over to the next lane and start moving along the new arc. (horses should have a very small turn angle during the race so their lane switching is smooth
    3) Use a variable to represent speed in my Move node. Adjust the variable on the fly through code. Make sure the move target stays a bit in front of the horse, along the arc, no matter how fast the horse is moving.
    4) You can deal with colliding by ensuring the targets keeps some distance from each other or simply enforcing certain spacing along the arc and reducing speeds accordingly.

    It’s a pretty simple setup and wouldn’t take long to implement.

    #34738

    prime
    Keymaster

    I’m not certain, but it looks to me like you have your variables mixed up in your Waypoint node. The wander script is setting your destination into the varMoveTo variable. In your waypoint node that should be your PathTarget - the place you are trying to create a path to. The MoveTargetVariable is the name of the variable you are passing to the move node inside the waypoint node. So:
    - use varMoveTo as your PathTarget
    - use varNext as your MoveTargetVariable
    - make sure your move node Move Target is set to varNext

    #34736

    In reply to: Constraints


    prime
    Keymaster

    There currently isn’t a distance function in RAIN expressions. That means you will have to rely on code to calculate the distance between 2 objects, or between the AI and some other object. Just use a custom action to set a memory variable.

    To force the sequencer to FAIL whenever the AI is already close enough, add an “Evaluate Expression” node as the first node under the sequencer. Do the distance check in that, so:
    SEQUENCER
    — EVALUATE (distance > 3)
    — ALL YOUR OTHER NODES

    If you don’t want a FAIL case, then use a selector instead
    SELECTOR
    — EVALUATE (distance > 3)
    — SEQUENCER
    — — ALL YOUR OTHER NODES

    #34733

    Velathora
    Participant

    Hello all,

    I’ve been following along @CodersExpo ‘s tutorials and had no issues until the last and final tutorial.

    I seem to be having issues with the custom action and the wander.

    Basically, I am able to get the character to run at the hero, wave (instead of punch) when within the “near” detector range, and whilst within his normal patrol route, idle randomly within the timer intervals set in BT.

    Afterwards, we had been advised to get the custom action created to allow the character to wander after the Hero takes cover and removes himself from line of sight. At that point, I have the parallel node showing a failure and the waypoint path node showing a failure as well. It seems odd because it states that the execution of the previous “WanderLocation” custom action is succeeding as needed.

    For reference,

    BT:

    ->PAR-RPT:Never, Fail:Any, Succeed:Any, TieBreaker:Fail
    ->->Detect-Sensor:"eyes", Aspect:"aHero", FormVariable:varHero
    ->->Detect-Sensor:"close", Aspect:"aHero", FormVariable:varNear
    ->->Selector
    ->->->Constraint(TreeHereWorksPerfectly)
    ->->->Constraint(TreeHereWorksPerfectly)
    ->->->Constraint-Constraint:varHero == null && isSearching (shows fail)
    ->->->->Custom Action - Name:WanderLocation, Assembly:(global), Class:WanderLocation (Succeeds)
    ->->->->PAR - RPT:Never, Fail:Any, Succeed:Any, TieBreaker:Succeed (Fails)
    ->->->->->WaypointPath - WaypointNetwork:"Wander", PathTarget:varNext, MoveTargetVariable:varMoveTo (Fails)
    ->->->->->->Move-MoveTarget:varMoveTo, MoveSpeed:3 (NeverCalled)
    ->->->->->Animate - AnimationState:Walk (fails)

    Custom Action Script “WanderLocation”:

    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 WanderLocation : RAINAction
    {
    		private static float _time = 0f;
    		public override void Start (RAIN.Core.AI ai)
    		{
    				base.Start (ai);
    				_time += Time.time;
    		}
    		public WanderLocation ()
    		{
    				actionName = "WanderLocation";
    		}
    		public override ActionResult Execute (RAIN.Core.AI ai)
    		{
    				Vector3 loc = Vector3.zero;
    				List<RAINNavigationGraph> found = new List<RAINNavigationGraph> ();
    				do {
    						loc = new Vector3 (ai.Kinematic.Position.x + Random.Range (-8f, 8f),
    			                  ai.Kinematic.Position.y,
    			                  ai.Kinematic.Position.z + Random.Range (-8f, 8f));
    						found = NavigationManager.Instance.GraphsForPoints (ai.Kinematic.Position, 
    			                                                    loc, 
    			                                                    ai.Motor.StepUpHeight, 
    			                                                    NavigationManager.GraphType.Navmesh,
    			                                                    ((BasicNavigator)ai.Navigator).GraphTags);
    				} while((Vector3.Distance(ai.Kinematic.Position, loc)<2f)||(found.Count == 0));
    				ai.WorkingMemory.SetItem<Vector3> ("varMoveTo", loc);
    				if (_time > 5000f) {
    						ai.WorkingMemory.SetItem ("isSearching", false);
    				}
    				return ActionResult.SUCCESS;
    		}
    		public override void Stop (RAIN.Core.AI ai)
    		{
    				base.Stop (ai);
    		}
    }

    So essentially, the character will run on the spot after losing detection and is set to “isSearching”, and after 5 seconds or so, he will then return to the normal patrol route. This is unexpected behaviour, simply because he should instead be wandering around searching on the waypoint network for signs of the hero.

    Would really appreciate the assistance to wrap my head around RAIN AI.

    Cheers.

    • This topic was modified 2 weeks, 2 days ago by  Velathora. Reason: Cleaned
    • This topic was modified 2 weeks, 2 days ago by  Velathora. Reason: Clarify end
    #34657

    Velathora
    Participant

    Unfortunately, it still seems like this isn’t working.

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    using RAIN.Navigation;
    using RAIN.Navigation.Waypoints;
    public class FindToggleSet : MonoBehaviour
    {
    		//create a private gameobject that will hold the detected entity
    		private GameObject tDetected;
    		//create an artificial intelligence rig and preset to null
    		private AIRig aiRig = null;
    		//string to hold wp route
    		private string theRoute;
    		//private waypointset
    		private WaypointSet tWaypointSet;
    		//newStart Pos
    		private Vector3 tInitPos;
    		void Start ()
    		{
    				theRoute = "PatrolRoute";
    				tWaypointSet = NavigationManager.Instance.GetWaypointSet (theRoute);
    				tInitPos = tWaypointSet.Waypoints [0].position;
    				aiRig = gameObject.GetComponentInChildren<AIRig> ();
    				Debug.Log (tInitPos);
    				aiRig.AI.WorkingMemory.SetItem<Vector3> ("nextStop", tInitPos);
    		}
    		void Update ()
    		{
    				tDetected = aiRig.AI.WorkingMemory.GetItem<GameObject> ("varNear");
    				if (tDetected != null) {
    						if (tDetected.GetComponent<ToggleSet> ().isRed) {
    								theRoute = "PatrolRoute";
    								aiRig.AI.WorkingMemory.SetItem ("theRoute", theRoute);
    								tWaypointSet = NavigationManager.Instance.GetWaypointSet (theRoute);
    								tInitPos = tWaypointSet.Waypoints [0].position;
    								aiRig.AI.WorkingMemory.SetItem<Vector3> ("nextStop", tInitPos);
    								Debug.Log ("Red: " + tInitPos);
    						} else if (tDetected.GetComponent<ToggleSet> ().isGreen) {
    								theRoute = "PatrolRouteAttempt2";
    								aiRig.AI.WorkingMemory.SetItem ("theRoute", theRoute);
    								tWaypointSet = NavigationManager.Instance.GetWaypointSet (theRoute);
    								tInitPos = tWaypointSet.Waypoints [0].position;
    								aiRig.AI.WorkingMemory.SetItem<Vector3> ("nextStop", tInitPos);
    								Debug.Log ("Green: " + tInitPos);
    						}
    				}
    		}
    }

    Sorry if I’m not quite bright in this area, first time working with RAIN.

    As a note: It seems to Log the right coordinates for the initial position, but it still goes to closest node on the opposing path.

    Perhaps the “nextStop” variable in the “MoveTarget” of the waypoint is not being set properly in working memory?

    • This reply was modified 2 weeks, 4 days ago by  Velathora. Reason: clarify
    • This reply was modified 2 weeks, 4 days ago by  Velathora. Reason: clarify and cleanup
Viewing 15 results - 1 through 15 (of 255 total)