Example #1
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        Vector2 direction = Target.getPosition() - Character.getPosition();
        float   distance  = direction.sqrMagnitude;

        float speed = Character.getVelocity().sqrMagnitude;

        float prediction;

        if (speed <= distance / maxPrediction)
        {
            prediction = maxPrediction;
        }
        else
        {
            prediction = distance / maxPrediction;
        }

        AgentMeta dummy = new AgentMeta(new Vector2(0.0f, 0.0f) + Target.getVelocity() * prediction);

        Behaviour seek = new Seek(dummy, Character);

        SteeringOutput.SteeringOutput steering = seek.getSteering();

        return(steering);
    }
Example #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();
    }
Example #3
0
 // Update is called once per frame
 protected override void Update()
 {
     steeringUpdate         = new SteeringOutput();
     steeringUpdate.linear  = myMoveType.getSteering().linear;
     steeringUpdate.angular = myRotateType.getSteering().angular;
     base.Update();
 }
Example #4
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        Vector2 direction = Target.position - Character.position;
        float   distance  = direction.magnitude;

        float speed = Character.velocity.magnitude;

        float prediction;

        if (speed <= distance / maxPrediction)
        {
            prediction = maxPrediction;
        }
        else
        {
            prediction = distance / maxPrediction;
        }

        AgentMeta dummyAgent = new AgentMeta();

        dummyAgent.position = Target.position + Target.velocity * prediction;
        Behaviour seek = new Seek(dummyAgent, Character);

        SteeringOutput.SteeringOutput steering = seek.getSteering();

        /* Limpiar y devolver resultados */
        MonoBehaviour.Destroy(dummyAgent);
        return(steering);
    }
Example #5
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        Vector2 direction = Target.getPosition() - Character.getPosition();
        float   distance  = direction.magnitude;

        float speed = Character.getVelocity().magnitude;

        float prediction;

        if (speed <= distance / maxPrediction)
        {
            prediction = maxPrediction;
        }
        else
        {
            prediction = distance / maxPrediction;
        }

        GameObject dummy      = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  dummyAgent = dummy.GetComponent <AgentMeta> ();

        dummyAgent.setPosition(Target.getPosition() + Target.getVelocity() * prediction);

        Behaviour seek = new Seek(dummyAgent, Character);

        SteeringOutput.SteeringOutput steering = seek.getSteering();

        MonoBehaviour.Destroy(dummy);
        return(steering);
    }
    // Update is called once per frame
    void Update()
    {
        // update my position and rotation
        this.transform.position += linearVelocity * Time.deltaTime;
        Vector3 v = new Vector3(0, angularVelocity, 0);

        this.transform.eulerAngles += v * Time.deltaTime;

        // update linear and angular velocities
        SteeringOutput steering = new SteeringOutput();

        if (behaviorType == "Seek" || behaviorType == "seek")
        {
            Seek mySeek = new Seek();
            mySeek.character = this;
            mySeek.target    = myTarget;
            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        else if (behaviorType == "Flee" || behaviorType == "flee")
        {
            Flee myFlee = new Flee();
            myFlee.character = this;
            myFlee.target    = myTarget;
            steering         = myFlee.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        else if (behaviorType == "Arrive" || behaviorType == "arrive")
        {
            Arrive myArrive = new Arrive();
            myArrive.character = this;
            myArrive.target    = myTarget;
            steering           = myArrive.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }



        //Align myAlign = new Align();
        //myAlign.character = this;
        //myAlign.target = myTarget;
        //steering = myAlign.getSteering();
        //if (steering != null)
        //{
        //    linearVelocity += steering.linear * Time.deltaTime;
        //    angularVelocity += steering.angular * Time.deltaTime;
        //}
    }
    public override SteeringOutput.SteeringOutput getSteering()
    {
        Behaviour seek = new Seek(Target, Character);

        Behaviour lwyg = new LWYG(Character);

        SteeringOutput.SteeringOutput steering = lwyg.getSteering() + seek.getSteering();

        return(steering);
    }
Example #8
0
    //Functions to create different Steering Behaviours
    public void createSeek(bool toFleeOrNotToFlee, SteeringOutput steering)
    {
        Seek mySeek = new Seek
        {
            character = this,
            target    = myTarget
        };

        mySeek.flee      = toFleeOrNotToFlee;
        steering         = mySeek.getSteering();
        linearVelocity  += steering.linear * Time.deltaTime;
        angularVelocity += steering.angular * Time.deltaTime;
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        //update position and rotation
        transform.position    += linearVelocity * Time.deltaTime;
        transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0);

        //update linear and angular velocities
        Seek mySeek = new Seek();

        mySeek.character = this;
        mySeek.target    = target;
        SteeringOutput steering = mySeek.getSteering();

        linearVelocity  += steering.linear * Time.deltaTime;
        angularVelocity += steering.angular * Time.deltaTime;
    }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        //update position and rotation
        transform.position    += linearVelocity * Time.deltaTime;
        transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0);
        Seek mySeek = new Seek();

        mySeek.character = this;
        mySeek.target    = target;
        steering         = mySeek.getSteering();
        if (steering != null)
        {
            linearVelocity += steering.linear * Time.deltaTime;
        }
        RotAI(mode);

        //update linear and angular velocities
    }
