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.
-
AuthorPosts
-
October 30, 2022 at 2:25 am #4839
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.
October 30, 2022 at 1:42 pm #4851We 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”.October 30, 2022 at 8:47 pm #4862Hey 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!
October 30, 2022 at 10:50 pm #4866Redofpaw,
Here is the link to our RAIN{indie} sample projects that Prime was talking about
Let me know what you think.
Jester
October 30, 2022 at 11:32 pm #4867Hey 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!
October 31, 2022 at 8:56 pm #4896Ok, 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.
October 31, 2022 at 10:25 pm #4905The
mind.GetObjectWithAspect("targetAspect", out targetToAvoid);
actually translates into
List<RAINAspect> targetsToAvoid = AI.Senses.Match("", "targetAspect");
October 31, 2022 at 10:26 pm #4906Sorry - that would be
IList<RAINAspect> targetsToAvoid = AI.Senses.Match("", "targetAspect");
October 31, 2022 at 10:52 pm #4909Hey 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!
November 1, 2022 at 5:06 pm #4939@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.
November 2, 2022 at 5:59 pm #4963Ok, 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?November 2, 2022 at 11:10 pm #4975AI.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.
November 3, 2022 at 8:22 am #4985@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.
November 3, 2022 at 11:50 am #4987@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?
November 5, 2022 at 5:36 pm #5053I could drop a message to support if that’s better?
-
AuthorPosts
You must be logged in to reply to this topic.