Troubled with resizing accessories and applying scaling to excess parts

Went on another search spree, turned up some threads that seem to cover the same problem. I’ll be experimenting with these solutions alongside what’s been posted above and my own thoughts. Turns out “resize accessory” didn’t contain what I needed.

The last thread is especially important because it directly reflects my use case.

1 Like

Little late, but an update. I have attempted the above solutions and none of them work in the way I expected. The morph I attempted this on is different from the one in the OP only by construct, but follows the same paradigm.


The space in the gratings should be filled red, instead of poking out at the top.

I could be close. The sizes look right but the positions are odd.

I have the feeling like I ought to just get rep for support towards the last posted thread in the above response. I haven’t a clue as to what I’m doing or if I’m applying the code samples in each of those threads correctly (I used them raw as-is).

I generally don’t want to touch resize functions without knowing what I’m doing because of how messy and cumbersome run time resizing can get.

Has anyone yet found a for sure solution to this? @PostApproval I know what you mean when you say you don’t like to touch resizing functions without knowing exactly what you’re doing. I’m in the same boat. I wish the accessories would automatically do this for you. It definitely should be a roblox feature.

At the moment, no I have not yet found a solution, which is why I’ve left the top thread (my thread on the matter) unmarked. I’ve tried experimenting with a bunch of different methods, currently leaving that progress on hiatus though so I can focus on other things.

Hey there!

I recently encountered this issue and was able to solve it through the following function that I wrote. I hope you find it useful!

function adjust(s, h, w)
    for i,v in pairs(s:GetChildren()) do
        if v.Name ~= "Handle" and v:IsA("BasePart") then
            v.Size = Vector3.new(v.Size.X * w, v.Size.Y * h, v.Size.Z * w)
            local d = v.Position - s.Handle.Position
            v.Position = v.Position + Vector3.new(d.X * (w - 1), d.Y * (h - 1), d.Z * (w - 1))
        end 
    end
end
adjust(source, height, weight)

Good luck!

Edit: You can incorporate depth/width into this, for my purposes I only used a general “weight”. (in case you didn’t know s is the accessory, h is height and w is weight ;p)

Edit 2: Just realized this doesn’t work great when called multiple times. Trying to come up with a mathy way of solving this.

1 Like

What is “weight”? Accessories have no concept of weight. Also, from reading your calculations, you use this W value across two axis but I don’t think this would help very much considering the fact that height, width and depth are all applied differently in regards to accessory scaling.

Could you show this code at work? I’m not so certain this resolves my problem.

Sorry about the confusion. In my game I don’t keep track of depth/width, I use a single float for that part. The “weight” in the function in my understanding is how “fat” the character is, i.e. their dimensions across the X/Z axis.

Here’s a gif of it working:

The shoe looks like one piece, but it has two parts, a semi transparent mesh part, and the same mesh part slightly smaller but neon.

https://gyazo.com/bc7a0fa5d3f51e9751ebf26bfc197ab6

Also, here’s the fixed code. You just have to track and know the previous weight/height before calling adjust() again.

function adjust(s, h, w, ph, pw)
    for i,v in pairs(s:GetChildren()) do
        if v.Name ~= "Handle" and v:IsA("BasePart") then
            local originalSize = Vector3.new(v.Size.X / pw, v.Size.Y / ph, v.Size.Z / pw)
            v.Size = Vector3.new(originalSize.X * w, originalSize.Y * h, originalSize.Z * w)
		
            local d = v.Position - s.Handle.Position
            v.Position = v.Position + Vector3.new(d.X * (w - 1), d.Y * (h - 1), d.Z * (w - 1))
        end 
    end
end 

adjust(source, 5, 3, 1, 1)
wait(2)
adjust(source, 10, 10, 5, 3)
2 Likes

Thanks for the showcase. It looks pretty close enough to what I’m looking for (save for the vague variable names, which I don’t find to be very helpful in deriving any information other than understanding that some value goes somewhere).

Do you know how I can get this resize function to work specifically with the scaling values in humanoids? That’s chiefly what I want, for accessories to be resized along with the scaling values. Although this function technically answers the question as far as getting accessories to resize, what I’m more specifically looking to tackle is resizing them according to the scaling values.

Related question:

Here, check out this different rendition. I expanded the variables a little more!

function adjust(s, height, width, depth, prevHeight, prevWidth, prevDepth)
    for i,v in pairs(s:GetChildren()) do
        if v.Name ~= "Handle" and v:IsA("BasePart") then
            local originalSize = Vector3.new(v.Size.X / prevWidth, v.Size.Y / prevHeight, v.Size.Z / prevDepth)
            v.Size = Vector3.new(originalSize.X * width, originalSize.Y * height, originalSize.Z * depth)
		
            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))
        end 
    end
end 

adjust(source, 5, 3, 1, 1)
wait(2)
adjust(source, 10, 10, 5, 3)

Edit: In this scenario I track the previous height/depth/width for finding original sizes/positions. You can instead have two Vector3 values in each part to keep track of their original size/positions, but it is up to you.

I’m not really sure on how their scalings work but I imagine it’s something to do in their Animate script, or one of the character related scripts.

2 Likes

Animate is strictly for animating, it doesn’t have to do with resizing character assets. The only other script as well is Health (Sounds would be one as well, but has long since been replaced).

Accessory resizing is probably baked into the Humanoid object right now so I’m trying to figure out how to scale with those values specifically. If I need to feed arbitrary values into a function without any idea as to where I’m supposed to go, then there’s no real merit in using a solution because likewise I won’t know how to maintain it. I don’t use things I don’t understand.

Thanks for the help anyway, appreciate it.

Did you guys find a solution to this? I’m having the same problem.

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!

2 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.

2 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.

2 Likes

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