Example #1
0
        public void Align()
        {
            var targetOrientation = KinematicBody.getNewOrientation(currentGoal - transform.position);
            //rotation = goal.eulerAngles;
            var rotation = targetOrientation - KinematicBody.getOrientation();

            rotation = Kinematic.mapToRange(rotation);
            var rotationSize = Mathf.Abs(rotation);

            if (rotationSize < angularGoalRadius)
            {
                torque             = 0f;
                tiltAmountSideways = 0f;
                return;
            }

            float targetRotation;

            // if we're outside the slow Radius
            if (rotationSize > angularSlowRadius)
            {
                targetRotation = SP.MAXROTATION;
            }
            else
            {
                targetRotation = SP.MAXROTATION * rotationSize / slowRadius;
            }

            tiltAmountSideways = targetRotation;

            // Final target rotation combines speed (already in variable) with rotation direction
            targetRotation = targetRotation * rotation / rotationSize;

            torque = targetRotation - KinematicBody.getRotation();
            torque = torque / alignTime;

            var angularAcceleration = Mathf.Abs(torque);

            if (angularAcceleration > SP.MAXANGULAR)
            {
                torque = torque / angularAcceleration;
                torque = torque * SP.MAXANGULAR;
            }
        }
        //public virtual DynoSteering getSteering();

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

            ds = new DynoSteering();
            //goal.position - transform.position;
            targetOrientation = charRigidBody.getNewOrientation(goal.position - transform.position);
            //rotation = goal.eulerAngles;
            rotation     = targetOrientation - charRigidBody.getOrientation();
            rotation     = Kinematic.mapToRange(rotation);
            rotationSize = Mathf.Abs(rotation);

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

            // if we're outside the slow Radius
            if (rotationSize > slowRadius)
            {
                targetRotation = sp.MAXROTATION;
            }
            else
            {
                targetRotation = sp.MAXROTATION * rotationSize / slowRadius;
            }

            // Final target rotation combines speed (already in variable) with rotation direction
            targetRotation = targetRotation * rotation / rotationSize;

            ds.torque = targetRotation - charRigidBody.getRotation();
            ds.torque = ds.torque / time_to_target;

            angularAcceleration = Mathf.Abs(ds.torque);

            if (angularAcceleration > sp.MAXANGULAR)
            {
                ds.torque = ds.torque / angularAcceleration;
                ds.torque = ds.torque * sp.MAXANGULAR;
            }

            return(ds);
        }
        // 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);
        }