Ejemplo n.º 1
0
        public override SteeringOutput getSteering()
        {
            base.getSteering();
            // Create the structure to hold the output
            SteeringOutput steering = new SteeringOutput();

            // Get the naive direction to target
            float rotation = target.orientation - character.orientation;

            // Map the result to the (-pi,pi) interval
            rotation = mapToRange(rotation);
            float rotationAngle = Math.Abs(rotationDirection);

            // Check if we are there, return no steering
            if (rotationAngle < targetRadius)
                return null;

            // If we are outside the slowRadius, then use
            // maximum rotation
            if (rotationAngle > slowRadius)
            {
                targetRotation = maxRotation;
            }
            else
            {
                targetRotation = maxRotation * rotationAngle / slowRadius;
            }

            // The final target rotation combines
            // speed (already in the variable) and direction
            targetRotation *= rotation / rotationAngle;

            // Acceleration tries to get to the target rotation
            steering.angular = targetRotation - character.rotation;
            steering.angular /= timeToTarget;

            // Check if the acceleration is too great
            float angularAcceleration = Math.Abs(steering.angular);
            if (angularAcceleration > maxAngularAcceleration)
            {
                steering.angular /= angularAcceleration;
                steering.angular *= maxAngularAcceleration;
            }

            // Output the steering
            steering.linear = new Vector2(0.f,0.f);
            return steering;
        }
Ejemplo n.º 2
0
        public SteeringOutput getSteering()
        {
            // create the structure for output
            SteeringOutput steering = new SteeringOutput();

            // get velocity from the vector form of the orientation
            steering.linear = maxSpeed * character.orientation.asVector();

            // change our orientation randomly
            steering.angular = randomBinomial() * maxRotation;

            // output steering
            return steering;
        }
Ejemplo n.º 3
0
        public SteeringOutput getSteering()
        {
            // create the structure for output
            SteeringOutput steering = new SteeringOutput();

            // get the direction to the target
            steering.linear = target.position - character.position;

            // the velocity is along this direction, at full speed
            steering.linear.Normalize();
            steering.linear *= maxSpeed;

            // face in the direction we want to move
            character.orientation = getNewOrientation(character.orientation,
                steering.linear);

            // output the steering
            steering.angular = 0;
            return steering;
        }
Ejemplo n.º 4
0
        // implements steering so that character arrives
        // at prescribed radius to the target.
        public SteeringOutput getSteering()
        {
            // create structure for output
            SteeringOutput steering = new SteeringOutput();

            // get the direction to target
            steering.linear = target.position - character.position;

            // check if we're within radius
            if (steering.linear.Length() < radius)
            {
                return null;
            }

            // we need to move to our target, we'd like to
            // get there in timeToTarget seconds
            steering.linear /= timeToTarget;

            // if this is too fast clip it to the max speed
            if (steering.linear.Length() > maxSpeed)
            {
                steering.linear.Normalize();
                steering.linear *= maxSpeed;
            }

            // face in the direction we want to move
            character.orientation = getNewOrientation(character.orientation,
                steering.linear);

            // output steering
            steering.angular = 0.f;
            return steering;
        }
Ejemplo n.º 5
0
            /// <summary>
            /// This uses Newton-Euler update, which works fine
            /// for small time intervals.
            /// </summary>
            /// <param name="steering"></param>
            /// <param name="time"></param>
            public void updateEuler(SteeringOutput steering, float time)
            {
                // Update the position and orientation
                position += velocity * time;
                orientation += rotation * time;

                // and the velocity and rotation
                velocity += steering.linear * time;
                rotation += steering.angular * time;
            }
Ejemplo n.º 6
0
        // Returns the desired steering output
        public SteeringOutput getSteering()
        {
            // create the structure to hold our output
            SteeringOutput steering = new SteeringOutput();

            // get the direction to the target
            steering.linear = target.position - character.position;

            // give full aceleration is along this direction
            steering.linear.Normalize();
            steering.linear *= maxAcceleration;

            // output the steering
            steering.angular = 0;
            return steering;
        }
Ejemplo n.º 7
0
        public override SteeringOutput getSteering()
        {
            // Create the structure to hold our output
            SteeringOutput steering = new SteeringOutput();

            // Get the direction to the target
            Vector2 direction = target.position - character.position;
            float distance = direction.Length();

            // Check if we are there return no steering
            if (distance < targetRadius)
                return null;

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

            // The target velocity combines speed and direction
            Vector2 targetVelocity = direction;
            targetVelocity.Normalize();
            targetVelocity *= targetSpeed;

            // Acceleration tries to get to target velocity
            steering.linear = targetVelocity - character.velocity;
            steering.linear /= timeToTarget;

            // Check if the acceleration is too fast
            if (steering.linear.Length() > maxAcceleration)
            {
                steering.linear.Normalize();
                steering.linear *= maxAcceleration;
            }

            // Output the steering
            steering.angular = 0.f;
            return steering;
        }