public void Update() { var x = End1.Position - End2.Position; double length = x.Length(); if (length <= TargetLength) { return; } x = (x / length) * (length - TargetLength); var dv = End2.Velocity - End1.Velocity; var force = Stiffness * x - dv * Damping; End1.ApplyForce(-force); End2.ApplyForce(force); }
public void Update() { var x = End1.Position - End2.Position; float length = x.magnitude; // these springs can only pull, not push if (length <= TargetLength) { return; } x = (x / length) * (length - TargetLength); var dv = End2.Velocity - End1.Velocity; var force = Stiffness * x - dv * Damping; End1.ApplyForce(-force); End2.ApplyForce(force); }
public void Update() { var x = End1.Position - End2.Position; float length = x.Length(); // springs are only able to pull but not able to push if (length <= TargetLength) { return; } x = (x / length) * (length - TargetLength); var dv = End2.Velocity - End1.Velocity; var force = Stiffness * x - dv * Damping; End1.ApplyForce(-force); End2.ApplyForce(force); }