예제 #1
0
        void FixedUpdate()
        {
            Vector3 accel = steeringBasics.Seek(target.position);

            steeringBasics.Steer(accel);
            steeringBasics.LookWhereYoureGoing();
        }
예제 #2
0
        public Vector3 GetSteering()
        {
            /* Get the jitter for this time frame */
            float jitter = wanderJitter * Time.deltaTime;

            /* Add a small random vector to the target's position */
            if (rb.is3D)
            {
                wanderTarget += new Vector3(Random.Range(-1f, 1f) * jitter, 0f, Random.Range(-1f, 1f) * jitter);
            }
            else
            {
                wanderTarget += new Vector3(Random.Range(-1f, 1f) * jitter, Random.Range(-1f, 1f) * jitter, 0f);
            }

            /* Make the wanderTarget fit on the wander circle again */
            wanderTarget.Normalize();
            wanderTarget *= wanderRadius;

            /* Move the target in front of the character */
            Vector3 targetPosition = transform.position + transform.right * wanderDistance + wanderTarget;

            //Debug.DrawLine(transform.position, targetPosition);

            return(steeringBasics.Seek(targetPosition));
        }
예제 #3
0
        public Vector3 GetSteering(MovementAIRigidbody target)
        {
            /* Calculate the distance to the target */
            Vector3 displacement = target.Position - transform.position;
            float   distance     = displacement.magnitude;

            /* Get the character's speed */
            float speed = rb.Velocity.magnitude;

            /* Calculate the prediction time */
            float prediction;

            if (speed <= distance / maxPrediction)
            {
                prediction = maxPrediction;
            }
            else
            {
                prediction = distance / speed;
            }

            /* Put the target together based on where we think the target will be */
            Vector3 explicitTarget = target.Position + target.Velocity * prediction;

            //Debug.DrawLine(transform.position, explicitTarget);

            return(steeringBasics.Seek(explicitTarget));
        }
예제 #4
0
        public Vector3 GetSteering()
        {
            float characterOrientation = rb.RotationInRadians;

            /* Update the wander orientation */
            wanderOrientation += RandomBinomial() * wanderRate;

            /* Calculate the combined target orientation */
            float targetOrientation = wanderOrientation + characterOrientation;

            /* Calculate the center of the wander circle */
            Vector3 targetPosition = transform.position + (SteeringBasics.OrientationToVector(characterOrientation) * wanderOffset);

            //debugRing.transform.position = targetPosition;

            /* Calculate the target position */
            targetPosition = targetPosition + (SteeringBasics.OrientationToVector(targetOrientation) * wanderRadius);

            //Debug.DrawLine (transform.position, targetPosition);

            return(steeringBasics.Seek(targetPosition));
        }