// Update is called once per frame
        public DynoSteering getSteering()
        {
            ds   = new DynoSteering();
            goal = goalObject.getGoal();

            direction = goal.position - transform.position;
            distance  = direction.magnitude;

            if (distance < goalRadius)
            {
                return(ds);
            }

            if (distance > slowRadius)
            {
                targetSpeed = sp.MAXSPEED;
            }
            else
            {
                targetSpeed = sp.MAXSPEED * distance / slowRadius;
            }

            targetVelocity = direction;
            targetVelocity.Normalize();
            targetVelocity = targetVelocity * targetSpeed;

            ds.force = targetVelocity - charRigidBody.getVelocity();
            ds.force = ds.force / time_to_target;

            if (ds.force.magnitude > sp.MAXACCEL)
            {
                ds.force.Normalize();
                ds.force = ds.force * sp.MAXACCEL;
            }
            ds.torque = 0f;

            return(ds);
        }
示例#2
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());
            }
        }
示例#3
0
        public void Seek(bool arrive)
        {
            var direction = currentGoal - transform.position;
            var distance  = direction.magnitude;

            if (distance < goalRadius)
            {
                force             = Vector3.zero;
                tiltAmountForward = 0f;
                return;
            }

            float targetSpeed;

            if (distance > slowRadius || !arrive)
            {
                targetSpeed = SP.MAXSPEED;
            }
            else
            {
                targetSpeed = SP.MAXSPEED * distance / slowRadius;
            }

            tiltAmountForward = targetSpeed;

            //targetVelocity = direction.normalized;
            //targetVelocity.Normalize();
            targetVelocity = direction.normalized * targetSpeed;

            force = targetVelocity - KinematicBody.getVelocity();
            force = force / arriveTime;

            if (force.magnitude > SP.MAXACCEL)
            {
                force.Normalize();
                force = force * SP.MAXACCEL;
            }
        }
示例#4
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);
            }
        }