News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: Linear interpolation  (Read 468 times)

0 Members and 1 Guest are viewing this topic.

Offline RanggaBS

  • Jr. Member
  • **
  • Posts: 64
  • Gender: Male
  • I don't know.
    • View Profile
    • This is website title.
Linear interpolation
« 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
« Last Edit: March 18, 2022, 12:29:59 AM by RanggaBS »