Exemple #1
0
    // Use this for initialization
    void Start()
    {
        target    = gameObject;
        boids     = new List <GameObject>();
        deadBoids = new List <GameObject>();
        for (int i = 0; i < numberOfBoids; i++)
        {
            Vector3 pos = transform.position + Random.insideUnitSphere * spawnRadius;
            pos.y = 0.0f;
            Quaternion rot = Quaternion.Euler(0, Random.Range(0, 360), 0);
            boids.Add(Instantiate(boidPrefab, pos, rot));
            boids[i].GetComponent <Boid>().flock = this;
            // TODO - Configure the combat AI on the boid we just built.
            // get the tree, and set any blackbaord variables it may need, such as the mask, the object hit (which will be null to start), the shooting range

            BehaviorTree bt = boids[i].AddComponent <BehaviorTree>();
            bt.AddKey("target");
            bt.AddKey("wait", Random.Range(1.0f, 2.0f));

            Sequence sq = new Sequence();
            sq.tree = bt;
            bt.root = sq;
            //Wait is used because it chaos without it
            Wait wait = new Wait();
            wait.tree          = bt;
            wait.TimeToWaitKey = "wait";

            ZapTarget zt = new ZapTarget();
            zt.tree      = bt;
            zt.TargetKey = "target";

            DetectTarget dt = new DetectTarget();
            dt.tree      = bt;
            dt.TargetKey = "target";

            DamageBoid db = new DamageBoid();
            db.tree      = bt;
            db.TargetKey = "target";

            sq.children.Add(wait);
            sq.children.Add(dt);
            sq.children.Add(zt);
            sq.children.Add(db);
        }
    }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        Selector     TreeRoot       = new Selector();
        Sequence     ShootSequence  = new Sequence();
        DetectTarget detectTask     = new DetectTarget();
        ZapTarget    zapTask        = new ZapTarget();
        DamageBoid   damageBoidTask = new DamageBoid();

        SetValue("selfBoid", Boid);
        SetValue("Line", line);

        ShootSequence.children.Add(detectTask);
        ShootSequence.children.Add(zapTask);
        ShootSequence.children.Add(damageBoidTask);
        TreeRoot.children.Add(ShootSequence);
        ShootSequence.tree  = this;
        TreeRoot.tree       = this;
        detectTask.tree     = this;
        zapTask.tree        = this;
        damageBoidTask.tree = this;
        root = TreeRoot;
    }