Hacker News new | ask | show | jobs
by EsportToys 1111 days ago
if you are only every gonna use critical damping, you can do something like:

    function crit_response(dt,pos,vel,rate)
       local dissipation = math.exp(-dt*rate)
       local disspatePos = pos*dissiptation
       local disspateVel = vel*dissiptation
       local posCarried = 1 + dt*rate
       local velCarried = 1 - dt*rate
       local posFromVel =     dt 
       local velFromPos =    -dt*rate*rate
       local newpos = posCarried*dissipatePos + posFromVel*dissipateVel
       local newvel = velFromPos*dissipatePos + velCarried*dissipateVel
      return newpos , newvel
    end
(intentionally verbose for self-didactic purposes to show how you can actually split the dissipation step into its own loop out from the elastic calculation, meaning that you can use this as a more accurate initial guess in numeric simulations compared to just constant-acceleration approximations)
1 comments

I can see an argument for wanting to go slightly to one side or the other of the critical factor for aesthetic reasons, but yes. If you want "critically-damped spring behaviour" you don't have to go the long way round to get it.