It sortof works, but not for what I am looking for.
It does bring the water to the stop’s position, but it also moves its X and Z value. It also just teleports to the location, it doesn’t do it over the 70 seconds that I placed as time limit.
I did read the article on the wiki but I still don’t understand how it works and how can I make it only lerp on the Y position.
Yes, I only want the part to move up and down, although it is not a must, as I figured out a way, I simply made an exact copy of water, named it stop, and moved it on the Y axis, that way it will line up properly.
It worked! Thanks!
Only problem is that it moves really blocky like.
I added a video so you know what I mean
It almost looks as if I was setting the CFrame to the same value but 4 studs above the original one very second. I think that is pretty much what is happening, but I wanted to use lerp so it went up smoothly. This is caused by the wait(1) but if I remove it, it just teleports to the top.
I used to use BodyVelocity, but the water just kept going up and I couldn’t really control the time it took to reach the top, so I switched to lerp.
Is there a better way to do this?
local iterations = 10
for i = 0, timelimit - 1 do
for j = 0, iterations do
water.CFrame = water.CFrame:Lerp(stop.CFrame, (i * iterations + j)/(timelimit * iterations))
wait(1/iterations)
end
end
What are iterations? Is it like the ammount of time that code runs?
And what are all the multiplications for?
I want to understand the code so I can replicate it if I encounted the same problem.
Also, the code didn’t quite work, it teleported the water to the stop position.
But thanks anyways, I want to learn how this whole thing works so it would be great if you could explain the code aswell.
Yes, that does work!
But there are two problems.
1-. Water rises extremley slowly
2-. Water still rises in blocks, which ruins the whole effect.
Here is a vid of what I mean
I want the water to reach the top in the time-limit(70 seconds), and I wanted to use lerp so that it goes up seamlessly, without it being blocky.
local startCFrame = water.CFrame
local iterations = 10
for i = 0, timelimit - 1 do
for j = 0, iterations do
water.CFrame = startCFrame:Lerp(stop.CFrame, (i * iterations + j)/(timelimit * iterations))
wait(1/iterations)
end
end
This is how it looked when I used BodyVelocity, this is what I mean by smooth transitions.
Thing is I don’t want to use BodyVelocity as I cannot control the time it takes for the water to reach point A to point B and also the water doesn’t stop at point B.
How could I use TweenService? I did open a wiki article on it a while back for scaling gui using Tween but I just thought it was for GUI and lerp was for objects.
I’ll do more research on Tween, but that sitll leaves me the queston on what lerp is for? I thought lerp was also for smooth transitions.
local water = script.Parent.Water
local stop = script.Parent.Stop
local timelimit = 70
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(timelimit,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
local goal = {position = stop.Position}
local tween = tweenservice:Create(water,tweeninfo,goal)
wait(5)
tween:Play()