示例#1
0
        /// <summary>
        /// The Update funcion moves the entity along their path
        /// </summary>
        /// <param name="time_elapsed">The time since the last update</param>
        public void Update(float time_elapsed)
        {
            if (parent.path.Count > 0)
            {
                if (parent.position.Distance(parent.path.current) < 1)
                {
                    if (!parent.path.GoNext())
                    {
                        return;
                    }
                }

                Vector2D target = Vector2D.Zero;

                foreach (ISteering force in steeringFactors)
                {
                    target += force.ApplySteering(this);
                    if (target.Length() >= parent.maxForce)
                    {
                        break;
                    }
                }

                target += parent.position;

                if (parent.RotateHeadingToFacePosition(target))
                {
                    parent.oldPos    = parent.position;
                    parent.position += parent.heading * parent.maxSpeed * time_elapsed;
                }
            }
        }