物理エンジンにばねを追加しようとしていますが、アルゴリズム自体は機能しますが、非常に硬いです(目に見える動きを引き出すには、値<=約0.1を入力する必要があり、非常に小さく設定する必要があります)。正しく動作するために)。次のコードを改善して、0.1から1の範囲の値でそれほど硬くないようにするためのヒントはありますか?
Vector2 posDiff = _a1.Position - _a2.Position;
Vector2 diffNormal = posDiff;
diffNormal.Normalize();
Vector2 relativeVelocity = _a1.Velocity - _a2.Velocity;
float diffLength = posDiff.Length();
float springError = diffLength - _restLength;
float springStrength = springError * _springStrength;
if (!float.IsPositiveInfinity(_breakpoint) && (springError > _breakpoint || springError < -1 * _breakpoint))
{
_isBroken = true;
}
float temp = Vector2.Dot(posDiff, relativeVelocity);
float dampening = _springDampening * temp / diffLength;
Vector2 _force = Vector2.Multiply(diffNormal, -(springStrength + dampening));
_a1.ApplyForce(_force / 2);
_a2.ApplyForce(-_force / 2);