News Forums RAIN General Discussion and Troubleshooting AI "Collision" solutions.

This topic contains 22 replies, has 7 voices, and was last updated by  CodersExpo 1 year, 4 months ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #4839

    safacon
    Participant

    How would you go about setting up ‘collision’ (or illusion of…) for the AI? Anyone have any methods that they have used or can think of? All I really want is for AI that is doing similar stuff to not end up walking inside of each other all the time and to path around other non-AI dynamic objects.

    #4851

    prime
    Keymaster

    We have some simple avoidance examples at support.rivaltheory.com related to RAIN{indie}. Those techniques can still apply to RAIN.

    However, we also have additional solutions coming soon in planned updates. Among them are:
    - Dynamic repathing for obstacle avoidance. This will allow AI to create localized paths for avoidance while maintaining their global paths to a target.
    - Waypoint lanes. You will be able to assign “lanes” to your waypoints and give AI lane choice preferences. This can be used for AI walking in corridors, on sidewalks, and in other places where many AI may take similar paths. You should be able to say things like “AI should prefer walking on the right hand side”.

    #4862

    Redofpaw
    Participant

    Hey Prime. Looked around but couldn’t fine the examples you mention - just a project where the objects have ‘avoid obstacles’ switched on.

    Could you point us in the right direction? Or maybe briefly summarize the theory of how to get two AIs (let’s say they are identical and following waypoints or similar) to avoid each other?

    Many thanks!

    #4866

    Jester
    Keymaster

    Redofpaw,

    Here is the link to our RAIN{indie} sample projects that Prime was talking about

    Let me know what you think.

    Jester

    #4867

    Redofpaw
    Participant

    Hey Jester. I’ve looked, but not sure which one has what we need. It appears ‘avoid obstacles’ is checked to avoid other AIs etc… but we don’t appear to have that option in the new Rain?

    Where might we find the specific ‘avoid obstacle’ type behaviour we wish to implement now?

    To recap: Currently my AIs are wandering through each other, rather than around like Indie used to manage.

    Thanks!

    #4896

    Redofpaw
    Participant

    Ok, so I’m making some progress. I believe if I have a PAR running that attempts to move away from a detected entity it will combine with the waypoint move node to produce an avoidance-like behaviour.

    I am attempting to adapt the custom script from this tutorial video:

    -

    -

    However I am having a little trouble adapting one of the code lines to fit the new API:
    -
    RAIN.Core.Mind mind = agent.Mind;
    -
    The changes to RAIN make most of this difficult to figure out where it all goes. Meanwhile I am also having trouble with the following:
    -
    mind.GetObjectWithAspect(“targetAspect”, out _targetToAvoid);
    -
    I have, I believe, narrowed it down to BasicMemory GetItem(T) - and I will no longer be looking for the ‘aspect’, but the ‘variable’ the detector spits out.

    The rest of it seems pretty comprehensible, but these two lines are throwing me currently.

    • This reply was modified 1 year, 8 months ago by  Redofpaw.
    #4905

    prime
    Keymaster

    The

    mind.GetObjectWithAspect("targetAspect", out targetToAvoid);

    actually translates into

    List<RAINAspect> targetsToAvoid = AI.Senses.Match("", "targetAspect");
    #4906

    prime
    Keymaster

    Sorry - that would be

    IList<RAINAspect> targetsToAvoid = AI.Senses.Match("", "targetAspect");
    #4909

    Redofpaw
    Participant

    Hey Prime, dropping that line in causes:

    Assets/AI/Actions/enAvoidance.cs(30,23): error CS0246: The type or namespace name `RAINAspect’ could not be found. Are you missing a using directive or an assembly reference?

    Am I missing something?

    In any case, what I am attempting to do is move away from an object hitting the detector in the BT. What might you recommend?

    Thanks again!

    #4939

    Aaron Mueller
    Participant

    @Redofpaw,
    I am guessing that you are missing an assembly reference.
    -
    At the top of your script, perhaps you should try adding:

    using RAIN.Entities.Aspects;

    Alternately, I believe you could rewrite that line as:

    IList<RAIN.Entities.Aspects.RAINAspect> targetsToAvoid = AI.Senses.Match("", "targetAspect");

    NOTE: I haven’t experimented as much yet, so I’m not sure exactly which to include.

    • This reply was modified 1 year, 8 months ago by  Aaron Mueller.
    #4963

    Redofpaw
    Participant

    Ok, so I am currently here, with a few errors:

    
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using RAIN.Core;
    using RAIN.Action;
    using RAIN.BehaviorTrees;
    using RAIN.Entities;
    using RAIN.Minds;
    using RAIN.Memory;
    using RAIN.Entities.Aspects;
    [RAINAction]
    public class enAvoidance : RAINAction
    {
    	private Vector3 _agentPos = Vector3.zero;
    	private Vector3 _directionToRun = Vector3.zero;
    	private Vector3 _moveToLocation = Vector3.zero;
    	private GameObject _targetToAvoid;
        public enAvoidance()
        {
            actionName = "enAvoidance";
        }
        public override void Start(AI ai)
        {
    		_agentPos = ai.Kinematic.Position;
    		RAIN.Minds.RAINMind mind = ai.Mind;
    		IList<RAINAspect> _targetsToAvoid = AI.Senses.Match("", "targetAspect");
    		//IList<RAIN.Entities.Aspects.RAINAspect> targetsToAvoid = AI.Senses.Match("", "targetAspect");
    		if(_targetToAvoid != null && _moveToLocation)
    		{		
    			_directionToRun = _agentPos - _targetToAvoid.transform.position;
    			_moveTo+ _directionToRun;
    		}
            base.Start(ai);
        }
        public override ActionResult Execute(AI ai)
        {
    		if(!ai.Motor.MoveTo(_moveToLocation))
    		{
    		return ActionResult.RUNNING;	
    		}
    		else
    		{
    			_moveToLocation = Vector3.zero;
    		}
            return ActionResult.SUCCESS;
        }
        public override void Stop(AI ai)
        {
            base.Stop(ai);
        }
    }
    

    The errors are as follows:
    .
    Assets/AI/Actions/enAvoidance.cs(36,56): error CS0120: An object reference is required to access non-static member `RAIN.Core.AI.Senses’

    Assets/AI/Actions/enAvoidance.cs(39,20): error CS0019: Operator “&&” cannot be applied to operands of type “bool” and `UnityEngine.Vector3′
    .
    Any tips?

    • This reply was modified 1 year, 8 months ago by  Redofpaw.
    • This reply was modified 1 year, 8 months ago by  Redofpaw.
    • This reply was modified 1 year, 8 months ago by  Redofpaw.
    • This reply was modified 1 year, 8 months ago by  Redofpaw.
    #4975

    prime
    Keymaster

    AI.Senses.Match should be ai.Senses.Match

    your second error refers to this line:

    if(_targetToAvoid != null && _moveToLocation)

    I’m not sure why you have the “&& _moveToLocation” part.

    #4985

    Redofpaw
    Participant

    @prime - it was in the original tutorial, so I kept it as it was. I have removed it and it’s no longer a problem apparently.

    I am still getting:

    Assets/AI/Actions/enAvoidance.cs(36,56): error CS0120: An object reference is required to access non-static member`RAIN.Core.AI.Senses’

    • This reply was modified 1 year, 8 months ago by  Redofpaw.
    #4987

    Redofpaw
    Participant

    @prime It looks to me as if we are trying to get a list of aspects and put them all in _targetsToAvoid.

    The script is then using a different Vector3 _targetToAvoid. However, even if it were the same, would this script actually cause the AI to avoid all the different objects with that aspect? Seems to me it would only attempt to ‘avoid’ one, yet we are looking for a ‘list’ of them?

    #5053

    Redofpaw
    Participant

    I could drop a message to support if that’s better?

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.