Ejemplo n.º 1
0
        private Vector2D Wander()
        {
            //this behavior is dependent on the update rate, so this line must
            //be included when using time independent framerate.
            var jitterThisTimeSlice = m_dWanderJitter * _entity.TimeEllapsed;

            if (jitterThisTimeSlice <= 0)
                jitterThisTimeSlice = 1;

            //first, add a small random vector to the target's position
            m_vWanderTarget += new Vector2D((float)(VectorHelper.RandomClamped() * jitterThisTimeSlice),
                                        (float)(VectorHelper.RandomClamped() * jitterThisTimeSlice));

            //reproject this new vector back on to a unit circle
            m_vWanderTarget.Normalize();

            //increase the length of the vector to the same as the radius
            //of the wander circle
            m_vWanderTarget *= (float)_mDWanderRadius;

            //move the target into a position WanderDist in front of the agent
            Vector2D target = m_vWanderTarget + new Vector2D(m_dWanderDistance, 0);

            //project the target into world space
            _entity.Target = PointToWorldSpace(target,
                                                 _entity.Heading,
                                                 _entity.Side,
                                                 _entity.Pos);

            //and steer towards it
            return _entity.Target - _entity.Pos;
        }