How can I set the radius of a cylinder to match a certain volume?

Hello! I am having a strange issue here. I am trying to create a game in which you consume objects as a hole. The problem is that I am not sure how to proceed with the growth system. You start as a 6 stud wide cylinder, however if you eat this bollard I have for example, it just adds the volume amount to your radius. The problem is that the radius is basically never accurate.

For example, if you have a cube which is 1x1x1, it would just add one stud to your radius, totalling at 7 studs, but it should be holevolume = holevolume + 1 (the area from above).

Does this make sense?

Video showcasing what I have so far.

Code snippet:

		local DeterminedValue = math.huge
		local area = math.huge
		local Consumeable = script.Parent:FindFirstChild('Consumeable')
		if Consumeable then
			if Consumeable.Value == true then
				local V3 = v.Parent:GetExtentsSize() -- the model (for this example the bollard)
				local X = V3.X
				local Y = V3.Y
				local Z = V3.Z
				area = X*Y*Z
				if Y > Z or Y == Z then
					print('Y')
					DeterminedValue = Y
				elseif Y < Z then
					DeterminedValue = Z
					print('Z')
				end
			end
		end

How the new size is determined:

Vector3.new(0.1, value.Value + area/2 --[[divided by two for the 2 axes]], value.Value + area/2)
--value.Value is just the size of the hole which is stored in the player instance so I don't have to calculate the size every time

If you need any further explanation, let me know.

Question, If you just needed to add the sizes together then whats the point of doing the area variable. You’re doing x * y * z > which is what I believe is causing that weird gain. cuz then you have v.Value + area/2 < Like I don’t understand this.

I would suggest getting the size of the circle you already have then just adding the value, that formula seems so overcomplicated for some reason lmao. Unless I’m just not understanding.

1 Like

Maybe I am not explaining properly, sorry about that.

v.Value is the player’s current radius, if you want to change the radius of the cylinder, you have to change both radii as the hitbox will become weird, it doesn’t automatically resize the other axis:

I just divided it by two to equilibrate the value to the two axes.

Basically, all I want to do is:

CylinderVolume = CylinderVolume + ObjectVolume

but without affecting the height of the cylinder, which is what I am unsure of.

Oh ok I see now, still I still believe theres other alternatives to the specific formula you’re trying to use. Not entirely sure if this would work, but couldn’t you essentially do something similar to this

local partx = part.size.x
local party = part.size.y
local partz = part.size.z

local targety = target.size.y
local targetz = target.size.z

part.size = Vector3.new(partx, party + targety, partz + targetz)

1 Like

Yeah, I could but it’s not as accurate as possible.

Basically, I want to do something like this, let’s say the Y axis is the height of the circle.

(π*x^2) * Y - this is the formula of obtaining the volume of the cylinder.

I want to check what I have to increase the radius by to gain the amount of volume.

So let’s say the volume of our sphere is 5 studs^3, and the object’s volume is 2 studs^3. I want to see how I can make the volume of the cylinder equal to 7 studs^3 while mainaining the height of 0.1 studs.

xd I guess I’m too simplistic for a question like this, funny enough though. The little mobile game that you’re referencing does it exactly how you’re doing it. They don’t attempt to add the actual size its pretty funny. Anyways hopefully someone with better math skills comes around. Best of luck mate

1 Like

Is it hole io? That’s what I based it off of lol, well trying to. Also, they have different size tiers instead of adding the volume or whatever I am trying to do lol.

Yeah, hole.io and all io games in general copy and paste the same formula for size. An the difference is it makes it harder > where like size tiers allow you to automatically grab the next big sized item, your adding size would force them to stay at a lower level until they collected more. I guess you could say your version would have a higher skill cap.

1 Like

Sounds like you need to find the diameter when volume is known.
Volume of cylinder formula is V = π * r^2 * h

Can change that to get radius:
V/(π*h) = r^2
r = sqrt( V/(π*h) )

Roblox cylinders use diameter not radius:
d/2 = sqrt( V/(π*h) )
d = 2 * sqrt( V/(π*h) )

You could keep track of current volume of your cylinder then add that volume to the volume of whatever was eaten and insert that for ‘V’ in the above formula.

-- something like this
local height = 0.1
function diameterFromNewVolume(oldVolume, addedVolume)
	local V = oldVolume+addedVolume
	return 2 * math.sqrt( V/(math.pi*height) )   -- returns diameter (for width and length)
end
4 Likes