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


Author Topic: Linear interpolation  (Read 1364 times)

0 Members and 1 Guest are viewing this topic.

Offline RBS ID

  • Jr. Member
  • **
  • Posts: 67
  • Gender: Male
  • I don't know.
    • View Profile
    • This is website title.
Linear interpolation
« 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

« Last Edit: March 18, 2022, 06:51:08 PM by RanggaBS »

Offline Ming

  • Full Member
  • ***
  • Posts: 154
  • Gender: Male
  • 抽刀斷水水更流,舉杯消愁愁更愁
    • View Profile
Re: Linear interpolation
« Reply #1 on: April 03, 2022, 02:09:53 AM »
What is math.lerp