Filling up container with a "Liquid"

hello, im am trying to make this machine be filled up with inc, but i am having trouble calculating how the inc should be scaled and placed according to the progress of the completion

and it stays in the same position, only the size changes.

the snippet of code:

local extracting = true
		
		local progress = script.Parent.Parent.Parent.Config.Progress
		
		local extractionSpeed = char.Config.ExtractionSpeed 
		local extractionSpeedMultiplier = char.CharacterValues.ExtractionSpeedMultiplier
		local inc = script.Parent.Parent.Parent.Venom
		while extracting do
			task.wait(1)
			progress.Value+= extractionSpeed.Value*extractionSpeedMultiplier.Value
			
			
			if progress.Value >= 100 then
				progress.Value = 100
				inc.Size = Vector3.new(maxIncSize, inc.Size.Y, inc.Size.Z)
				break
			end
			TweenService:Create(inc, TweenInfo.new(1, Enum.EasingStyle.Linear), {Size = Vector3.new((progress.Value/maxIncSize) * 0.25, inc.Size.Y, inc.Size.Z)}):Play()
		end

any help would be really appreciated!

Easy, as you can see the ink is not moving, well for it to work, you need to change position in y axis to half of the size you’re changing it to, add it to your tween and you got it!

1 Like

To explain a little better, let’s say you have a line in 2d diagram, there are squares, let’s call it studs. So the center position of your line is X = 2, Y = 0 studs and size is not defined. But you wish to increase the size of Y by 3 studs. And as you do, you see the line is not gaining 3 studs up, but instead it’s getting 1.5 studs on both sides, so for it to be illusion of it just rising up instead of growing in both sides, that 1.5 studs in Y behind has to be moved up back in position, so you add to your position half of the size you added which is exactly how much it grew in other side, so your Y position is 1.5

1 Like

Hello, thanks for the reply. I feel like i understand, but i just can’t get it right in the code, i dont know what im doing wrong…

while extracting do
			task.wait(1)
			progress.Value+= extractionSpeed.Value*extractionSpeedMultiplier.Value
			
			local AddAmount = (progress.Value/maxIncSize) * 0.25
			
			
			if progress.Value >= 100 then
				progress.Value = 100
				inc.Size = Vector3.new(maxIncSize, inc.Size.Y, inc.Size.Z)
				break
			end
			TweenService:Create(inc, TweenInfo.new(1, Enum.EasingStyle.Linear), {Size = Vector3.new(AddAmount, inc.Size.Y, inc.Size.Z), CFrame = inc.CFrame*CFrame.new(AddAmount/2,0, 0)}):Play()
		end

it brings it up too much for some reason or too little depending on how much i divide it for

Okay so I’m really confused about the whole script but, here is how you can do it.

You have percentage of it being done.
Make an invisible container (what you wish for the ink to look like when it’s full)

And now you just have to do something along these lines

InkSizeY = Container.Size.Y * 100/progress

InkY = InkSizeY / 2
InkX = Ink.CFrame.X
InkZ = Ink.Cframe.Z

Ink.Size = Vector.New(0,inkSizeY,0)
Ink.CFrame = CFrame.new(InkX,InkY,InkZ)

This should probably work, fluids occupy all the space so just make the starting ink a flat disk on the bottom of Container

All you should be changing is Y size and Y position, you can do it this way and then make it a tween to play

1 Like

Hello, i think to scale a cylinder part up, you need to change the X size of it.

and it dosen’t really work… it just bugs and flies in weird ways…

local inkSizeY = container.Size.Y * 100/progress.Value
			
			local inkY = inkSizeY/2
			local inkX = 	inc.CFrame.X
			local incZ = inc.CFrame.Z
			
			inc.Size = Vector3.new(1,inkSizeY,1)
			inc.CFrame = CFrame.new(inkX,inkY,incZ)

Hey easy fix, go to union and select only the cylinder and make it a mesh now it will work, also the rotation is weird, check that out.

1 Like

i tried that, nothing changed.
Okay, im really confused now, but i am trying to rewrite the code, heres what ive got so far:

local fraction = maxIncSize/100
			
local containerFraction = container.Size.Y/100

local howMuchAdd = fraction*progress.Value

inc.Size = Vector3.new(fraction*progress.Value, inc.Size.Y, inc.Size.Z)

inc.Position = inc.Position+Vector3.new(0, containerFraction*progress.Value/2, 0)

this works for size, but i absolutelly cannot figure it out for the position

this just makes it go too far, even though it should work
i’ve tried many ways, and but it just goes too far.

edit: i figured out whats wrong, it does calculate right, but it just changes the position to be higher every time, i dont know how to fix it yet

1 Like

Finally! i was able to figure it out. thanks so much!!

1 Like