Bully-Board

Bully Modding Section => Script Modding => Topic started by: RBS ID on March 17, 2022, 10:20:53 AM

Title: Linear interpolation
Post by: RBS ID on March 17, 2022, 10:20:53 AM
Playing around with linear interpolation, another that similar to this is 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)
  until IsButtonBeingPressed (6, 0)
  EffectKill (eff)
  x, y, z, eff = nil, nil, nil, nil
  while true do
    Wait(0)
  end
end


Sorry, I posted in wrong section