Example #1
0
        public void Steer(Vector3 origin, Vector3 target, bool departed, bool arrive)
        {
            // assume position already set

            currentGoal = target;

            seekTask  = () => Seek(arrive);
            alignTask = Align;

            Mathf.Lerp(transform.position.x, origin.x, 1f);
            Mathf.Lerp(transform.position.z, origin.z, 1f);

            //Mathf.SmoothDamp(transform.position.x, origin.x, ref positionRefx, 1f);
            //Mathf.SmoothDamp(transform.position.z, origin.z, ref positionRefz, 1f);
            //transform.position = origin;
            KinematicBody.position = transform.position;

            if (departed)
            {
                // current Velocity is the position + directino * max speed
                var direction       = currentGoal - transform.position;
                var currentVelocity = direction.normalized * SP.MAXSPEED;
                // instantaneously set orientation and velocity
                KinematicBody.setVelocity(currentVelocity);
                KinematicBody.setOrientation(KinematicBody.getNewOrientation(currentVelocity));
                transform.position = new Vector3(KinematicBody.position.x, transform.position.y, KinematicBody.position.z);
                transform.rotation = Quaternion.Euler(0f, KinematicBody.getOrientation() * Mathf.Rad2Deg - 90f, 0f);
            }

            steering    = true;
            playingClip = true;
        }
        // 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 = 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);
        }