Sibling of L3 Tween.
Add as a git package:
https://github.com/Less3Design/L3-spring.git
private Spring3 moveSpring;
void Start()
{
moveSpring = Spring3.At(transform.position)
.SetOnUpdate(p => transform.position = p)
.SetOnComplete(() => Debug.Log("arrived"));
}
void MoveTo(Vector3 point) => moveSpring = moveSpring.SetTarget(point);Spring,Spring2,Spring3,Spring4spring afloat,Vector2,Vector3,Vector4.- Handles are readonly structs. Always assign the result of every call.
SetTargeton a moving spring changes its goal and keeps its momentum. On an idle spring it starts a new one from where the last stopped, with the same settings.- A spring is done when it is within
restThresholdof the target and nearly stopped. It snaps to the target, callsonUpdateonce more, thenonComplete. - Idle springs hold no pool slot. Nothing to clean up.
acceleration = -stiffness * (value - target) - damping * velocity
SetFrequency(hz, ratio) is the easy way to set both:
- hz: how fast. Oscillations per second if there were no damping.
- ratio: how bouncy.
0bounces forever,1no overshoot,>1sluggish.
Default is 170 stiffness, 26 damping (ratio 1).
restThreshold defaults to 0.001, which suits 0..1 values. Raise it for world units.
256 springs, doubles as needed up to 4096. Change it in Project Settings > Less3 > Spring, or in code before the first spring:
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void ConfigureSprings() => SpringManager.Configure(initialPoolSize: 512, maxPoolSize: 8192);