How to tween a parabola?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to tween a parabola?

Post by pgimeno »

Gunroar:Cannon() wrote: Wed Dec 07, 2022 7:13 pm I think when the (Y) value of the goal is bigger than the (Y) value of the origin it has an opposite arc and reversing the at. just makes it wobble. Anyway to always make the arc one that goes up and back down no matter what (while still using tweening)?
What?

Code: Select all

local function lerp(a, b, t)
  return t < 0.5 and a + (b - a) * t or b - (b - a) * (1 - t)
end

local function tween_parabola(a, b, t)
  return lerp(a, b, 1-(t*2-1)^2)
end

print(tween_parabola(5, 100, 0)) -- prints 5
print(tween_parabola(5, 100, 0.5)) -- prints 100
print(tween_parabola(5, 100, 1)) -- prints 5
What you're doing with the parameters is not the function's fault.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: How to tween a parabola?

Post by Gunroar:Cannon() »

pgimeno wrote: Wed Dec 07, 2022 9:00 pm
Gunroar:Cannon() wrote: Wed Dec 07, 2022 7:13 pm I think when the (Y) value of the goal is bigger than the (Y) value of the origin it has an opposite arc and reversing the at. just makes it wobble. Anyway to always make the arc one that goes up and back down no matter what (while still using tweening)?
What?

Code: Select all

local function lerp(a, b, t)
  return t < 0.5 and a + (b - a) * t or b - (b - a) * (1 - t)
end

local function tween_parabola(a, b, t)
  return lerp(a, b, 1-(t*2-1)^2)
end

print(tween_parabola(5, 100, 0)) --5
print(tween_parabola(5, 100, 0.5))-- 100
print(tween_parabola(5, 100, 1))-- 5
Oh, the function makes it go high to back to the original value when used. Okay, that makes sense now. I used it thinking it adds the parabola then takes it to the final value. To my discredit I didn't even try and see if I could understand the function, but now I see what happens in relation to t and how you got the formula :P (exp+1 :crazy: )

Thanks again.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests