Filling a spherical container

Hello! I want to have a spherical container be filled up with a liquid in my game, but I don’t how how I would go about doing that. Something like this, but dynamic and using scripts.
image

I want it to be smooth, so that it doesn’t look janky when being filled. Is there any way to achieve this?

I suppose you could have a part for the liquid, being the same size as the sphere but smaller. When you want to change the fill value, perhaps use BasePart:SubtractAsync() with a part sized to match your value.

2 Likes

So I’ve been thinking about this for a few minutes. My first thought is to have two hemispheres that will make up the fluid when full. The idea was to have one semisphere on the bottom and use tween service to size it however you want. The second semisphere will remain invisible until the first semisphere is now a hemisphere (if that makes sense) and then tween the size of the second one as well.
It may or may not work, was just a thought.

Apologies if my theory isn’t very clear or doesn’t work.

1 Like

The only way I can think of is using a BillboardGui with a circle image inside of a frame with ClipDescendants on.

3 Likes

I like @GibusWielder 's answer. The easiest way to do this would be avoiding a physical part entirely. Of course, the illusion would easily be thrown off from different perspectives.

You could try the calculus approach of slicing the liquid (sphere) into thin cylinders, which are generated and resized as the liquid volume changes.

1 Like

Thanks for the replies, I’ve been messing with each technique. Using a BillboardGui doesn’t work when you’re looking at the container from weird angles, which I think is a big issue. I would rather avoid using calculus, and so I settled with @1Minecraft0954 's suggestion. I tweened one hemisphere to the size and position of a bunch of differently sized ones, to emulate liquid filling. Here’s what it looks like:
image
image
https://gyazo.com/4f2b62af3283397db66298a2e3a1a35f

And my code:

local TweenService = game:GetService("TweenService")

local part = script.Parent

local current = 0

while true do
	
	local goal = {}
	goal.Position = script.Parent.Parent:FindFirstChild(current).Position
	goal.Size = script.Parent.Parent:FindFirstChild(current).Size
	
	
	
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear)

	local tween = TweenService:Create(part, tweenInfo, goal)

	tween:Play()
	wait(2)
	current += 1
	if current == 6 then
		current = 0
	end
	
	
	
end

It’s just one hemisphere, but creating a second one won’t be tough. The result could use some tweaking, but it works smoothly enough.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.