Smooth damp or tween algorithm

前端 未结 1 926
陌清茗
陌清茗 2021-01-26 03:45

I would like to know an algorithm for smooth damp or as some people call it, tween. I would like it in Lua preferably but anything will help.

I have tried watching unity

相关标签:
1条回答
  • 2021-01-26 04:05

    If I understand the question correctly, you're looking for an easing function. There is a Lua library that provides a set of easing functions on GitHub: https://github.com/EmmanuelOga/easing

    An example would be:

    local function inOutQuad(t, b, c, d)
      t = t / d * 2
      if t < 1 then
        return c / 2 * pow(t, 2) + b
      else
        return -c / 2 * ((t - 1) * (t - 3) - 1) + b
      end
    end
    

    Where t = time, b = begin value, c = change in value, and d = duration.

    More information on these easing functions is available directly from Robert Penner here (this is where the function above is derived from): http://www.robertpenner.com/easing/

    0 讨论(0)
提交回复
热议问题