News Forums Search Search Results for 'variable'

Viewing 15 results - 1 through 15 (of 425 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.

    #34860

    Alex3D
    Participant

    Hi,
    I have similar problem.

    //		private VisualAspect aspect;
    		private EntityRig localEntity;
    		// Use this for initialization
    		void Start () {
    			localEntity = GetComponentInChildren<EntityRig>();
    			if (localEntity == null){
    				localEntity = EntityRig.AddRig(gameObject);
    				localEntity.Entity.EntityInit();
    			}
    			VisualAspect aspect;
    			aspect = localEntity.Entity.GetAspect(Mind.COVER_ASPECT_NAME) as VisualAspect;
    			if (aspect == null)
    			{
    				Debug.Log("=============== No aspect");
    				aspect = new VisualAspect(); 
    				aspect.AspectName = Mind.COVER_ASPECT_NAME;
    				aspect.MountPoint = transform;
    				aspect.VisualSize = 1.0f;
    				localEntity.Entity.AddAspect(aspect);
    			}
    		}

    EntityRig appears, aspect - dont. In first variant it was TacticalAcpect, then I change it to Visual…
    Code pattern was taken from Advances Warfighter TeamElement.
    What can be wrong in this 3 lines? Ive tried some variants, persistent and temporally variables, nothing helps.
    May be it cant work in context of Start or MonoBehavior?

    #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.

    #34841

    Alex3D
    Participant

    Hi,
    I have some questions:
    1. Why did you prefer CapsuleCollider + Rigidbody instead of CharacterController?
    2. Where does you fill value into “playerThreat” RAIN variable?
    Thanks

    #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.

    #34814

    Sprakle
    Participant

    The MoveLookTarget was coming from a Detect action followed by a Move action. There doesn’t seem to be a way to make them give a variable target.

    However, getting the target variable from memory by name should work. Thanks for the tip!

    #34812

    prime
    Keymaster

    The MoveTarget is a MoveLookTarget under the hood. A MoveLookTarget can encapsulate a lot of different types of targets, including Aspect, Transform, NavigationTarget, Vector3, Kinematic, and Variable. You can tell which type your MoveLookTarget contains by checking its TargetType property. It’s possible that your MoveLookTarget is variable type, in which case VariableTarget contains the name of the variable that holds the actual target. You can use GetTargetFromVariable to get another MoveLookTarget that has a direct reference to the contents of your variable, or you can just use AI.Memory.GetItem() to grab the variable directly out of memory (assuming you know its type).

    #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.

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