SimpleSoccer.Net.SoccerBall.CalculateFuturePosition C# (CSharp) Method

CalculateFuturePosition() public method

Given a time this method returns the ball position at that time in the future
public CalculateFuturePosition ( double time ) : Vector2D
time double
return Vector2D
        public Vector2D CalculateFuturePosition(double time)
        {
            //using the equation s = ut + 1/2at^2, where s = distance, a = friction
            //u=start velocity

            //calculate the ut term, which is a vector
            Vector2D ut = Velocity * time;

            //calculate the 1/2at^2 term, which is scalar
            double half_a_t_squared = 0.5 * ParameterManager.Instance.Friction * time * time;

            //turn the scalar quantity into a vector by multiplying the value with
            //the normalized velocity vector (because that gives the direction)
            Vector2D scalarToVector = half_a_t_squared * Vector2D.Vec2DNormalize(Velocity);

            //the predicted position is the balls position plus these two terms
            return Position + ut + scalarToVector;
        }

Usage Example

        /// <summary>
        /// This behavior creates a force that steers the agent towards the
        //  ball
        /// </summary>
        /// <param name="ball"></param>
        /// <returns></returns>
        protected Vector2D calculatePursuitVector(SoccerBall ball)
        {
            Vector2D toBall = ball.Position - _player.Position;

            //the lookahead time is proportional to the distance between the ball
            //and the pursuer;
            double lookAheadTime = 0.0;

            if (Math.Abs(ball.Speed) > Geometry.MinPrecision)
            {
                lookAheadTime = toBall.Length / ball.Speed;
            }

            //calculate where the ball will be at this time in the future
            _target = ball.CalculateFuturePosition(lookAheadTime);

            //now seek to the predicted future position of the ball
            return(calculateArriveVector(_target, DecelerationState.Fast));
        }
All Usage Examples Of SimpleSoccer.Net.SoccerBall::CalculateFuturePosition