Fillable Container Positioning When Turned Sideways

Hello I’m currently trying to make a fillable container using math, you can see a demonstration of it below. I’ve got it working for the most part except for when it turns sideways the math seems to be off, you can find my code below, any help is appreciated thanks.

https://streamable.com/75u2l6

local Original = script.Parent.Size

script.Parent:GetAttributeChangedSignal("Amount"):Connect(function()
	local Amount = script.Parent:GetAttribute("Amount")
	local OriginPosition = script.Parent.Parent.Outside.Position
	local OriginY = Original.X
	local Size = (OriginY/100) * Amount
	local Position = (OriginY - Size) / 2
	script.Parent.Size = Vector3.new(Size, Original.Y, Original.Z)
	script.Parent.Position = Vector3.new(OriginPosition.X, OriginPosition.Y - Position, OriginPosition.Z)
end)

Because your not taking into account the object space of the container, your using world space this is why the transformations are off when you rotate the object, it must be in the containers local space

2 Likes

Thanks, I looked into using local space and ended up using VectorToWorldSpace, it works perfectly.

1 Like

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