Esempio n. 1
0
        // Update is called once per frame
        public KinematicSteeringOutput updateSteering(DynoSteering ds, float time)
        {
            if (sp == null)
            {
                sp = GetComponent <SteeringParams>();

                position    = this.transform.position;
                velc        = new Vector3(0f, 0f, 0f);
                rotation    = 0f;
                orientation = 0f;
            }

            steering = new KinematicSteeringOutput();

            // make Updates
            position    += velc * time;
            orientation += rotation * time;

            velc        += ds.force * time;
            orientation += ds.torque * time;

            if (velc.magnitude > sp.MAXSPEED)
            {
                velc.Normalize();
                velc = velc * sp.MAXSPEED;
            }

            steering.position    = position;
            steering.orientation = orientation;

            return(steering);
        }
Esempio n. 2
0
        //public void RegisterPlayableToList

        // Update is called once per frame
        void Update()
        {
            if (!initiatedExternally)
            {
                steering = false;
                //throw new System.Exception();
            }
            if (steering)
            {
                //Debug.Log(gameObject.name + " " + transform.position);

                //Debug.Log(transform.name + force.ToString());
                seekTask();

                // Strategy to prevent sudden re-allignment.
                if (playingClip)
                {
                    alignTask();
                    //Debug.Log("aligning " + transform.name);
                }

                kso = KinematicBody.updateSteering(new DynoSteering(force, torque), Time.deltaTime);
                transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);

                transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
                playingClip        = false;
            }
        }
        // Update is called once per frame
        public KinematicSteeringOutput updateSteering(DynoSteering ds, float time)
        {
            steering = new KinematicSteeringOutput();

            //perform wander behavior


            // make Updates
            position    += (velc) * time;
            orientation += rotation * time;

            velc        += ds.force * time;
            orientation += ds.torque * time;

            if (velc.magnitude > sp.MAXSPEED)
            {
                velc.Normalize();
                velc = velc * sp.MAXSPEED;
            }

            steering.position    = position;
            steering.orientation = orientation;

            return(steering);
        }
Esempio n. 4
0
        // Update is called once per frame
        void Update()
        {
            // Decide on behavior
            ds_force  = arrive.getSteering();
            ds_torque = align.getSteering();

            ds = new DynoSteering(ds_force.force, ds_torque.torque);

            // Update Kinematic Steering
            kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
            //Debug.Log(kso.position);
            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
        }
        private void kinematicSeekBehavior()
        {
            ds = new DynoSteering();

            // Decide on behavior
            seeking_output = seek.getSteering();
            char_kinematic.setVelocity(seeking_output.velc);
            // Manually set orientation for now
            float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);

            char_kinematic.setOrientation(new_orient);
            char_kinematic.setRotation(0f);

            // Update Kinematic Steering
            kso = char_kinematic.updateSteering(ds, Time.deltaTime);

            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
        }
Esempio n. 6
0
        // Update is called once per frame
        void Update()
        {
            ks = new KinematicSteering();
            ds = new DynoSteering();

            // Decide on behavior

            //seeking_output = seek.updateSteering();
            //******seeking_output = arrive.getSteering();
            seeking_output = arrive.getSteering();
            ds_torque      = align.getSteering();
            //******
            //seeking_output = seek.getSteering();
            char_kinematic.setVelocity(seeking_output.velc);

            // Manually set orientation for now
            /*Replace these three lines with a dynamic rotation*/
            //float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);
            //char_kinematic.setOrientation(new_orient);
            //char_kinematic.setRotation(0f);

            ds.torque = ds_torque.torque;

            // Update Kinematic Steering
            kso = char_kinematic.updateSteering(ds, Time.deltaTime);

            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);


            /*record and write out speed on timer*/
            string t = (Time.time - StartTime).ToString();

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"C:\Grad School\AI\A1\" + FileName, true))
            {
                file.WriteLine(t + " | " + char_kinematic.getVelocity().ToString());
            }
        }
Esempio n. 7
0
        private void kinematicSeekBehavior()
        {
            ds = new DynoSteering();

            // Decide on behavior
            //******
            seeking_output = seek.getSteering();
            //******seeking_output = align.getSteering();
            //******
            char_kinematic.setVelocity(seeking_output.velc);
            // Manually set orientation for now
            /*Replace these three lines with a dynamic rotation*/
            //float new_orient = char_kinematic.getNewOrientation(seeking_output.velc);
            //char_kinematic.setOrientation(new_orient);
            //char_kinematic.setRotation(0f);

            ds.torque = ds_torque.torque;

            // Update Kinematic Steering
            kso = char_kinematic.updateSteering(ds, Time.deltaTime);

            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
        }
        void Update()
        {
            currentGoalTile = goalComponent.getGoalTile();
            currentTile     = QuantizeLocalize.Quantize(transform.position, tg);
            if (prevGoalTile != currentGoalTile)
            {
                foreach (TileNode tn in currentPath)
                {
                    if (tn.isEqual(currentTile))
                    {
                        continue;
                    }
                    tn.setOffMaterial();
                }


                currentPath  = PathFind.Dijkstra(tg, currentTile, currentGoalTile);
                prevGoalTile = currentGoalTile;
                // light up all tiles
                foreach (TileNode tn in currentPath)
                {
                    if (tn.isEqual(currentGoalTile))
                    {
                        continue;
                    }
                    tn.setPlanMaterial();
                }

                currentGoal = QuantizeLocalize.Localize(currentPath.Pop());
            }


            // determine how to set force
            if (currentPath.Count > 0)
            {
                ds_force = seek.getSteering(currentGoal);
                // pop when seek says we've made it into range and seek the next target
                if (seek.changeGoal)
                {
                    nextTile = currentPath.Pop();
                    nextTile.setNextMaterial();
                    currentGoal = QuantizeLocalize.Localize(nextTile);
                    if (currentPath.Count > 0)
                    {
                        ds_force = seek.getSteering(currentGoal);
                    }
                    else
                    {
                        ds_force = arrive.getSteering(currentGoal);
                    }
                }
            }
            else if (currentPath.Count == 0)
            {
                ds_force = arrive.getSteering(currentGoal);
            }


            ds_torque = align.getSteering(currentGoal);

            ds        = new DynoSteering();
            ds.force  = ds_force.force;
            ds.torque = ds_torque.torque;

            kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
        }
