I have a floating point value X which is animated. When in rest it’s at zero, but at times an outside source may change it to somewhere between -1 and 1.
If that happens I want it to go smoothly back to 0. I currently do something like
addToXspeed(-x * FACTOR);
// below is out of my control
function addToXspeed(bla) {
xspeed += bla;
x += xspeed;
}
every step in the animation, but that only causes X to oscillate. I want it to rest on 0 however.
(I’ve explained the problem in abstracts. The specific thing I’m trying to do is make a jumping game character balance himself upright in the air by applying rotational force)
Writing the question oftens results in realising the answer.
targetxspeed = -x * FACTOR; addToXspeed(targetxspeed - xspeed); // below is out of my control function addToXspeed(bla) { xspeed += bla; x += xspeed; }So simple too