Example #1
0
        public override SteeringOutput getSteering()
        {
            SteeringOutputDynamic steering = new SteeringOutputDynamic();

            steering.linear  = character.position - target.position;
            steering.linear  = steering.linear.Normalize(2);
            steering.linear *= maxAcceleration;

            steering.angular = 0;

            return(steering);
        }
        public override SteeringOutput getSteering()
        {
            SteeringOutputDynamic steering = new SteeringOutputDynamic();

            steering.linear  = target.velocity - character.velocity;
            steering.linear /= timeToTarget;

            if (steering.linear.L2Norm() > maxAcceleration)
            {
                steering.linear = steering.linear.Normalize(2) * maxAcceleration;
            }

            steering.angular = 0;

            return(steering);
        }
Example #3
0
        public override SteeringOutput getSteering()
        {
            SteeringOutputDynamic steering = new SteeringOutputDynamic();

            Vector <float> direction = target.position - character.position;
            float          distance  = (float)direction.L2Norm();

            // Check if we are there, return no steering
            if (distance < targetRadius)
            {
                return(steering);
            }

            float targetSpeed = 0;

            // If we are outside the slowRadius, then go max speed
            if (distance > slowRadius)
            {
                targetSpeed = maxSpeed;
            }

            // Otherwise calculate a scaled speed
            else
            {
                targetSpeed = maxSpeed * (distance / slowRadius);
            }

            Vector <float> targetVelocity = direction.Normalize(2) * targetSpeed;

            steering.linear  = targetVelocity - character.velocity;
            steering.linear /= timeToTarget;

            if (steering.linear.L2Norm() > maxAcceleration)
            {
                steering.linear = steering.linear.Normalize(2) * maxAcceleration;
            }

            steering.angular = 0;

            return(steering);
        }
Example #4
0
        public override SteeringOutput getSteering()
        {
            SteeringOutputDynamic steering = new SteeringOutputDynamic();

            float rotation = target.orientation - character.orientation;

            while (rotation > Math.PI)
            {
                rotation -= 2 * (float)Math.PI;
            }
            while (rotation < -Math.PI)
            {
                rotation += 2 * (float)Math.PI;
            }
            float rotationSize = Math.Abs(rotation);

            if (rotationSize < targetRadius)
            {
                return(steering);
            }

            float targetRotation = rotationSize > slowRadius ? maxRotation : maxRotation * (rotationSize / slowRadius);

            targetRotation *= rotation / rotationSize;

            steering.angular  = targetRotation - character.rotation;
            steering.angular /= timeToTarget;

            float angularAcceleration = Math.Abs(steering.angular);

            if (angularAcceleration > maxAngularAcceleration)
            {
                steering.angular /= angularAcceleration;
                steering.angular *= maxAngularAcceleration;
            }

            steering.linear = Vector <float> .Build.Dense(2);

            return(steering);
        }