Esempio n. 9
0
        // Update is called once per frame
        void Update()
        {
            ds = new DynoSteering();

            if (bHasGoal)
            {
                // Decide on behavior
                ds_force  = arrive.getSteering();
                ds_torque = align.getSteering();
            }
            else
            {
                Vector3 tempGoal = ds_wander.getWanderGoal(char_RigidBody.getVelocity(), transform.position, toCenterWanderCircle, wanderCircleRad);                     //, UpperBoundX, LowerBoundX, UpperBoundZ, LowerBoundZ);
                ds_force  = arrive.getSteering(tempGoal);
                ds_torque = align.getSteering(tempGoal);
            }

            ds.force  = ds_force.force;
            ds.torque = ds_torque.torque;


            // Update Kinematic Steering
            kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
            //Debug.Log(kso.position);
            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);

            /*record and write out speed on timer*/
            string t = (Time.time - StartTime).ToString();

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"C:\Grad School\AI\A1\" + FileName, true))
            {
                file.WriteLine(t + " | " + char_RigidBody.getVelocity().ToString());
            }

            DropCrumb(char_RigidBody.getVelocity());

            if (!(CheckInBounds(transform.position, UpperBoundX, LowerBoundX, UpperBoundZ, LowerBoundZ)))
            {
                char_RigidBody.setVelocity(char_RigidBody.getVelocity() * -1);
                //char_RigidBody.setRotation(char_RigidBody.getRotation () * -1);
                //char_RigidBody.setOrientation(char_RigidBody.getOrientation () - 180);
                //transform.Rotate (0, 180, 0);


                //float targetOrientation = char_RigidBody.getNewOrientation ((transform.position + char_RigidBody.getVelocity ()));
                //char_RigidBody.setRotation (targetOrientation - char_RigidBody.getOrientation ());

                //char_RigidBody.setOrientation (targetOrientation);
                //char_RigidBody.setRotation (char_RigidBody.getRotation () - 180);
                //char_RigidBody.setOrientation

                /*
                 * if (CheckInBounds (transform.position + (char_RigidBody.getVelocity () * -1), UpperBoundX, LowerBoundX, UpperBoundZ, LowerBoundZ))
                 * {
                 *      char_RigidBody.setVelocity (char_RigidBody.getVelocity () * -1);
                 * }
                 */
                //transform.Rotate (0, 180, 0);
                //char_RigidBody.setOrientation( char_RigidBody() * (-1)  );//char_RigidBody.getNewOrientation())//  char_RigidBody.getOrientation() - 180  );//char_RigidBody.getNewOrientation (char_RigidBody.getVelocity ()));
                //transform.rotation = Quaternion.Euler (0, kso.orientation * Mathf.Rad2Deg * -1 ,0);
                //char_RigidBody.setRotation(char_RigidBody.getRotation () * -1);
            }
        }
        void Update()
        {
            // check what the current goal is
            currentGoalTile = goalComponent.tileGoal;

            // check if we are at the goal position
            currentTile = QuantizeLocalize.Quantize(transform.position, tg);


            // if we're at the goal position, then pick a new goal
            if (currentTile == currentGoalTile)
            {
                Debug.Log("here");
                goalSetter.SetNextGoal();
                currentGoalTile = goalComponent.tileGoal;

                // find path to new goal
                currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile);

                // pick next point to seek
                currentGoal = QuantizeLocalize.Localize(currentPath.Pop());
            }
            else if (!hasPath)
            {
                currentPath = PathFind.Dijkstra(tg, currentTile, currentGoalTile);
                currentGoal = QuantizeLocalize.Localize(currentPath.Pop());
                hasPath     = true;
            }


            // if we are not at last point on path
            if (currentPath.Count > 0)
            {
                // seek next point on path
                ds_force = seek.getSteering(currentGoal);

                // pop when seek says we've made it into range and seek the next target
                if (seek.changeGoal)
                {
                    nextTile    = currentPath.Pop();
                    currentGoal = QuantizeLocalize.Localize(nextTile);
                    if (currentPath.Count > 0)
                    {
                        ds_force = seek.getSteering(currentGoal);
                    }
                    else
                    {
                        ds_force = arrive.getSteering(currentGoal);
                    }
                }
            }
            // otherwise, we are approaching the path goal.  we should arrive.
            else if (currentPath.Count == 0)
            {
                ds_force = arrive.getSteering(currentGoal);
            }


            ds_torque = align.getSteering(currentGoal);

            ds        = new DynoSteering();
            ds.force  = ds_force.force;
            ds.torque = ds_torque.torque;

            kso = char_RigidBody.updateSteering(ds, Time.deltaTime);
            transform.position = new Vector3(kso.position.x, transform.position.y, kso.position.z);
            transform.rotation = Quaternion.Euler(0f, kso.orientation * Mathf.Rad2Deg, 0f);
        }