Exemplo n.º 1
0
 protected override void Update()
 {
     steeringUpdate         = new SteeringOutput();
     steeringUpdate.linear  = myMoveType.getSteering().linear;
     steeringUpdate.angular = myRotateType.getSteering().angular;
     base.Update();
 }
Exemplo n.º 2
0
    // Update is called once per frame
    protected override void Update()
    {
        steeringUpdate = new SteeringOutput();
        if (seeking)
        {
            steeringUpdate.linear = moveTypeSeek.getSteering().linear;
        }
        else if (fleeing)
        {
            steeringUpdate.linear = moveTypeFlee.getSteering().linear;
        }
        else if (evading)
        {
            steeringUpdate.linear = moveTypeEvade.getSteering().linear;
        }
        else
        {
            steeringUpdate.linear = moveTypeAvoid.getSteering().linear;
        }

        steeringUpdate.angular = facing ?
                                 rotateTypeFace.getSteering().angular :
                                 rotateTypeLWYG.getSteering().angular;
        base.Update();
    }
Exemplo n.º 3
0
    // Update is called once per frame
    protected override void Update()
    {
        if (obstacle)
        {
            steeringUpdate = avoidTypeObs.getSteering();
        }
        else
        {
            steeringUpdate = avoidTypeCol.getSteering();
        }

        base.Update();
    }
Exemplo n.º 4
0
 protected override void Update()
 {
     steeringUpdate = myMoveType.getSteering();
     base.Update();
 }
Exemplo n.º 5
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;
        }
    }
    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   = path;
            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)
            {
                linear  += pursuing.linear * Time.deltaTime;
                angular += pursuing.angular * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Separate:
            Separate       separate       = new Separate();
            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)
            {
                linear  += obAvoiding.linear * Time.deltaTime;
                angular += obAvoiding.angular * Time.deltaTime;
            }
            break;
        }
    }
 void Update()
 {
     //Perseguimos al enemigo
     // con seek aceleracion
     steeringAgent.UpdateSteering(obstacleAvoidance.getSteering());
 }