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, 1 month ago.
-
AuthorPosts
-
November 8, 2022 at 3:38 pm #5112
If you haven’t already, please do. Contact Jester directly.
February 19, 2022 at 1:38 am #7984Hello @Prime,
Did a resolution get posted that I missed on this one? I have a group of the attackers and of course they are all more or less in single file. I was hoping the “Avoidance” would help me to keep them spread out and more realistic.
February 21, 2022 at 1:25 am #8152Haven’t had a chance to take a look yet. I’ll see if I can get to it tonight.
February 21, 2022 at 8:08 pm #8197Excellent … thanks
February 25, 2022 at 1:27 am #8407Has this issue been resolved? I often can’t match projects I receive to the forum posts here.
February 27, 2022 at 1:02 am #8614Well, I read that you were going to check for something regarding “Avoidance”. (?)
February 27, 2022 at 8:36 pm #8664Hey Redofpaw,
The video tutorial, you linked to above, was an old one I did with RAIN {indie}. Since the upgrade stuff has changed quite a bit. Try this code here. I’m assuming you (and anyone reading this..) will have already watched the basic tutorial videos Prime did. Anyway, basic behavior tree setup with a parallel node. Add the detect and custom action child nodes. Be sure the object doing the running away has a sensor. Add an aspect to your character (the one he is running fromusing UnityEngine;
using System.Collections;
using System.Collections.Generic;
using RAIN.Core;
using RAIN.Action;
//using RAIN.BehaviorTrees;
using RAIN.Entities.Aspects;
//using RAIN.Minds;
//using RAIN.Memory;[RAINAction]
public class PlayerAvoidance : RAINAction
{
private const float MINIMUM_DISTANCE = 3f;private Vector3 _target;
private IList<RAINAspect> _targetsToAvoid;public PlayerAvoidance()
{
actionName = “PlayerAvoidance”;
}public override void Start(AI ai)
{
_targetsToAvoid = ai.Senses.Match(“Visual”, “HeroAspect”);
base.Start(ai);
}public override ActionResult Execute(AI ai)
{
if(_targetsToAvoid != null)
{
foreach(var aspect in _targetsToAvoid)
{
if(isToClose(ai,aspect))
{
doAvoidance(ai, aspect);
}
}
}return ActionResult.SUCCESS;
}public override void Stop(AI ai)
{
base.Stop(ai);
}#region
private void doAvoidance(AI ai, RAINAspect aspect)
{
var direction = ai.Kinematic.Position - aspect.Position;
//direction.Normalize();
ai.Motor.MoveTo(ai.Kinematic.Position + direction);
}private bool isToClose(AI ai, RAINAspect aspect)
{
var dist = Vector3.Distance(ai.Kinematic.Position, aspect.Position);if(dist <= MINIMUM_DISTANCE)
return true;return false;
}
#endregion
}February 28, 2022 at 2:25 am #8697Just wanted to add a line to keep the target facing you…..
if(dist <= MINIMUM_DISTANCE)
return true;_target = aspect.Entity.Form.transform;
ai.Motor.FaceAt(_target.position);
return false;
-
AuthorPosts
You must be logged in to reply to this topic.