public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(.0f, .0f), .0f);
        SteeringOutput.SteeringOutput auxSteering;

        for (int i = 0; i < weightedBehaviours.Count; i++)
        {
            auxSteering = weightedBehaviours [i].behaviour.getSteering();

            auxSteering.linear.x *= weightedBehaviours [i].weight;
            auxSteering.linear.y *= weightedBehaviours [i].weight;

            auxSteering.angular *= weightedBehaviours [i].weight;

            steering += auxSteering;
        }

        Behaviour lwyg = new LWYG(Character);

        steering += lwyg.getSteering();

        if (steering.linear.magnitude > Character.maxAcceleration)
        {
            steering.linear = steering.linear.normalized * Character.maxAcceleration;
        }

        if (steering.angular > Character.maxAngularAcceleration)
        {
            steering.angular = Character.maxAngularAcceleration;
        }

        return(steering);
    }
    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 flee = new Flee(dummyAgent, Character);

        SteeringOutput.SteeringOutput steering = flee.getSteering();

        MonoBehaviour.Destroy(dummy);

        Behaviour lwyg = new LWYG(Character);

        steering += lwyg.getSteering();

        return(steering);
    }
Exemple #3
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f);

        Vector2 direction = Target.position - Character.position;
        float   distance  = direction.magnitude;

        if (distance < targetRadius)
        {
            return(steering);
        }

        var targetSpeed = Character.maxSpeed;

        if (distance <= slowRadius)
        {
            targetSpeed *= distance / slowRadius;
        }

        var targetVelocity = direction.normalized * targetSpeed;

        steering.linear  = ((Vector3)targetVelocity) - Character.velocity;
        steering.linear /= timeToTarget;

        steering.angular = 0.0f;

        Behaviour lwyg = new LWYG(Character);

        steering += lwyg.getSteering();

        return(steering);
    }
Exemple #4
0
    // Update is called once per frame
    protected override void Update()
    {
        SteeringOutput steeringUpdate = new SteeringOutput();

        steeringUpdate.angular = myRotateType.getSteering().angular;
        steeringUpdate.linear  = myMoveType.getSteering().linear;
        base.Update();
    }
    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);
    }
Exemple #6
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput();
        steering.linear  = Character.position - Target.position;
        steering.linear  = steering.linear.normalized * Character.maxAcceleration;
        steering.angular = 0.0f;

        Behaviour lwyg = new LWYG(Character);

        steering += lwyg.getSteering();
        return(steering);
    }
Exemple #7
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;
            }
        }
    }
    // 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;
            }
        }
    }
    // 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;
            }
        }
    }
    // 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;
            }
        }
    }