Example #11
0
    void MainSteeringBehaviors()
    {
        ResetOrientation();

        switch (choiceOfBehavior)
        {
        case steeringBehaviors.Seek:
            Seek seek = new Seek();
            seek.selectedBoi = this;
            seek.myBoi       = myBoi;
            SteeringOutput seeking = seek.getSteering();
            if (seeking != null)
            {
                linearVelocity  += seeking.linearVelocity * Time.deltaTime;
                angularVelocity += seeking.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Flee:
            Flee flee = new Flee();
            flee.selectedBoi = this;
            flee.myBoi       = myBoi;
            SteeringOutput fleeing = flee.getSteering();
            if (fleeing != null)
            {
                linearVelocity  += fleeing.linearVelocity * Time.deltaTime;
                angularVelocity += fleeing.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Arrive:
            Arrive arrive = new Arrive();
            arrive.selectedBoi = this;
            arrive.myBoi       = myBoi;
            SteeringOutput arriving = arrive.getSteering();
            if (arriving != null)
            {
                linearVelocity  += arriving.linearVelocity * Time.deltaTime;
                angularVelocity += arriving.angularVelocity * Time.deltaTime;
            }
            break;
        }
    }
	public override SteeringOutput.SteeringOutput getSteering() {

		Vector2 futurePos = Character.getPosition () + Character.getVelocity () * predictTime;

		currentParam = path.getParam (futurePos, currentParam);

		float targetParam = currentParam + PathOffset;

		GameObject dummy = (GameObject) MonoBehaviour.Instantiate (Resources.Load ("Prefab/Dummy"));
		AgentMeta dummyAgent = dummy.GetComponent<AgentMeta> ();
		dummyAgent.setPosition (path.getPosition (targetParam));

		Behaviour seek = new Seek (dummyAgent, Character);
		SteeringOutput.SteeringOutput steering = seek.getSteering ();

		MonoBehaviour.Destroy (dummy);
		return steering; 

	}
    //en este caso la accion es actualizar la acelaracion del usuario
    public override void DoAction()
    {
        //HUIMOS DEL TARGET QUE ESTE MAS CERCA
        float    min           = float.PositiveInfinity;
        Vector3  agentPosition = kineticsAgent.transform.position;
        Kinetics currentKin;
        float    currentDistance;

        for (int i = 0; i < kineticsTargets.Length; i++)
        {
            currentKin      = kineticsTargets[i];
            currentDistance = Vector3.Distance(agentPosition, currentKin.transform.position);
            if (currentDistance < min)
            {
                min         = currentDistance;
                seek.target = currentKin;
            }
        }

        //actualizamos aceleracion
        steeringAgent.UpdateSteering(seek.getSteering(0));
    }
    // Update is called once per frame
    void Update()
    {
        // update my position and rotation
        this.transform.position += linearVelocity * Time.deltaTime;
        Vector3 v = new Vector3(0, angularVelocity, 0);

        this.transform.eulerAngles += v * Time.deltaTime;

        // update linear and angular velocities
        SteeringOutput steering = new SteeringOutput();

        // Seek: target is "alsoMyTargetForPursueTho"
        if (behaviorType == "Seek" || behaviorType == "seek")
        {
            Seek mySeek = new Seek();

            mySeek.target    = alsoMyTargetForPursueTho;
            mySeek.character = this;

            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        // Flee
        else if (behaviorType == "Flee" || behaviorType == "flee")
        {
            Flee myFlee = new Flee();
            myFlee.character = this;
            myFlee.target    = myTarget;
            steering         = myFlee.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        // Arrive
        else if (behaviorType == "Arrive" || behaviorType == "arrive")
        {
            Arrive myArrive = new Arrive();
            myArrive.character = this;
            myArrive.target    = myTarget;
            steering           = myArrive.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }
        // Align
        else if (behaviorType == "Align" || behaviorType == "align")
        {
            Align myAlign = new Align();
            myAlign.character = this;
            myAlign.target    = myTarget;
            steering          = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Face
        else if (behaviorType == "Face" || behaviorType == "face")
        {
            Face myFace = new Face();
            myFace.character = this;
            myFace.target    = myTarget;
            steering         = myFace.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Look where you're going
        else if (behaviorType == "LWYG" || behaviorType == "lwyg" || behaviorType == "Lwyg")
        {
            LWYG myLook = new LWYG();
            myLook.character = this;
            steering         = myLook.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Path following
        else if (behaviorType == "pathFollow" || behaviorType == "PathFollow")
        {
            myPathFollow.character = this;
            myPathFollow.path      = pathToFollow;
            steering = myPathFollow.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Pursue
        else if (behaviorType == "Pursue" || behaviorType == "pursue")
        {
            Pursue myPursue = new Pursue();
            myPursue.character = this;
            myPursue.target    = alsoMyTargetForPursueTho;
            steering           = myPursue.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Seperate
        else if (behaviorType == "Seperate" || behaviorType == "seperate")
        {
            mySeperate.character = this;
            mySeperate.targets   = targetsForSeperate;
            steering             = mySeperate.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
    }
Example #15
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;
        }
    }
    // Update is called once per frame
    void Update()
    {
        //update position and rotation
        transform.position    += linearVelocity * Time.deltaTime;
        transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0);

        //update linear and angular velocities
        switch (mode)
        {
        case 0:
            Seek mySeek = new Seek();
            mySeek.character = this;
            mySeek.target    = target;
            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
            Debug.Log("Seek");
            break;

        case 1:
            Flee myFlee = new Flee();
            myFlee.character = this;
            myFlee.target    = target;
            steering         = myFlee.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
            Debug.Log("Flee");
            break;

        case 2:
            Arrive myArrive = new Arrive();
            myArrive.character = this;
            myArrive.target    = target;
            steering           = myArrive.getSteering();
            linearVelocity    += steering.linear * Time.deltaTime;
            angularVelocity   += steering.angular * Time.deltaTime;
            Debug.Log("Arrive");
            break;

        case 3:
            Align myAlign = new Align();
            myAlign.character = this;
            myAlign.target    = target;
            steering          = myAlign.getSteering();
            linearVelocity   += steering.linear * Time.deltaTime;
            angularVelocity  += steering.angular * Time.deltaTime;
            Debug.Log("Align");
            break;

        case 4:
            Face myFace = new Face();
            myFace.character = this;
            myFace.target    = target;
            steering         = myFace.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
            Debug.Log("Face");
            break;

        case 5:
            LookWhereYoureGoing myLook = new LookWhereYoureGoing();
            myLook.character = this;
            myLook.target    = target;
            steering         = myLook.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
            Debug.Log("Look");
            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (behaviorNum != 0)
        {
            // update my position and rotation
            this.transform.position += linearVelocity * Time.deltaTime;
            Vector3 v = new Vector3(0, angularVelocity, 0);
            this.transform.eulerAngles += v * Time.deltaTime;
        }

        // update linear and angular velocities
        SteeringOutput steering = new SteeringOutput();

        // Seek: target is "alsoMyTargetForPursueTho"
        if (behaviorNum == 1)
        {
            Seek mySeek = new Seek();
            text.text = "Seek";

            mySeek.target    = alsoMyTargetForPursueTho;
            mySeek.character = this;

            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        // Flee
        else if (behaviorNum == 2)
        {
            Flee myFlee = new Flee();
            text.text = "Flee";

            myFlee.character = this;
            myFlee.target    = myTarget;
            steering         = myFlee.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        // Arrive
        else if (behaviorNum == 3)
        {
            Arrive myArrive = new Arrive();
            text.text = "Arrive";

            myArrive.character = this;
            myArrive.target    = myTarget;
            steering           = myArrive.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }
        // Align
        else if (behaviorNum == 4)
        {
            Align myAlign = new Align();
            text.text = "Align";

            myAlign.character = this;
            myAlign.target    = myTarget;
            steering          = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Face
        else if (behaviorNum == 5)
        {
            Face myFace = new Face();
            text.text = "Face";

            myFace.character = this;
            myFace.target    = myTarget;
            steering         = myFace.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Look where you're going
        else if (behaviorNum == 6)
        {
            LWYG myLook = new LWYG();
            text.text = "LWYG";

            myLook.character = this;
            steering         = myLook.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Path following
        else if (behaviorNum == 7)
        {
            text.text = "Path Follow";

            myPathFollow.character = this;
            myPathFollow.path      = pathToFollow;
            steering = myPathFollow.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Pursue
        else if (behaviorNum == 8)
        {
            Pursue myPursue = new Pursue();
            text.text = "Pursue";

            myPursue.character = this;
            myPursue.target    = alsoMyTargetForPursueTho;
            steering           = myPursue.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Seperate
        else if (behaviorNum == 9)
        {
            text.text = "Seperate";

            mySeperate.character = this;
            mySeperate.targets   = targetsForSeperate;
            steering             = mySeperate.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Collision Avoidance
        else if (behaviorNum == 10)
        {
            text.text = "Collision Avoidance";

            CollisionAvoidance myCollision = new CollisionAvoidance();
            myCollision.character = this;
            myCollision.targets   = targetsForSeperate;
            steering = myCollision.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Obstacle Avoidance
        else if (behaviorNum == 11)
        {
            text.text = "Obstacle Avoidance";

            ObstacleAvoid myObstacleAvoid = new ObstacleAvoid();
            myObstacleAvoid.character = this;
            myObstacleAvoid.target    = myTarget;
            steering = myObstacleAvoid.GetSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
    }
Example #18
0
    // Update is called once per frame
    void Update()
    {
        // update my position and rotation
        this.transform.position += linearVelocity * Time.deltaTime;
        Vector3 v = new Vector3(0, angularVelocity, 0); // TODO - don't make a new Vector3 every update you silly person

        this.transform.eulerAngles += v * Time.deltaTime;

        // update linear and angular velocities
        SteeringOutput steering = new SteeringOutput();

        if (behaviorType == "Seek" || behaviorType == "seek")
        {
            Seek mySeek = new Seek();
            mySeek.character = this;
            mySeek.target    = myTarget;
            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        else if (behaviorType == "Flee" || behaviorType == "flee")
        {
            Flee myFlee = new Flee();
            myFlee.character = this;
            myFlee.target    = myTarget;
            steering         = myFlee.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        else if (behaviorType == "Arrive" || behaviorType == "arrive")
        {
            Arrive myArrive = new Arrive();
            myArrive.character = this;
            myArrive.target    = myTarget;
            steering           = myArrive.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }
        else if (behaviorType == "Align" || behaviorType == "align")
        {
            Align myAlign = new Align();
            myAlign.character = this;
            myAlign.target    = myTarget;
            steering          = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        else if (behaviorType == "Face" || behaviorType == "face")
        {
            Face myFace = new Face();
            myFace.character = this;
            myFace.target    = myTarget;
            steering         = myFace.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        else if (behaviorType == "LWYG" || behaviorType == "lwyg" || behaviorType == "Lwyg")
        {
            LWYG myLook = new LWYG();
            myLook.character = this;
            steering         = myLook.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
    }
Example #19
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)
            {
                linearVelocity  += seeking.linearVelocity * Time.deltaTime;
                angularVelocity += seeking.angularVelocity * Time.deltaTime;
            }
            break;

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

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

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

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

        case steeringBehaviors.Arrive:
            Arrive arrive = new Arrive();
            arrive.character = this;
            arrive.target    = newTarget;
            SteeringOutput arriving = arrive.getSteering();
            if (arriving != null)
            {
                linearVelocity  += arriving.linearVelocity * Time.deltaTime;
                angularVelocity += arriving.angularVelocity * Time.deltaTime;
            }
            break;
        }
    }
Example #20
0
    void MainSteeringBehaviors()
    {
        ResetOrientation();

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

        case steeringBehaviors.Flee:
            Flee flee = new Flee();
            flee.character = this;
            flee.target    = target;
            SteeringOutput fleeing = flee.getSteering();
            if (fleeing != null)
            {
                linearVelocity  += fleeing.linearVelocity * Time.deltaTime;
                angularVelocity += fleeing.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Align:
            Align align = new Align();
            align.character = this;
            align.target    = target;
            SteeringOutput aligning = align.getSteering();
            if (aligning != null)
            {
                linearVelocity  += aligning.linearVelocity * Time.deltaTime;
                angularVelocity += aligning.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Face:
            Face face = new Face();
            face.character = this;
            face.target    = target;
            SteeringOutput facing = face.getSteering();
            if (facing != null)
            {
                linearVelocity  += facing.linearVelocity * Time.deltaTime;
                angularVelocity += facing.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.LookWhereGoing:
            LookWhereGoing look = new LookWhereGoing();
            look.character = this;
            look.target    = target;
            SteeringOutput looking = look.getSteering();
            if (looking != null)
            {
                linearVelocity  += looking.linearVelocity * Time.deltaTime;
                angularVelocity += looking.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Arrive:
            Arrive arrive = new Arrive();
            arrive.character = this;
            arrive.target    = target;
            SteeringOutput arriving = arrive.getSteering();
            if (arriving != null)
            {
                linearVelocity  += arriving.linearVelocity * Time.deltaTime;
                angularVelocity += arriving.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.SeekLWYG:
            LookWhereGoing lwyg  = new LookWhereGoing();
            Seek           seek1 = new Seek();
            seek1.character = this;
            seek1.target    = target;
            lwyg.character  = this;
            lwyg.target     = target;
            SteeringOutput seeker = seek1.getSteering();
            SteeringOutput lwyger = lwyg.getSteering();
            if (seeker != null && lwyger != null)
            {
                linearVelocity  += seeker.linearVelocity * Time.deltaTime;
                angularVelocity += lwyger.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.PathFollow:

            follow.character = this;
            face1.character  = this;

            follow.path  = pathArray;
            face1.target = target;


            SteeringOutput following = follow.getSteering();
            SteeringOutput facer1    = face1.getSteering();

            if (following != null)
            {
                linearVelocity += following.linearVelocity * Time.deltaTime;
                //angularVelocity += facer1.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Pursue:
            Pursue pursue = new Pursue();
            pursue.character = this;
            face1.character  = this;
            pursue.target    = target;
            face1.target     = target;
            //Debug.Log(target);
            SteeringOutput pursuing = pursue.getSteering();
            SteeringOutput facer2   = face1.getSteering();
            if (pursuing != null)
            {
                linearVelocity += pursuing.linearVelocity * Time.deltaTime;
                //angularVelocity += pursuing.angularVelocity * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Seperation:
            Seperation     seperation = new Seperation();
            LookWhereGoing face4      = new LookWhereGoing();
            seperation.character = this;
            face4.character      = this;

            seperation.targets = objectArray;
            face4.target       = target;
            Debug.Log(target);
            SteeringOutput seperationing = seperation.getSteering();
            SteeringOutput facer3        = face4.getSteering();
            //SteeringOutput facing2 = face2.getSteering();
            if (seperationing != null)
            {
                linearVelocity  += seperationing.linearVelocity * Time.deltaTime;
                angularVelocity += seperationing.angularVelocity * Time.deltaTime;
            }
            break;
        }
    }
Example #21
0
 //en este caso la accion es actualizar la acelaracion del usuario
 public override void DoAction()
 {
     steeringAgent.UpdateSteering(seek.getSteering(1));
 }
Example #22
0
    void StandardBehavior()
    {
        UpdatePositionRotation();

        switch (behavior)
        {
        case steeringBehaviors.Seek:
            Seek seek = new Seek();
            seek.character = this;
            seek.target    = target;
            SteeringOutput seekSteering = seek.getSteering();
            if (seekSteering != null)
            {
                linearVelocity  += seekSteering.linear * Time.deltaTime;
                angularVelocity += seekSteering.angular * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Flee:
            Flee flee = new Flee();
            flee.character = this;
            flee.target    = target;
            SteeringOutput fleeSteering = flee.getSteering();
            if (fleeSteering != null)
            {
                linearVelocity  += fleeSteering.linear * Time.deltaTime;
                angularVelocity += fleeSteering.angular * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Arrive:
            Arrive arrive = new Arrive();
            arrive.character = this;
            arrive.target    = target;
            SteeringOutput arriveSteering = arrive.getSteering();
            if (arriveSteering != null)
            {
                linearVelocity  += arriveSteering.linear * Time.deltaTime;
                angularVelocity += arriveSteering.angular * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Align:
            Align align = new Align();
            align.character = this;
            align.target    = target;
            SteeringOutput alignSteering = align.getSteering();
            if (alignSteering != null)
            {
                linearVelocity  += alignSteering.linear * Time.deltaTime;
                angularVelocity += alignSteering.angular * Time.deltaTime;
            }
            break;

        case steeringBehaviors.Face:
            Face face = new Face();
            face.character = this;
            face.target    = target;
            SteeringOutput faceSteering = face.getSteering();
            if (faceSteering != null)
            {
                linearVelocity  += faceSteering.linear * Time.deltaTime;
                angularVelocity += faceSteering.angular * Time.deltaTime;
            }
            break;

        case steeringBehaviors.LookWhereGoing:
            LookWhereGoing look = new LookWhereGoing();
            look.character = this;
            look.target    = target;
            SteeringOutput lookSteering = look.getSteering();
            if (lookSteering != null)
            {
                linearVelocity  += lookSteering.linear * Time.deltaTime;
                angularVelocity += lookSteering.angular * Time.deltaTime;
            }
            break;
        }
    }
Example #23
0
 void Update()
 {
     //Perseguimos al enemigo
     // con seek aceleracion
     steeringAgent.UpdateSteering(seek.getSteering(seek_or_flee));
 }
Example #24
0
    // Update is called once per frame
    protected virtual void Update()
    {
        //Update pos rot
        transform.position += linearVelocity * Time.deltaTime;
        Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0);

        if (float.IsNaN(angularIncrement.y))
        {
        }
        else
        {
            transform.eulerAngles += angularIncrement;
        }
        //Debug.Log(angularIncrement);

        SteeringOutput steering = new SteeringOutput();

        //Get Steerings
        if (bIsSeeking)
        {
            steering = mySeek.getSteering();
        }
        else
        {
            //steering = myFlee.getSteering();
        }
        if (bCanArrive)
        {
            SteeringOutput _arrvSteering = myArrv.getSteering();
            if (_arrvSteering != null)
            {
                linearVelocity  += _arrvSteering.linear * Time.deltaTime;
                angularVelocity += _arrvSteering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }
        if (bDoesAlign)
        {
            SteeringOutput _algnSteering = myAlgn.getSteering();
            if (_algnSteering != null)
            {
                steering.angular += _algnSteering.angular * Time.deltaTime;
            }
            else
            {
                angularVelocity = 0f;
            }
        }

        if (bDoesFace)
        {
            SteeringOutput _faceSteering = myFace.getSteering();
            if (_faceSteering != null)
            {
                angularVelocity += _faceSteering.angular * Time.deltaTime;
            }
        }
        if (bDoesLookWhereGoing)
        {
            SteeringOutput _lwygSteering = myLWYG.getSteering();
            if (_lwygSteering != null)
            {
                angularVelocity += _lwygSteering.angular * Time.deltaTime;
            }
        }
        if (bDoesFollowPath)
        {
            SteeringOutput _fpthSteering = myFPth.getSteering();
            if (_fpthSteering != null)
            {
                linearVelocity += _fpthSteering.linear * Time.deltaTime;
            }
        }
        if (bDoesSeparate)
        {
            SteeringOutput _seprSteering = mySepr.getSteering();
            if (_seprSteering != null)
            {
                linearVelocity += _seprSteering.linear * Time.deltaTime;
            }
        }
        if (bDoesPursue)
        {
            SteeringOutput _prsuSteering = myPrsu.getSteering();
            if (_prsuSteering != null)
            {
                linearVelocity += _prsuSteering.linear * Time.deltaTime;
            }
        }
        if (bDoesAvoidColl)
        {
            SteeringOutput _clAvSteering = myClAv.getSteering();
            if (_clAvSteering != null)
            {
                linearVelocity += _clAvSteering.linear * Time.deltaTime;
            }
        }
        if (bDoesObstAvoid)
        {
            SteeringOutput _obAvSteering = myObAv.getSteering();
            if (_obAvSteering != null)
            {
                linearVelocity += _obAvSteering.linear * Time.deltaTime;
            }
        }



        ///Check for controlled steering updates
        if (controlledSteeringUpdate != null)
        {
            linearVelocity  += controlledSteeringUpdate.linear * Time.deltaTime;
            angularVelocity += controlledSteeringUpdate.angular * Time.deltaTime;
        }


        //update lin ang vel

        linearVelocity  += steering.linear * Time.deltaTime;
        angularVelocity += steering.angular * Time.deltaTime;
    }
    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;
        }
    }
    // Update is called once per frame
    void Update()
    {
        transform.position += linearVelocity * Time.deltaTime;
        // adding angular velocity to current transform rotation y component
        transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0);

        // control to switch to proper steering behavior
        if (!arrive)
        {
            Seek mySeek = new Seek();
            mySeek.ai = this;
            // if seek is false set seek property on class to false to activate flee
            if (!seek)
            {
                mySeek.seek = false;
            }
            else
            {
                mySeek.seek = true;
            }
            mySeek.target = target;
            SteeringOutput steering = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
            if (linearVelocity.magnitude > maxSpeed)
            {
                linearVelocity.Normalize();
                linearVelocity *= maxSpeed;
            }
        }
        else
        {
            Arrive myArrive = new Arrive();
            myArrive.ai     = this;
            myArrive.target = target;
            SteeringOutput steering = myArrive.getSteering();

            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }

        /* commented out after turn in - non-relevant code for assignment was throwing errors
         * if (align)
         * {
         *  Align myAlign = new Align();
         *  myAlign.ai = this;
         *  myAlign.target = target;
         *  SteeringOutput steering = myAlign.getSteering();
         *  if (steering != null)
         *  {
         *      linearVelocity += steering.linear * Time.deltaTime;
         *      angularVelocity += steering.angular * Time.deltaTime;
         *  }
         * }
         * if (lookWhereGoing && !align)
         * {
         *  LookWhereGoing myLook = new LookWhereGoing();
         *  myLook.ai = this;
         *  target = new GameObject();
         *  SteeringOutput steering = myLook.getSteering();
         *  linearVelocity += steering.linear * Time.deltaTime;
         *  angularVelocity += steering.angular * Time.deltaTime;
         *  Destroy(target);
         * }
         */
    }
Example #27
0
    // Update is called once per frame
    void Update()
    {
        //Update pos rot
        transform.position += linearVelocity * Time.deltaTime;
        Vector3 angularIncrement = new Vector3(0, angularVelocity * Time.deltaTime, 0);

        if (float.IsNaN(angularIncrement.y))
        {
        }
        else
        {
            transform.eulerAngles += angularIncrement;
        }
        //Debug.Log(angularIncrement);

        SteeringOutput steering = new SteeringOutput();

        //Get Steerings
        if (bIsSeeking)
        {
            steering = mySeek.getSteering();
        }
        else
        {
            //steering = myFlee.getSteering();
        }
        if (bCanArrive)
        {
            SteeringOutput _arrvSteering = myArrv.getSteering();
            if (_arrvSteering != null)
            {
                linearVelocity  += _arrvSteering.linear * Time.deltaTime;
                angularVelocity += _arrvSteering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }
        if (bDoesAlign)
        {
            SteeringOutput _algnSteering = myAlgn.getSteering();
            if (_algnSteering != null)
            {
                steering.angular += _algnSteering.angular * Time.deltaTime;
            }
            else
            {
                angularVelocity = 0f;
            }
        }

        if (bDoesFace)
        {
            SteeringOutput _faceSteering = myFace.getSteering();
            if (_faceSteering != null)
            {
                angularVelocity += _faceSteering.angular * Time.deltaTime;
            }
        }
        if (bDoesLookWhereGoing)
        {
            SteeringOutput _lwygSteering = myLWYG.getSteering();
            if (_lwygSteering != null)
            {
                angularVelocity += _lwygSteering.angular * Time.deltaTime;
            }
        }
        if (bDoesFollowPath)
        {
            SteeringOutput _fpthSteering = myFPth.getSteering();
            if (_fpthSteering != null)
            {
                linearVelocity += _fpthSteering.linear * Time.deltaTime;
            }
        }

        //update lin ang vel

        linearVelocity  += steering.linear * Time.deltaTime;
        angularVelocity += steering.angular * Time.deltaTime;
    }
    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;

            follow.path = path;

            SteeringOutput following = follow.getSteering();

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

        case steeringBehaviors.Pursue:
            Pursue pursue = new Pursue();
            pursue.target    = newTarget;
            pursue.character = this;

            SteeringOutput pursuing = pursue.getSteering();

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

        case steeringBehaviors.Separate:
            Separate separate = new Separate();
            separate.character = this;
            separate.targets   = targets;
            SteeringOutput separating = separate.getSteering();
            if (separating != null)
            {
                linear  += separating.linear * Time.deltaTime;
                angular += separating.angular * Time.deltaTime;
            }
            break;
        }
    }
Example #29
0
    // Update is called once per frame
    void Update()
    {
        if (behaviorNum != 0)
        {
            // update my position and rotation
            this.transform.position += linearVelocity * Time.deltaTime;
            Vector3 v = new Vector3(0, angularVelocity, 0);
            this.transform.eulerAngles += v * Time.deltaTime;
        }

        // update linear and angular velocities
        SteeringOutput steering = new SteeringOutput();

        // Seek: target is "alsoMyTargetForPursueTho"
        if (behaviorNum == 1)
        {
            text.text = "Seek";

            Seek mySeek = new Seek();
            mySeek.target    = alsoMyTargetForPursueTho;
            mySeek.character = this;

            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        // Flee
        else if (behaviorNum == 2)
        {
            Flee myFlee = new Flee();
            text.text = "Flee";

            myFlee.character = this;
            myFlee.target    = myTarget;
            steering         = myFlee.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        // Arrive
        else if (behaviorNum == 3)
        {
            Arrive myArrive = new Arrive();
            text.text = "Arrive";

            myArrive.character = this;
            myArrive.target    = myTarget;
            steering           = myArrive.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }
        // Align
        else if (behaviorNum == 4)
        {
            Align myAlign = new Align();
            text.text = "Align";

            myAlign.character = this;
            myAlign.target    = myTarget;
            steering          = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Face
        else if (behaviorNum == 5)
        {
            Face myFace = new Face();
            text.text = "Face";

            myFace.character = this;
            myFace.target    = myTarget;
            steering         = myFace.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Look where you're going
        else if (behaviorNum == 6)
        {
            LWYG myLook = new LWYG();
            text.text = "LWYG";

            myLook.character = this;
            steering         = myLook.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Path following
        else if (behaviorNum == 7)
        {
            text.text = "Path Follow";

            myPathFollow.character = this;
            myPathFollow.path      = pathToFollow;
            steering = myPathFollow.getSteering();
            if (steering != null)
            {
                if (linearVelocity.magnitude > 2)
                {
                    linearVelocity = linearVelocity.normalized * 2;
                }

                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Pursue
        else if (behaviorNum == 8)
        {
            Pursue myPursue = new Pursue();
            text.text = "Pursue";

            myPursue.character = this;
            myPursue.target    = alsoMyTargetForPursueTho;
            steering           = myPursue.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Seperate
        else if (behaviorNum == 9)
        {
            text.text = "Seperate";

            mySeperate.character = this;
            mySeperate.targets   = targetsForSeperate;
            steering             = mySeperate.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Collision Avoidance
        else if (behaviorNum == 10)
        {
            text.text = "Collision Avoidance";

            CollisionAvoidance myCollision = new CollisionAvoidance();
            myCollision.character = this;
            myCollision.targets   = targetsForSeperate;
            steering = myCollision.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Obstacle Avoidance
        else if (behaviorNum == 11)
        {
            text.text = "Obstacle Avoidance";

            ObstacleAvoid myObstacleAvoid = new ObstacleAvoid();
            myObstacleAvoid.character = this;
            myObstacleAvoid.target    = myTarget;
            steering = myObstacleAvoid.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        // Flocking
        else if (behaviorNum == 12)
        {
            text.text = "Flocking";

            if (!setUp)
            {
                // BehaviorAndWeight1 : Seperate
                BehaviorAndWeight behavior1  = new BehaviorAndWeight();
                Seperate          mySeperate = new Seperate();
                mySeperate.character = this;
                GameObject[] birds  = GameObject.FindGameObjectsWithTag("Bird");
                Kinematic[]  kBirds = new Kinematic[birds.Length - 1];

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

                behavior1.behavior = mySeperate;
                behavior1.weight   = 10f;

                // BehaviorAndWeight2 : Arrive
                BehaviorAndWeight behavior2 = new BehaviorAndWeight();
                Arrive            myArrive  = new Arrive();
                myArrive.character = this;
                myArrive.target    = myTarget;
                behavior2.behavior = myArrive;
                behavior2.weight   = 10f;

                // BehaviorAndWeight3 : Align
                BehaviorAndWeight behavior3 = new BehaviorAndWeight();
                Align             myAlign   = new Align();
                myAlign.character  = this;
                myAlign.target     = myTarget;
                behavior3.behavior = myAlign;
                behavior3.weight   = 3f;

                // BehaviorAndWeight4 : ObstacleAvoidance
                BehaviorAndWeight behavior4  = new BehaviorAndWeight();
                ObstacleAvoid     myObstacle = new ObstacleAvoid();
                myObstacle.character = this;
                myObstacle.target    = myTargetObstacle; // Does this make sense?
                behavior4.behavior   = myObstacle;
                behavior4.weight     = 1f;

                // Lower priority steering behaviors: Arrive, Align, & Seperate
                BlendedSteeringDemo myBlended = new BlendedSteeringDemo();
                myBlended.behaviors    = new BehaviorAndWeight[3];
                myBlended.behaviors[0] = new BehaviorAndWeight();
                myBlended.behaviors[0] = behavior1;
                myBlended.behaviors[1] = new BehaviorAndWeight();
                myBlended.behaviors[1] = behavior2;
                myBlended.behaviors[2] = new BehaviorAndWeight();
                myBlended.behaviors[2] = behavior3;

                // Higher priority steering behavior: Obstacle avoidance
                BlendedSteeringDemo myBlendedAvoid = new BlendedSteeringDemo();
                myBlendedAvoid.behaviors    = new BehaviorAndWeight[1];
                myBlendedAvoid.behaviors[0] = new BehaviorAndWeight();
                myBlendedAvoid.behaviors[0] = behavior4;

                // Initialize myPriority's array of groups with two groups
                myPriority.groups    = new BlendedSteeringDemo[2];
                myPriority.groups[0] = new BlendedSteeringDemo();
                myPriority.groups[0] = myBlendedAvoid;
                myPriority.groups[1] = new BlendedSteeringDemo();
                myPriority.groups[1] = myBlended;

                setUp = true;
            }


            steering = myPriority.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
    }
Example #30
0
    // Update is called once per frame
    void Update()
    {
        myTarget = GameObject.Find("Player");
        // update my position and rotation
        this.transform.position += linearVelocity * Time.deltaTime;
        Vector3 v = new Vector3(0, angularVelocity, 0); // TODO - don't make a new Vector3 every update you silly person

        this.transform.eulerAngles += v * Time.deltaTime;

        // update linear and angular velocities
        SteeringOutput steering = new SteeringOutput();

        //TODO add switch statement for different move type (6 behaviours)

        if (flee)
        {
            Seek mySeek = new Seek
            {
                character = this,
                target    = myTarget
            };
            mySeek.flee      = true;
            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }
        else if (seek)
        {
            Seek mySeek = new Seek
            {
                character = this,
                target    = myTarget
            };
            steering         = mySeek.getSteering();
            linearVelocity  += steering.linear * Time.deltaTime;
            angularVelocity += steering.angular * Time.deltaTime;
        }

        else if (arrive)
        {
            Arrive myArrive = new Arrive
            {
                character = this,
                target    = myTarget
            };
            steering = myArrive.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
            else
            {
                linearVelocity = Vector3.zero;
            }
        }

        else if (face)
        {
            Face myAlign = new Face
            {
                character = this,
                target    = myTarget
            };
            steering = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        else if (look)
        {
            LookWhereYoureGoing myAlign = new LookWhereYoureGoing
            {
                character = this,
                target    = myTarget
            };
            steering = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
        else if (align)
        {
            Align myAlign = new Align
            {
                character = this,
                target    = myTarget
            };
            steering = myAlign.getSteering();
            if (steering != null)
            {
                linearVelocity  += steering.linear * Time.deltaTime;
                angularVelocity += steering.angular * Time.deltaTime;
            }
        }
    }