public override Status Run(float dt, BehaviourContext context)
    {
        WanderContext _context = (WanderContext)context;
        Vector2       center   = _context.go.transform.position;

        Collider2D[] entities = Physics2D.OverlapCircleAll(center, radius);
        if (entities.Length <= 1)
        {
            return(Status.FAIL);
        }
        else
        {
            for (int i = 0; i < entities.Length; i++)
            {
                if (entities[i].gameObject.CompareTag(tag))
                {
                    colliders.Add(entities[i]);
                }
            }
            if (colliders.Count > 0)
            {
                GameObject entity = colliders[Random.Range(0, colliders.Count)].gameObject;
                _context.aroundGO     = entity;
                _context.moveToTarget = _context.aroundGO.transform.position;
                return(Status.SUCCESS);
            }
            return(Status.FAIL);
        }
    }
Esempio n. 2
0
    public override void Start(BehaviourContext context)
    {
        WanderContext _context = (WanderContext)context;

        _context.timer.After(duration, () => {
            done = true;
        });
    }
Esempio n. 3
0
    public override Status Run(float dt, BehaviourContext context)
    {
        float angle    = Random.Range(0, 2 * Mathf.PI);
        float distance = Random.Range(0, radius);

        WanderContext _context = (WanderContext)context;

        _context.moveToTarget = new Vector2(this.x + distance * Mathf.Cos(angle), this.y + distance * Mathf.Sin(angle));
        _status = Status.SUCCESS;
        return(_status);
    }
Esempio n. 4
0
    public override Status Run(float dt, BehaviourContext context)
    {
        WanderContext _context = (WanderContext)context;
        GameObject    obj      = ((WanderContext)context).go;
        float         distance = Vector2.Distance(obj.transform.position, _context.moveToTarget);

        if (distance < 0.1)
        {
            return(Status.SUCCESS);
        }
        obj.transform.position = Vector2.MoveTowards(obj.transform.position, _context.moveToTarget, speed * dt);
        return(Status.RUNNING);
    }
    public override void Start(BehaviourContext context)
    {
        WanderContext _context = (WanderContext)context;
        Timer         timer    = _context.timer;

        GameObject _target = _context.aroundGO;

        SpriteRenderer renderer = _target.GetComponent <SpriteRenderer>();

        renderer.color = color;
        timer.After(2, () =>
        {
            renderer.color = Color.white;
            done           = true;
        });
    }
Esempio n. 6
0
    // Use this for initialization
    void Start()
    {
        context = new WanderContext {
            go    = obj,
            timer = new Timer()
        };

        root = new Root(context, new Selector("idle",
                                              new Sequence("Fighting animal",
                                                           new DebugAction(Time.frameCount.ToString()),
                                                           new AnyAroundAction("Animal", 0.5f),
                                                           new RepeateUntilFail(
                                                               new Sequence("Chasing animal",
                                                                            new AnyAroundAction("Animal", 0.5f),
                                                                            new Parallel("Chase", ParallelPocity.ALL, ParallelPocity.ALL,
                                                                                         new DebugAction("I'm chasing"),
                                                                                         new Sequence("Attacking",
                                                                                                      new AnyAroundAction("Animal", 0.25f),
                                                                                                      new ChangeColorAction(Color.yellow)
                                                                                                      )
                                                                                         )
                                                                            )
                                                               )
                                                           ),
                                              new Sequence("Change enemies color",
                                                           FindAndMoveTo("Enemies", 1.5f),
                                                           new ChangeColorAction(Color.red)
                                                           ),
                                              new Sequence("Change friends color",
                                                           FindAndMoveTo("Player", 1f),
                                                           new ChangeColorAction(Color.blue)
                                                           ),
                                              new Sequence("wander",
                                                           new FindWanderPointAction(obj.transform.position.x, obj.transform.position.y, 2),
                                                           new MoveToPointAction(),
                                                           new WaitAction(1)
                                                           )
                                              ));
    }