|
Started off well, then got horrifically confused. I'm making a custom lerp as I want to tween at speeds not possible with a standard :tween
My current issue revolves around my maths.
This:
function lerpnum(val, val2, amount)
return ((1-amount)*val) + (amount*val2)
end
function _M.lerp(value1, value2, amount)
return UDim2.new(lerpnum(value1.X.Scale, value2.X.Scale, amount), lerpnum(value1.X.Offset, value2.X.Offset, amount), lerpnum(value1.Y.Scale, value2.Y.Scale, amount), lerpnum(value1.Y.Offset, value2.Y.Offset, amount))
end
Called with this:
m = require(game.ServerScriptService.ModuleScript)
local val1 = UDim2.new(1,1,1,1)
local val2 = UDim2.new(2,2,2,2)
print(m.lerp(val1, val2, .5))
Outputs this:
{1.5, 1}, {1.5, 1}
An explation is just as helpful as the solution for this one. Thanks
|
|
KAAK82Join Date: 2014-05-06 Post Count: 1166 |
Me and my friend were also thinking about this... we also got a bit stuck, but we were on the right Path...
local function lerp(n0, n1, num)
local d = math.abs(n0 - n1)
local n = d * num
return n0 + n
end
Try this :P |
|
KAAK82Join Date: 2014-05-06 Post Count: 1166 |
Actually wait there
local d = n1 - n0
there |
|
|
function lerpnum(val,val2,amount)
return val + (val2 - val1) * amount
end |
|
KAAK82Join Date: 2014-05-06 Post Count: 1166 |
That's just a shortened version of what I gave :P |
|
|
KAAK82Join Date: 2014-05-06 Post Count: 1166 |
Works? Np ;) |
|
|
function lerp(a, b, c) return (1-c)*a+(b*c) end
local start = 0
local end = 10
local alpha = 0.5
print(lerp(start, end, alpha)) --> 5
alpha = 0.25
print(lerp(start, end, alpha)) --> 2.5 |
|
|
The lerp works, but the rest of the script doesn't. This causes the decal to fly off the screen, any idea why?
mouse.Move:connect(function()
if mouse.Target and debounce then
debounce = false
while mouse.Target and mouse.Target.Name == "Interact" and not small do
small = true
for i = 10, 20, .5 do
if mouse.Target and mouse.Target.Name == "Interact" then
local newnum = -5 - ((i - 10) / 2)
local newpos = m.lerp(decal.Position, UDim2.new(0, newnum, 0, newnum), i)
decal.Position = newpos
print(newpos)
wait(.1)
end
end
wait()
end
--small = false
--[[while mouse.Target and mouse.Target.Name ~= "Interact" and decal.Size.X ~= 10 do
for i = decal.Size.X.Offset, 10, -1 do
if mouse.Target and mouse.Target.Name ~= "Interact" then
local newnum = 0
decal:TweenSize(UDim2.new(0, i, 0, i))
wait(.05)
end
end
wait() -- Just a saftey net
end]]
end
debounce = true
end)
|
|
C_SharperJoin Date: 2011-10-03 Post Count: 9405 |
Are you making a lerp that works with Gui elements? |
|
|
C_SharperJoin Date: 2011-10-03 Post Count: 9405 |
Sounds really useful. Are you planning on making it free for the public? |
|
|
I hadn't considered it, but given I could use it as a publicity stunt, maybe. The lerp work, btw. It's just implementing it is what I'm struggling with. If you want the code, it's here:
function lerpnum(val,val2,amount)
return val + (val2 - val) * amount
end
function _M.lerp(value1, value2, amount)
return UDim2.new(lerpnum(value1.X.Scale, value2.X.Scale, amount), lerpnum(value1.X.Offset, value2.X.Offset, amount), lerpnum(value1.Y.Scale, value2.Y.Scale, amount), lerpnum(value1.Y.Offset, value2.Y.Offset, amount))
end
It's uses are limited to high frequency tweening though
|
|
C_SharperJoin Date: 2011-10-03 Post Count: 9405 |
Cool! Good luck with it. |
|
KAAK82Join Date: 2014-05-06 Post Count: 1166 |
What u trying to do? |
|
|
When a player hovers his mouse over a part called interact, decal (mouse is made invisible as it is less customisable), is swollen. I would normally achieve this with tween, but if he moves off it whilst it's still expanding, with tween it'll finish the expansion then shrink. I want it to automatically shrink.
|
|
|
|
If you override it with another tween, it screws up
|
|
|
It doesn't ruin the effect to do it like that though. Mhmmm...
|
|
KAAK82Join Date: 2014-05-06 Post Count: 1166 |
Seems weird :/ I half don't get it and half don't understand the Code :/ |
|