A tiny-spring utility that returns the change of the value.
I'm tired of installing popmotion just to get the spring.
This is the younger brother of Lerpy.
Usage
; let change = ;objkey += change;
With actual code:
; let obj = x: 0 ;let settings = spring: 08 damping: 02friction: 098 snapThreshold: 0001 ; let changeX = ;objx += changeX;
- Call sringu
- Add the velocity to the value
A note on API design.
No callbacks for when updating or completing.
While this makes it so you have to do that manually. It makes checking when multiple springs are done easier to think about and do. Without the need for a super complex API.
IMAGINARY API: callbacks + automatic setting the value
// THIS ISN'T THE ACTUAL API. JUST TO ILUSTRATE; let obj = x: 0 y: 0 ;let settings = spring: 08 damping: 02friction: 098 snapThreshold: 0001 ;let isXdone = false;let isYdone = false; // THIS ISN'T THE ACTUAL API. JUST TO ILUSTRATE
This feels like I have to go back and forward to understand what's even happening here.
Happy API : Returning the velocity to allow manual checking
; let obj = x: 0 y: 0 ;let settings = spring: 08 damping: 02friction: 098 snapThreshold: 0001 ; let speedX = ;let speedY = ; objx += speedX;objy += speedY; // Do something if they aren't doneifspeedX || speedY{}// Do something when both are doneif!speedX && !speedY{}
The code is pretty linear and I can understand/wrap my head around it pretty easily.
No automatic adding to the object
While having to do this is more mental overhead:
objx += speedX; objy += speedY;
I have two reasons for doing this.
- Keep the API the same as my Lerpy package.
- Meaning you can swap them with only one line. And you don't need to remember to remove/add that line of code
- I honeslty forgot about the second one. But yeah, the 1st is more than enough for me
On that note...
lerpy doesn't.
Why springu needs the object, whileUnlike lerpy, springu needs to hold the current velocity of the spring somewhere. And it also needs to somehow know which is the velocity for certain value.
The only way of doing that with the lerpy API, is to rely on call order. Which is not the best of ideas since that's out of the scope of springu.