void InitializePriorityThree()
 {
     flockGroups[2]                       = new BlendedSteering();
     flockGroups[2].behaviors             = new BehaviorAndWeight[1];
     flockGroups[2].behaviors[0]          = new BehaviorAndWeight();
     flockGroups[2].behaviors[0].behavior = look;
     flockGroups[2].behaviors[0].weight   = 4f;
 }
 void InitializePriorityTwo()
 {
     flockGroups[1]                       = new BlendedSteering();
     flockGroups[1].behaviors             = new BehaviorAndWeight[1];
     flockGroups[1].behaviors[0]          = new BehaviorAndWeight();
     flockGroups[1].behaviors[0].behavior = arrive;
     flockGroups[1].behaviors[0].weight   = 1f;
 }
Exemplo n.º 3
0
    void Start()
    {
        Separation separate = new Separation();

        separate.character = this;
        GameObject[] goBirds = GameObject.FindGameObjectsWithTag("bird");
        kBirds = new Kinematic[goBirds.Length - 1];
        int j = 0;

        for (int i = 0; i < goBirds.Length - 1; i++)
        {
            if (goBirds[i] == this)
            {
                continue;
            }
            kBirds[j++] = goBirds[i].GetComponent <Kinematic>();
        }
        separate.targets = kBirds;
        Arrive cohere = new Arrive();

        cohere.character = this;
        cohere.target    = myCohereTarget;
        LookWhereGoing myRotateType = new LookWhereGoing();

        myRotateType.character = this;

        mySteering                       = new BlendedSteering();
        mySteering.behaviors             = new BehaviorAndWeight[3];
        mySteering.behaviors[0]          = new BehaviorAndWeight();
        mySteering.behaviors[0].behavior = separate;
        mySteering.behaviors[0].weight   = 1f;
        mySteering.behaviors[1]          = new BehaviorAndWeight();
        mySteering.behaviors[1].behavior = cohere;
        mySteering.behaviors[1].weight   = 1f;
        mySteering.behaviors[2]          = new BehaviorAndWeight();
        mySteering.behaviors[2].behavior = myRotateType;
        mySteering.behaviors[2].weight   = 1f;

        ObstacleAvoidance myAvoid = new ObstacleAvoidance();

        myAvoid.character = this;
        myAvoid.target    = myCohereTarget;
        myAvoid.flee      = true;
        BlendedSteering myHighPrioritySteering = new BlendedSteering();

        myHighPrioritySteering.behaviors             = new BehaviorAndWeight[1];
        myHighPrioritySteering.behaviors[0]          = new BehaviorAndWeight();
        myHighPrioritySteering.behaviors[0].behavior = myAvoid;
        myHighPrioritySteering.behaviors[0].weight   = 1f;

        myAdvancedSteering           = new PrioritySteering();
        myAdvancedSteering.groups    = new BlendedSteering[2];
        myAdvancedSteering.groups[0] = new BlendedSteering();
        myAdvancedSteering.groups[0] = myHighPrioritySteering;
        myAdvancedSteering.groups[1] = new BlendedSteering();
        myAdvancedSteering.groups[1] = mySteering;
    }
Exemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        //DATOS DE PERSONAJE
        kineticsAgent = agent.kineticsAgent;
        steeringAgent = agent.steeringAgent;


        //ARRIVE INITIALIZATION

        enemy = new GameObject();//creamos un enemigo ficticio que sera el mouse
        enemy.transform.position = Vector3.zero;
        kineticsEnemy            = new Kinetics(0f, Vector3.zero, enemy.transform);

        arrive        = new Arrive(kineticsAgent, kineticsEnemy, maxAccelerationArrive, agent.maxspeed, targetRadiusArrive, slowRadiusArrive, timeTotargetArrive);
        arrive.weigth = 1f;

        //AVOID INITIALIZATION

        obstacles = GameObject.FindGameObjectsWithTag("Obstacle");

        for (int i = 0; i < obstacles.Length; i++)
        {
            obs_trans.Add(obstacles[i].transform);
        }

        Transform[] obstacles_transforms = obs_trans.ToArray();

        obstacleAvoidance        = new ObstacleAvoidance(kineticsAgent, obstacles_transforms, avoidDistance, lookAheadAvoid, steeringAgent);
        obstacleAvoidance.weigth = 1f;

        //FACE INITIALIZATION

        face        = new Face(kineticsAgent, kineticsEnemy);
        face.weigth = 1f;



        //BLEND INITIALIZATION

        behaviorsArrive[0] = arrive;
        behaviorsArrive[1] = face;

        behaviorsAvoid[0] = obstacleAvoidance;


        blendArrive = new BlendedSteering(behaviorsArrive, maxAccelBlend, maxAngularBlend);
        blendAvoid  = new BlendedSteering(behaviorsAvoid, maxAccelBlend, maxAngularBlend);

        //PRIORITY INITIALIZATION

        groups[0] = blendAvoid;//OJO avoid tiene prioridad por eso va primero
        groups[1] = blendArrive;

        priority = new PrioritySteering(groups, steeringAgent);
    }
    void InitializePriorityOne()
    {
        flockGroups[0]              = new BlendedSteering();
        flockGroups[0].behaviors    = new BehaviorAndWeight[2];
        flockGroups[0].behaviors[0] = new BehaviorAndWeight();
        flockGroups[0].behaviors[1] = new BehaviorAndWeight();

        flockGroups[0].behaviors[0].behavior = avoid;
        flockGroups[0].behaviors[0].weight   = 10000f;
        flockGroups[0].behaviors[1].behavior = seperate;
        flockGroups[0].behaviors[1].weight   = 1f;
    }
Exemplo n.º 6
0
    private void Awake()
    {
        steering = new BlendedSteering();

        //Create behaviors to go into the bird
        Arrive arriveAI = new Arrive();

        arriveAI.character = GetComponent <Kinematic>();
        arriveAI.target    = arriveTarget;

        Seperation seperateAI = new Seperation();

        seperateAI.character = GetComponent <Kinematic>();
        GameObject[] allBirds = GameObject.FindGameObjectsWithTag("bird");
        Kinematic[]  allOtherBirdKinematics = new Kinematic[allBirds.Length];
        int          j = 0;

        foreach (GameObject bird in allBirds)
        {
            if (bird != this)
            {
                allOtherBirdKinematics[j] = bird.GetComponent <Kinematic>();
                j++;
            }
            else
            {
                Debug.Log("caught myself");
            }
        }
        seperateAI.targets = allOtherBirdKinematics;

        LookWhereGoing lookAI = new LookWhereGoing();

        lookAI.character = GetComponent <Kinematic>();

        //Set up the blended steering array
        //We need three for Seperation, Arrive, and LookWhereGoing
        steering.behaviors    = new BehaviorAndWeight[3];
        steering.behaviors[0] = new BehaviorAndWeight();
        steering.behaviors[1] = new BehaviorAndWeight();
        steering.behaviors[2] = new BehaviorAndWeight();

        //Assign the specific behaviors
        steering.behaviors[0].behavior = arriveAI;
        steering.behaviors[1].behavior = seperateAI;
        steering.behaviors[2].behavior = lookAI;

        //Now set the weight of each behavior
        steering.behaviors[0].weight = 1f;
        steering.behaviors[1].weight = 20f;
        steering.behaviors[2].weight = 4f;
    }
