Bully-Board

Bully Modding Section => Bully Modding => Topic started by: RBS ID on March 18, 2022, 12:25:40 AM

Title: Linear interpolation
Post by: RBS ID on March 18, 2022, 12:25:40 AM
Playing around with linear interpolation, another that similar to this is called easing or tweening.

Linear interpolation is used to move an object slowly. It can move slowly when it starts to move (acceleration), or when approaching the end point, or both.

Code: [Select]

--[[
  a = start point
  b = end point
  t = progress (the value is between 0 and 1)
]]
_G.math.lerp = function(a, b, t)
  return a + (b - a) * t
end

function main()
  Wait(1000)
  local x, y, z = PlayerGetPosXYZ ()
  local eff = EffectCreate ("GymFire", x, y, z)
  repeat
    Wait(0)
    local X, Y, Z = PlayerGetPosXYZ ()
    x, y, z = math.lerp(x, X,  0.05),  math.lerp(y, Y, 0.05), math.lerp(z, Z, 0.05)
    EffectSetPosition (eff, x, y, z)
  until IsButtonBeingPressed (6, 0)
  EffectKill (eff)
  x, y, z, eff = nil, nil, nil, nil
  while true do
    Wait(0)
  end
end

Title: Re: Linear interpolation
Post by: Ming on April 03, 2022, 02:09:53 AM
What is math.lerp