Troubled with resizing accessories and applying scaling to excess parts

I haven’t found a solution to this problem primarily because I’m too lazy with the math involved in it.

A while ago I found out how Roblox internally resizes accessories (applies against a single part), so the idea is to use that principle and apply it to multiple parts while maintaining their respective offsets (thus appearing as a resize and not a jumbled mess like the asset I posted somewhere in this thread). The most difficult part will be adjusting offsets.

Apologies for bumping this thread.

This would be a great solution as it looks like it solves everyone’s problems but your function and what it does is extremely vague.

I just recently ran into this problem and after days of searching came across this thread. Your function works perfectly with re-sizing based on BodyScale but the positioning of the parts is extremely vague as you don’t explain it.

I just have one question:

  • How do you fit the shoe onto the foot? If you’re using welds, why are you setting part positions?

local d = v.Position - s.Handle.Position
v.Position = v.Position + Vector3.new(d.X * (width - 1), d.Y * (height - 1), d.Z * (depth - 1))

If you could explain the function more in-depth and explain how it works, it’d do everyone in this thread looking for answers a huge favor. Thanks.

Yeah I realized that it was super vague a little too late. Forgot to come back and explain it. Anyway, for anyone else who found this thread this is what it’s doing under the hood:

function adjust(source, height, width, depth, prevHeight, prevWidth, prevDepth)
    for _, part in pairs(source:GetChildren()) do
        if part.Name ~= "Handle" and part:IsA("BasePart") then --Don't want to touch the handle
            local originalSize = Vector3.new(part.Size.X / prevWidth, part.Size.Y / prevHeight, part.Size.Z / prevDepth)
            --Get the ORIGINAL size of the previous resizing. On a fresh rig nothing should change.

            part.Size = Vector3.new(originalSize.X * width, originalSize.Y * height, originalSize.Z * depth)
            --OK, got the original size. Now just scale along the ways that you want it to.		

            --OK now all the positions are wonky. 
            --We need to find the current offset of the parts from the root part, 
            --aka the center, aka... the handle.
            local offset = part.Position - source.Handle.Position

            --OK that was easy. got the offset. now just need to scale the position 
            --from the center. Wait... why subtract one? Because the offset is already "one"
            --full scale off the center. OK, now just scale the desired width, height, depth etc.
            part.Position = part.Position + Vector3.new(offset.X * (width - 1), offset.Y * (height - 1), offset.Z * (depth - 1))

           --OK cool, now to go onto the next part.
        end 
    end
end 

adjust(source, 5, 3, 2, 1, 1, 1)
--Height to 5, width to 3, depth to 2
--Previous was 1,1,1
wait(2)
--Height to 10, width to 10, depth to 5
adjust(source, 10, 10, 5, 1, 1, 1)

This was assuming you were using WeldConstraints to connect your stuff up I believe. If you edit the position of a part connected by a WeldConstraint it stills sticks to Part0 from the offset you just changed.

OK. Hopefully that clears the air. Thinking about it now, might’ve been nicer to use Vector3’s for the scaling info. Oh well, it still works less than a year later. Let me know if that helped!

3 Likes

Thanks for replying! It makes a lot more sense now. After I replied last night I took it into studio and attempted to make it work with welds.

It was fairly simple, I just followed the same code you used for resizing for offsetting the welds properly. It works like a charm.

-- // this function assumes you have it pre-welded to the body part/base part. You could make a custom welding function if you want, I assume it's not impossible.

function adjust(s, height, width, depth, prevHeight, prevWidth, prevDepth)
	for i, v in pairs(s:GetChildren()) do
		
		for u, o in pairs(v:children()) do
			
			if o:IsA("BasePart") then
				
				local originalSize = Vector3.new(o.Size.X / prevWidth, o.Size.Y / prevHeight, o.Size.Z / prevDepth)
				o.Size = Vector3.new(originalSize.X * width, originalSize.Y * height, originalSize.Z * depth)
				
				local d = o.Position - v.Handle.Position
				local pos = o.Position + Vector3.new(d.X * (width - 1), d.Y * (height - 1), d.Z * (depth - 1))
				
				if o.Name ~= "Handle" then -- // Makes sure it's not the handle because we are welding any other parts TO the handle.
					
					local handle = v.Handle
					
					-- // all this is is just reconnecting the weld to the correct body parts.
					local weld
					for _, w in pairs(o.Parent.Handle:children()) do
						if w.Part1 == o then
							weld = w
						end
					end
					
					-- // same as below, offsets the weld based on the desired BodyScale while keeping it's rotations.
					local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = weld.C0:GetComponents()
					local originalCF = CFrame.new(weld.C0.X / prevWidth, weld.C0.Y / prevHeight, weld.C0.Z / prevDepth)

					weld.C0 = CFrame.new(originalCF.X * width, originalCF.Y * height, originalCF.Z * depth, r00, r01, r02, r10, r11, r12, r20, r21, r22)
					weld.Part1 = o
				end
			end
			
			if o.Name == "Handle" then -- // This is used for welding the Handle or the main part to whatever your welding it too
				local weld = o:FindFirstChild("Handle") -- // name of the main weld.
				
				-- // This basically grabs the already offset and C0 of the weld and offsets it slightly with set BodyScale while maintaining it's rotations.
				local limb = s.Parent[v.Name] -- // this is just the thing that it is being welded to.
				local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = weld.C0:GetComponents() -- rotational values.
				local originalCF = CFrame.new(weld.C0.X / prevWidth, weld.C0.Y / prevHeight, weld.C0.Z / prevDepth) -- original offset.
				
				weld.C0 = CFrame.new(originalCF.X * width, originalCF.Y * height, originalCF.Z * depth, r00, r01, r02, r10, r11, r12, r20, r21, r22)
				weld.Part1 = limb
			end
		end
	end
end 

I apologize for the sloopy-ish code. I’ll just leave this code here for anyone looking for a solution using welds.

3 Likes

Can you please explain this or the original one because I am having issues getting this to work as nothing is being resized.

Also, I am having a little troubles with this. What exactly is the source.

Ages old issue but replying just to mark a solution: just use model scale.

3 Likes

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