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.

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #5112

    prime
    Keymaster

    If you haven’t already, please do. Contact Jester directly.

    #7984

    emmcd3
    Participant

    Hello @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.

    #8152

    prime
    Keymaster

    Haven’t had a chance to take a look yet. I’ll see if I can get to it tonight.

    #8197

    emmcd3
    Participant

    Excellent … thanks

    #8407

    prime
    Keymaster

    Has this issue been resolved? I often can’t match projects I receive to the forum posts here.

    #8614

    emmcd3
    Participant

    Well, I read that you were going to check for something regarding “Avoidance”. (?)

    #8664

    CodersExpo
    Participant

    Hey 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 from

    using 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
    }

    #8697

    CodersExpo
    Participant

    Just 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;

Viewing 8 posts - 16 through 23 (of 23 total)

You must be logged in to reply to this topic.