Example #1
0
        /// <summary>
        /// Apply a force to the body without increasing it's velocity above a specific limit.
        /// </summary>
        public void ApplyForce(Vector2 force, float maxVelocity)
        {
            if (!IsValidValue(maxVelocity, "max velocity"))
            {
                return;
            }

            Vector2 velocityAddition = force / Mass * (float)Timing.Step;
            Vector2 newVelocity      = FarseerBody.LinearVelocity + velocityAddition;

            float newSpeedSqr = newVelocity.LengthSquared();

            if (newSpeedSqr > maxVelocity * maxVelocity && Vector2.Dot(FarseerBody.LinearVelocity, force) > 0.0f)
            {
                float newSpeed       = (float)Math.Sqrt(newSpeedSqr);
                float maxVelAddition = maxVelocity - newSpeed;
                if (maxVelAddition <= 0.0f)
                {
                    return;
                }
                force = velocityAddition.ClampLength(maxVelAddition) * Mass / (float)Timing.Step;
            }

            if (!IsValidValue(force, "clamped force", -1e10f, 1e10f))
            {
                return;
            }
            FarseerBody.ApplyForce(force);
        }
Example #2
0
 public void ApplyForce(Vector2 force)
 {
     if (!IsValidValue(force, "force", -1e10f, 1e10f))
     {
         return;
     }
     FarseerBody.ApplyForce(force);
 }
Example #3
0
 public void ApplyForce(Vector2 force, Vector2 point)
 {
     if (!IsValidValue(force, "force", -1e10f, 1e10f))
     {
         return;
     }
     if (!IsValidValue(point, "point"))
     {
         return;
     }
     FarseerBody.ApplyForce(force, point);
 }