/// <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); }
/// <summary> /// Apply an impulse to the body without increasing it's velocity above a specific limit. /// </summary> public void ApplyLinearImpulse(Vector2 impulse, Vector2 point, float maxVelocity) { if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f)) { return; } if (!IsValidValue(point, "point")) { return; } if (!IsValidValue(maxVelocity, "max velocity")) { return; } Vector2 velocityAddition = impulse / Mass; Vector2 newVelocity = FarseerBody.LinearVelocity + velocityAddition; float newSpeedSqr = newVelocity.LengthSquared(); if (newSpeedSqr > maxVelocity * maxVelocity) { newVelocity = newVelocity.ClampLength(maxVelocity); } if (!IsValidValue((newVelocity - FarseerBody.LinearVelocity), "new velocity", -1000.0f, 1000.0f)) { return; } FarseerBody.ApplyLinearImpulse((newVelocity - FarseerBody.LinearVelocity) * Mass, point); FarseerBody.AngularVelocity = MathHelper.Clamp( FarseerBody.AngularVelocity, -NetConfig.MaxPhysicsBodyAngularVelocity, NetConfig.MaxPhysicsBodyAngularVelocity); }
/// <summary> /// Apply an impulse to the body without increasing it's velocity above a specific limit. /// </summary> public void ApplyLinearImpulse(Vector2 impulse, float maxVelocity) { if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f)) { return; } if (!IsValidValue(maxVelocity, "max velocity")) { return; } Vector2 velocityAddition = impulse / Mass; Vector2 newVelocity = FarseerBody.LinearVelocity + velocityAddition; float newSpeedSqr = newVelocity.LengthSquared(); if (newSpeedSqr > maxVelocity * maxVelocity) { newVelocity = newVelocity.ClampLength(maxVelocity); } if (!IsValidValue((newVelocity - FarseerBody.LinearVelocity), "new velocity", -1000.0f, 1000.0f)) { return; } FarseerBody.ApplyLinearImpulse((newVelocity - FarseerBody.LinearVelocity) * Mass); }
public void ApplyTorque(float torque) { if (!IsValidValue(torque, "torque")) { return; } FarseerBody.ApplyTorque(torque); }
public void ApplyForce(Vector2 force) { if (!IsValidValue(force, "force", -1e10f, 1e10f)) { return; } FarseerBody.ApplyForce(force); }
public void ApplyForce(Vector2 force, Vector2 point) { if (!IsValidValue(force, "force", -1e10f, 1e10f)) { return; } if (!IsValidValue(point, "point")) { return; } FarseerBody.ApplyForce(force, point); }
public void ApplyLinearImpulse(Vector2 impulse) { if (!IsValidValue(impulse / FarseerBody.Mass, "new velocity", -1000f, 1000f)) { return; } if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f)) { return; } FarseerBody.ApplyLinearImpulse(impulse); }
public void MoveToPos(Vector2 simPosition, float force, Vector2?pullPos = null) { if (pullPos == null) { pullPos = FarseerBody.Position; } if (!IsValidValue(simPosition, "position", -1e10f, 1e10f)) { return; } if (!IsValidValue(force, "force")) { return; } Vector2 vel = FarseerBody.LinearVelocity; Vector2 deltaPos = simPosition - (Vector2)pullPos; deltaPos *= force; FarseerBody.ApplyLinearImpulse((deltaPos - vel * 0.5f) * FarseerBody.Mass, (Vector2)pullPos); }
public bool SetTransformIgnoreContacts(Vector2 simPosition, float rotation, bool setPrevTransform = true) { System.Diagnostics.Debug.Assert(MathUtils.IsValid(simPosition)); System.Diagnostics.Debug.Assert(Math.Abs(simPosition.X) < 1000000.0f); System.Diagnostics.Debug.Assert(Math.Abs(simPosition.Y) < 1000000.0f); if (!IsValidValue(simPosition, "position", -1e10f, 1e10f)) { return(false); } if (!IsValidValue(rotation, "rotation")) { return(false); } FarseerBody.SetTransformIgnoreContacts(ref simPosition, rotation); if (setPrevTransform) { SetPrevTransform(simPosition, rotation); } return(true); }
public void ResetDynamics() { FarseerBody.ResetDynamics(); }