Exemplo n.º 7
0
    void Start()
    {
        // Separate from other birds
        Separation separate = new Separation();

        separate.character = this;
        GameObject[] goBirds = GameObject.FindGameObjectsWithTag("bird");
        kBirds = new GameObject[goBirds.Length - 1];
        int j = 0;

        for (int i = 0; i < goBirds.Length - 1; i++)
        {
            if (goBirds[i] == this)
            {
                continue;
            }
            kBirds[j++] = goBirds[i];
        }
        separate.targets = kBirds;

        // Cohere to center of mass - ez mode
        Seek cohere = new Seek();

        cohere.character = this;
        cohere.target    = myCohereTarget;

        Pursue pursue = new Pursue();

        pursue.character = this;
        pursue.target    = myTarget;

        // look where center of mass is going - ez mode
        LookWhereGoing myRotateType = new LookWhereGoing();

        myRotateType.character = this;

        mySteering                       = new BlendedSteering();
        mySteering.behaviors             = new BehaviorAndWeight[4];
        mySteering.behaviors[0]          = new BehaviorAndWeight();
        mySteering.behaviors[0].behavior = separate;
        mySteering.behaviors[0].weight   = .2f;
        mySteering.behaviors[1]          = new BehaviorAndWeight();
        mySteering.behaviors[1].behavior = cohere;
        mySteering.behaviors[1].weight   = .3f;
        mySteering.behaviors[2]          = new BehaviorAndWeight();
        mySteering.behaviors[2].behavior = pursue;
        mySteering.behaviors[2].weight   = .5f;
        mySteering.behaviors[3]          = new BehaviorAndWeight();
        mySteering.behaviors[3].behavior = myRotateType;
        mySteering.behaviors[3].weight   = 1f;
    }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (inputHandler.reload)
        {
            destroySteerings();

            gameObject.AddComponent <BlendedSteering>();
            blendedSteering = gameObject.GetComponent <BlendedSteering>();

            gameObject.GetComponent <AgentNPC>().ReloadSteerings();

            updateSteering();
            inputHandler.reload = false;
        }
    }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="owner">The character owner of this behavior</param>
        public GroupWander(Character owner)
        {
            // Initialize the blending
            blending = new BlendedSteering();

            // Add behaviors
            BehaviorAndWeight a = new BehaviorAndWeight(new LookWhereYoureGoing(), 1);
            BehaviorAndWeight b = new BehaviorAndWeight(new Wander(), 1);
            BehaviorAndWeight c = new BehaviorAndWeight(new ObstacleAvoidance(), 2);
            BehaviorAndWeight d = new BehaviorAndWeight(new Separation(owner), 1.5f);
            BehaviorAndWeight e = new BehaviorAndWeight(new FriendsAvoidance(owner), 1.5f);

            blending.behaviors.Add(a);
            blending.behaviors.Add(b);
            blending.behaviors.Add(c);
            blending.behaviors.Add(d);
            blending.behaviors.Add(e);
        }
