private void ApplyForce(PhysicsBody body, float deltaTime) { float distFactor = 1.0f; if (ForceFalloff) { distFactor = 1.0f - ConvertUnits.ToDisplayUnits(Vector2.Distance(body.SimPosition, PhysicsBody.SimPosition)) / ColliderRadius; if (distFactor < 0.0f) { return; } } switch (ForceMode) { case TriggerForceMode.Force: if (ForceVelocityLimit < 1000.0f) { body.ApplyForce(Force * currentForceFluctuation * distFactor, ForceVelocityLimit); } else { body.ApplyForce(Force * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); } break; case TriggerForceMode.Acceleration: if (ForceVelocityLimit < 1000.0f) { body.ApplyForce(Force * body.Mass * currentForceFluctuation * distFactor, ForceVelocityLimit); } else { body.ApplyForce(Force * body.Mass * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); } break; case TriggerForceMode.Impulse: if (ForceVelocityLimit < 1000.0f) { body.ApplyLinearImpulse(Force * currentForceFluctuation * distFactor, maxVelocity: ForceVelocityLimit); } else { body.ApplyLinearImpulse(Force * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); } break; case TriggerForceMode.LimitVelocity: float maxVel = ForceVelocityLimit * currentForceFluctuation * distFactor; if (body.LinearVelocity.LengthSquared() > maxVel * maxVel) { body.ApplyForce( Vector2.Normalize(-body.LinearVelocity) * Force.Length() * body.Mass * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); } break; } }
public void ApplyForce(Vector2 force) { Body.ApplyForce(force); }
public void ApplyForce(Vector2 force) { Body.ApplyForce(force, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); }