Exemplo n.º 10
0
    void MainSteeringBehaviors()
    {
        ResetOrientation();

        switch (choiceOfBehavior)
        {
        case SteeringBehaviors.Seek:
            Seek seek = new Seek();
            seek.character = this;
            seek.target    = newTarget;
            SteeringOutput seeking = seek.getSteering();
            if (seeking != null)
            {
                linear  += seeking.linear * Time.deltaTime;
                angular += seeking.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Flee:
            Flee flee = new Flee();
            flee.character = this;
            flee.target    = newTarget;
            SteeringOutput fleeing = flee.getSteering();
            if (fleeing != null)
            {
                linear  += fleeing.linear * Time.deltaTime;
                angular += fleeing.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Align:
            Align align = new Align();
            align.character = this;
            align.target    = newTarget;
            SteeringOutput aligning = align.getSteering();
            if (aligning != null)
            {
                linear  += aligning.linear * Time.deltaTime;
                angular += aligning.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Face:
            Face face = new Face();
            face.character = this;
            face.target    = newTarget;
            SteeringOutput facing = face.getSteering();
            if (facing != null)
            {
                linear  += facing.linear * Time.deltaTime;
                angular += facing.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.LookWhereGoing:
            LookWhereGoing look = new LookWhereGoing();
            look.character = this;
            look.target    = newTarget;
            SteeringOutput looking = look.getSteering();
            if (looking != null)
            {
                linear  += looking.linear * Time.deltaTime;
                angular += looking.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Arrive:
            Arrive arrive = new Arrive();
            arrive.character = this;
            arrive.target    = newTarget;
            SteeringOutput arriving = arrive.getSteering();
            if (arriving != null)
            {
                linear  += arriving.linear * Time.deltaTime;
                angular += arriving.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.PathFollow:

            follow.character = this;
            lookwg.character = this;

            follow.path   = myPath;
            lookwg.target = newTarget;

            SteeringOutput following = follow.getSteering();
            SteeringOutput lookingwg = lookwg.getSteering();

            if (following != null)
            {
                linear += following.linear * Time.deltaTime;
                // angular += lookingwg.angular* Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Pursue:
            Pursue         pursue = new Pursue();
            LookWhereGoing PursuelookWhereGoing = new LookWhereGoing();
            pursue.character = this;
            PursuelookWhereGoing.character = this;
            pursue.target = newTarget;
            PursuelookWhereGoing.target = newTarget;
            SteeringOutput pursuing = pursue.getSteering();
            SteeringOutput pursuelookingWhereGoing = PursuelookWhereGoing.getSteering();

            if (pursuing != null)
            {
                if (pursuing.linear.magnitude <= maxSpeed)
                {
                    linear += pursuing.linear * Time.deltaTime;
                }
                angular += pursuing.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Separate:
            Separation     separate       = new Separation();
            LookWhereGoing lookWhereGoing = new LookWhereGoing();
            separate.character       = this;
            lookWhereGoing.character = this;
            separate.targets         = targets;
            lookWhereGoing.target    = newTarget;
            SteeringOutput lookingWhereGoing = lookWhereGoing.getSteering();
            SteeringOutput separating        = separate.getSteering();
            if (separating != null)
            {
                linear  += separating.linear * Time.deltaTime;
                angular += separating.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.CollisionAvoidance:
            CollisionAvoidance avoid = new CollisionAvoidance();
            LookWhereGoing     AvoidlookWhereGoing = new LookWhereGoing();
            avoid.character = this;
            AvoidlookWhereGoing.character = this;
            avoid.targets = targets;
            AvoidlookWhereGoing.target = newTarget;
            SteeringOutput AvoidlookingWhereGoing = AvoidlookWhereGoing.getSteering();
            SteeringOutput avoiding = avoid.getSteering();
            if (avoiding != null)
            {
                linear  += avoiding.linear * Time.deltaTime;
                angular += avoiding.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.ObstacleAvoidance:
            ObstacleAvoidance obAvoid = new ObstacleAvoidance();
            LookWhereGoing    obAvoidlookWhereGoing = new LookWhereGoing();
            obAvoid.character = this;
            obAvoidlookWhereGoing.character = this;
            obAvoid.target = newTarget;
            obAvoidlookWhereGoing.target = newTarget;
            SteeringOutput obAvoiding = obAvoid.getSteering();
            SteeringOutput obAvoidlookingWhereGoing = obAvoidlookWhereGoing.getSteering();
            if (obAvoiding != null)
            {
                if (obAvoiding.linear.magnitude <= maxSpeed)
                {
                    linear += obAvoiding.linear * Time.deltaTime;
                }
                angular += obAvoiding.angular * Time.deltaTime;
            }
            break;

        case SteeringBehaviors.Flocking:
            Separation      sepFlock    = new Separation();
            Arrive          arriveFlock = new Arrive();
            LookWhereGoing  lwgFlock    = new LookWhereGoing();
            BlendedSteering mySteering  = new BlendedSteering();
            Kinematic[]     kBirds;
            sepFlock.character = this;
            GameObject[] goBirds = GameObject.FindGameObjectsWithTag("Pengu");
            kBirds = new Kinematic[goBirds.Length - 1];
            int j = 0;
            for (int i = 0; i < goBirds.Length - 1; i++)
            {
                if (goBirds[i] == this)
                {
                    continue;
                }
                goBirds[i].GetComponent <Animator>().SetInteger("Walk", 1);
                kBirds[j++] = goBirds[i].GetComponent <Kinematic>();
            }
            sepFlock.targets = kBirds;

            arriveFlock.character = this;
            //Debug.Log(arriveFlock.character);
            arriveFlock.target = newTarget;
            //Debug.Log(arriveFlock.target);
            lwgFlock.character               = this;
            lwgFlock.target                  = newTarget;
            mySteering.behaviors             = new BehaviorAndWeight[3];
            mySteering.behaviors[0]          = new BehaviorAndWeight();
            mySteering.behaviors[0].behavior = sepFlock;
            mySteering.behaviors[0].weight   = 1f;
            mySteering.behaviors[1]          = new BehaviorAndWeight();
            mySteering.behaviors[1].behavior = arriveFlock;
            mySteering.behaviors[1].weight   = 1f;
            mySteering.behaviors[2]          = new BehaviorAndWeight();
            mySteering.behaviors[2].behavior = lwgFlock;
            mySteering.behaviors[2].weight   = 1f;

            ObstacleAvoidance myAvoid = new ObstacleAvoidance();
            myAvoid.character = this;
            myAvoid.target    = newTarget;
            myAvoid.flee      = true;

            BlendedSteering myHighPrioritySteering = new BlendedSteering();
            myHighPrioritySteering.behaviors             = new BehaviorAndWeight[1];
            myHighPrioritySteering.behaviors[0]          = new BehaviorAndWeight();
            myHighPrioritySteering.behaviors[0].behavior = myAvoid;
            myHighPrioritySteering.behaviors[0].weight   = 0.1f;
            myAdvancedSteering.groups    = new BlendedSteering[2];
            myAdvancedSteering.groups[0] = new BlendedSteering();
            myAdvancedSteering.groups[0] = myHighPrioritySteering;
            myAdvancedSteering.groups[1] = new BlendedSteering();
            myAdvancedSteering.groups[1] = mySteering;

            //steeringUpdate = mySteering.getSteering();
            avoidObstacles = true;
            if (!avoidObstacles)
            {
                steeringUpdate = mySteering.getSteering();
                if (steeringUpdate != null)
                {
                    linear  += steeringUpdate.linear * Time.deltaTime;
                    angular += steeringUpdate.angular * Time.deltaTime;
                }
            }
            else
            {
                steeringUpdate = myAdvancedSteering.getSteering();
                if (steeringUpdate != null)
                {
                    linear  += steeringUpdate.linear * Time.deltaTime;
                    angular += steeringUpdate.angular * Time.deltaTime;
                }
            }
            break;

        case SteeringBehaviors.PathFinder:
            SteeringOutput lwyger = myRotateType.getSteering();
            linear  += myMoveType.getSteering().linear *Time.deltaTime;
            angular += myMoveType.getSteering().angular *Time.deltaTime;
            break;
        }
    }
    private void Start()
    {
        //Separate
        Separation separation = new Separation();

        separation.character = this;
        GameObject[] goBirds = GameObject.FindGameObjectsWithTag("Bee");

        kBirds = new Kinematic[goBirds.Length - 1];

        int a = 0;

        for (int i = 0; i < goBirds.Length - 1; i++)
        {
            if (goBirds[i] == this)
            {
                continue;
            }
            kBirds[a++] = goBirds[i].GetComponent <Kinematic>();
        }
        separation.targets = kBirds;

        //Cohere
        Arrive cohere = new Arrive();

        cohere.character = this;
        cohere.target    = myCohereTarget;

        //Rotate
        LookWhereGoing myRotateType = new LookWhereGoing();

        myRotateType.character = this;

        blendedSteering                       = new BlendedSteering();
        blendedSteering.behaviors             = new WeightedBehavior[3];
        blendedSteering.behaviors[0]          = new WeightedBehavior();
        blendedSteering.behaviors[0].behavior = separation;
        blendedSteering.behaviors[0].weight   = 1f;
        blendedSteering.behaviors[1]          = new WeightedBehavior();
        blendedSteering.behaviors[1].behavior = cohere;
        blendedSteering.behaviors[1].weight   = 1f;
        blendedSteering.behaviors[2]          = new WeightedBehavior();
        blendedSteering.behaviors[2].behavior = myRotateType;
        blendedSteering.behaviors[2].weight   = 1f;

        //Priority Arbitration
        AvoidObstacle avoid = new AvoidObstacle();

        avoid.character = this;
        avoid.target    = myCohereTarget;
        avoid.flee      = false;
        BlendedSteering prioritySteering = new BlendedSteering();

        prioritySteering.behaviors             = new WeightedBehavior[1];
        prioritySteering.behaviors[0]          = new WeightedBehavior();
        prioritySteering.behaviors[0].behavior = avoid;
        prioritySteering.behaviors[0].weight   = 1f;

        advancedSteering             = new PrioritySteering();
        advancedSteering.myGroups    = new BlendedSteering[2];
        advancedSteering.myGroups[0] = new BlendedSteering();
        advancedSteering.myGroups[0] = prioritySteering;
        advancedSteering.myGroups[1] = new BlendedSteering();
        advancedSteering.myGroups[1] = blendedSteering;
    }
Exemplo n.º 12
0
    void Start()
    {
        ///Setup behaviours and BlendSteer for general flocking
        #region General Flocking

        ///Start Separation
        //Separate from others and not self
        Separation _separate = new Separation();
        _separate.character = this;
        GameObject[] _goBirds = GameObject.FindGameObjectsWithTag("birds");
        relevantBirds = new GameObject[_goBirds.Length - 1];


        int _relevantBirdCount = 0;
        for (int _bird = 0; _bird < _goBirds.Length - 1; _bird++)
        {
            if (_goBirds[_bird] == this)
            {
                //Ignore self for separation
                continue;
            }
            ///Else separate from them
            relevantBirds[_relevantBirdCount++] = _goBirds[_bird];
        }
        _separate.neighborhood = relevantBirds;
        ///End Separation

        ///Start Cohere
        Arrive _cohere = new Arrive();
        _cohere.character = this;
        _cohere.target    = flockCoMTarget;
        ///End Cohere

        ///Start LWYG
        LookWhereGoing _lWYG = new LookWhereGoing();
        _lWYG.character = this;
        ///End LWYG



        ///Start Blending for general flocking
        _generalFlockSteering            = new BlendedSteering();
        _generalFlockSteering.behaviours = new BehaviourAndWeight[3];

        //Separation
        _generalFlockSteering.behaviours[0]           = new BehaviourAndWeight();
        _generalFlockSteering.behaviours[0].behaviour = _separate;
        _generalFlockSteering.behaviours[0].weight    = 1f; //Weights are still not great, but functional

        //Cohere
        _generalFlockSteering.behaviours[1]           = new BehaviourAndWeight();
        _generalFlockSteering.behaviours[1].behaviour = _cohere;
        _generalFlockSteering.behaviours[1].weight    = .4f;

        //Look Where Going
        _generalFlockSteering.behaviours[2]           = new BehaviourAndWeight();
        _generalFlockSteering.behaviours[2].behaviour = _lWYG;
        _generalFlockSteering.behaviours[2].weight    = 20f;
        ///End Blending

        #endregion General Flocking



        #region Obst Avoid
        ///Start ObstAvoid
        ObstAvoid _obstAvoid = new ObstAvoid();
        _obstAvoid.character     = this;
        _obstAvoid.lookAheadDist = 5f;
        //_obstAvoid.target = flockCoMTarget;

        ///End ObstAvoid

        ///Start Blending for obstacle avoidance
        _obstAvoidSteering            = new BlendedSteering();
        _obstAvoidSteering.behaviours = new BehaviourAndWeight[1];

        //ObstAvoid
        _obstAvoidSteering.behaviours[0]           = new BehaviourAndWeight();
        _obstAvoidSteering.behaviours[0].behaviour = _obstAvoid;
        _obstAvoidSteering.behaviours[0].weight    = 1f; //Priority handles this
        ///End Blending

        #endregion Obst Avoid



        #region Priority Blending
        ///Start Prioritization
        _prioritySteering        = new PrioritySteering();
        _prioritySteering.blends = new BlendedSteering[2];

        //General Flocking
        _prioritySteering.blends[0] = new BlendedSteering();
        _prioritySteering.blends[0] = _obstAvoidSteering;

        //Obst Avoid
        _prioritySteering.blends[1] = new BlendedSteering();
        _prioritySteering.blends[1] = _generalFlockSteering;
        ///End Prioritization

        #endregion Priority Blending
    }
Exemplo n.º 13
0
    // Failed attempt to add observer pattern to allow for adding
    // or deleting boids
    //private void OnEnable()
    //{
    //    DestroyerAngel.OnKillBoid += killBoids;
    //    //PriorityGame.OnAddBoid += addBoids;
    //}

    //private void OnDisable()
    //{
    //    DestroyerAngel.OnKillBoid -= killBoids;
    //    //PriorityGame.OnAddBoid -= addBoids;
    //}

    // Start is called before the first frame update
    protected override void Start()
    {
        // personal space for the boidies
        separate           = new Separation();
        separate.character = this;
        GameObject[] goBoids = GameObject.FindGameObjectsWithTag("boid");
        kBoids = new Kinematic[goBoids.Length - 1];
        int j = 0;

        for (int i = 0; i < goBoids.Length - 1; i++)
        {
            if (goBoids[i] == this)
            {
                continue;
            }
            kBoids[j++] = goBoids[i].GetComponent <Kinematic>();
        }
        separate.targets = kBoids;

        // cohere to center of mass
        Arrive cohere = new Arrive();

        cohere.character = this;
        cohere.target    = cohereTarget;

        // and look where center of mass is going
        Face rotateType = new Face();

        rotateType.character = this;
        rotateType.target    = cohereTarget;

        // m_Steering = new BlendedSteering();
        m_Steering                       = gameObject.AddComponent <BlendedSteering>();
        m_Steering.behaviors             = new BehaviorAndWeight[3];
        m_Steering.behaviors[0]          = new BehaviorAndWeight();
        m_Steering.behaviors[0].behavior = separate;
        m_Steering.behaviors[0].weight   = 1f;
        m_Steering.behaviors[1]          = new BehaviorAndWeight();
        m_Steering.behaviors[1].behavior = cohere;
        m_Steering.behaviors[1].weight   = 1f;
        m_Steering.behaviors[2]          = new BehaviorAndWeight();
        m_Steering.behaviors[2].behavior = rotateType;
        m_Steering.behaviors[2].weight   = 1f;

        // add prioritysteering
        ObstacleAvoidance avoid = new ObstacleAvoidance();

        avoid.character     = this;
        avoid.target        = avoidThis;
        avoid.lookAhead     = 200f;
        avoid.avoidDistance = 100f;
        avoid.flee          = true;

        // blend the priority steering with the original blended steering
        BlendedSteering highPriority = gameObject.AddComponent <BlendedSteering>();

        highPriority.behaviors             = new BehaviorAndWeight[1];
        highPriority.behaviors[0]          = new BehaviorAndWeight();
        highPriority.behaviors[0].behavior = avoid;
        highPriority.behaviors[0].weight   = 100f;

        prioritySteering           = gameObject.AddComponent <PrioritySteering>();
        prioritySteering.groups    = new BlendedSteering[2];
        prioritySteering.groups[0] = gameObject.AddComponent <BlendedSteering>();
        prioritySteering.groups[0] = highPriority;
        prioritySteering.groups[1] = gameObject.AddComponent <BlendedSteering>();
        prioritySteering.groups[1] = m_Steering;
    }
Exemplo n.º 14
0
    void Start()
    {
        // Separate from other birds
        Separation separate = new Separation();

        separate.character = this;
        GameObject[] goBirds = GameObject.FindGameObjectsWithTag("bird");
        kBirds = new Kinematic[goBirds.Length - 1];
        int j = 0;

        for (int i = 0; i < goBirds.Length - 1; i++)
        {
            if (goBirds[i] == this)
            {
                continue;
            }
            kBirds[j++] = goBirds[i].GetComponent <Kinematic>();
        }
        separate.targets = kBirds;

        // Cohere to center of mass - ez mode
        Arrive cohere = new Arrive();

        cohere.character = this;
        cohere.target    = myCohereTarget;

        // look where center of mass is going - ez mode
        LookWhereGoing myRotateType = new LookWhereGoing();

        myRotateType.character = this;

        mySteering                       = new BlendedSteering();
        mySteering.behaviors             = new BehaviorAndWeight[3];
        mySteering.behaviors[0]          = new BehaviorAndWeight();
        mySteering.behaviors[0].behavior = separate;
        mySteering.behaviors[0].weight   = 1f; //3
        mySteering.behaviors[1]          = new BehaviorAndWeight();
        mySteering.behaviors[1].behavior = cohere;
        mySteering.behaviors[1].weight   = 1f; //.5
        mySteering.behaviors[2]          = new BehaviorAndWeight();
        mySteering.behaviors[2].behavior = myRotateType;
        mySteering.behaviors[2].weight   = 1f;

        // set up prioritysteering
        ObstacleAvoidance myAvoid = new ObstacleAvoidance();

        myAvoid.character = this;
        myAvoid.target    = myCohereTarget;
        myAvoid.flee      = true; // otherwise I seek to the obstacle
        BlendedSteering myHighPrioritySteering = new BlendedSteering();

        myHighPrioritySteering.behaviors             = new BehaviorAndWeight[1];
        myHighPrioritySteering.behaviors[0]          = new BehaviorAndWeight();
        myHighPrioritySteering.behaviors[0].behavior = myAvoid;
        myHighPrioritySteering.behaviors[0].weight   = 1f;

        myAdvancedSteering           = new PrioritySteering();
        myAdvancedSteering.groups    = new BlendedSteering[2];
        myAdvancedSteering.groups[0] = new BlendedSteering();
        myAdvancedSteering.groups[0] = myHighPrioritySteering;
        myAdvancedSteering.groups[1] = new BlendedSteering();
        myAdvancedSteering.groups[1] = mySteering;
    }
Exemplo n.º 15
0
    // Start is called before the first frame update
    void Start()
    {
        //DATOS DE PERSONAJE
        kineticsAgent = agent.kineticsAgent;
        steeringAgent = agent.steeringAgent;


        //SEPARATION INITIALIZATION

        //buscamos a todos los pokemones
        GameObject[] allPokemons = GameObject.FindGameObjectsWithTag("Pokemon");
        //vamos a usar solo los pokemones que participan en flock
        GameObject[] pokemons = Array.FindAll(allPokemons, c => c.GetComponent <static_data>().flocker);

        //Inicializamos las estructuras necesarias de otros componentes
        for (int i = 0; i < pokemons.Length; i++)
        {
            if (pokemons[i].name != name) //solo me interesan los pokemones que no son yo
            {
                targets_kin_sepa.Add(pokemons[i].GetComponent <static_data>().kineticsAgent);
            }
        }

        Kinetics[] targets_sep = targets_kin_sepa.ToArray();
        separation = new Separation(kineticsAgent, targets_sep, threshold, maxAccelSep);

        separation.weigth = 3f;


        //VELOCITY MATCH INITIALIZATION

        enemyVel         = GameObject.Find(enemyNameVel).GetComponent <static_data>();
        kineticsEnemyVel = enemyVel.kineticsAgent;

        velMatch = new VelocityMatch(kineticsAgent, kineticsEnemyVel, MaxAccelVel, timeTotargetVel);

        velMatch.weigth = 1f;


        //COHESION INITIALIZATION


        //Inicializamos las estructuras necesarias de otros componentes
        for (int i = 0; i < pokemons.Length; i++)
        {
            targets_trans_cohe.Add(pokemons[i].transform);
        }

        Transform[] targets_cohe = targets_trans_cohe.ToArray();

        maxSpeedCohe = agent.maxspeed;
        cohesion     = new Cohesion(kineticsAgent, targets_cohe, maxAccelCohe, maxSpeedCohe, targetRadiusCohe, slowRadiusCohe, timeToTargetCohe);

        cohesion.weigth = 1.5f;


        //BLEND INITIALIZATION
        //mezclamos nuestros comportamientos para crear fllock
        behaviors[0] = separation;
        behaviors[1] = velMatch;
        behaviors[2] = cohesion;

        blendFlock = new BlendedSteering(behaviors, maxAccelBlend, maxAngularBlend);
    }