Custom Character Scaling with Motor6Ds

Trying to scale a Character properly

Scaling the Character works correctly if the model is anchored, but as soon as you unanchor the model it turns into a blob, which I’m assuming is due to the Motor6Ds not being scaled as well and it retracts back to the Motor6D positions

The rigtype is r6

Code
function AnchorModel(Model, Bool)
	for _, Part in pairs(Model:GetChildren()) do
		if Part:IsA("BasePart") then
		Part.Anchored = Bool
		end
	end
end




function Scale(Model, Scale) -- loops through model and scales
	--AnchorModel(Model, true)
	local Primary = Model.PrimaryPart
	local PrimaryCFrame = Primary.CFrame
	
	for i, Part in pairs(Model:GetChildren()) do
		if Part:IsA("BasePart") then
			
			Part.Size = (Part.Size * Scale) -- scales the part
			if Part ~= Primary then
			Part.Position = PrimaryCFrame.Position + (Part.Position-PrimaryCFrame.Position)* Scale
 -- if the part isnt the primary part scale the position
			end
			
		end
	end
	--AnchorModel(Model, false)
end

local Runs = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(Player)
	
	while true do
		local Char = Player.Character
		if Char then
			wait(5)
			Scale(Char, 2)
		end
		Runs.Heartbeat:Wait()
	end

end)

ScalePlace.rbxl (19.6 KB)

I’ve did research but I couldn’t find any relating to motor6D scaling

Does anyone know how I can scale motor6Ds when I scale the size?
Thanks in advance

4 Likes

Is Motor6D scaling as simple as multiplying the C0 and C1 by a certain number relative to the scale number, or is it something that requires a lot of math, time

Scaling would be great for my game and I don’t want to go without it, but if this is overly complicated I may be better off working on other features

I’m always happy to learn but I have deadlines for the game I’m creating, and if it’s hard to do I could learn later when I have more time to spare

Thanks

Yes, this happens because the Motor6Ds retract after unanchoring. And yes, it’s as simple as moving the C0 and C1 of the Motor6Ds (or JointInstance) by the scale (See example below).

function ScaleModel(Model, Scale)	
	for _, Part in pairs(Model:GetChildren()) do
		if Part:IsA("BasePart") then
			Part.Size = Part.Size*Scale
			
			for _, child in pairs(Part:GetChildren()) do
				if child:IsA("JointInstance") then
					-- Set the Offset CFrames to itself adding (or subtracting) a scaled position of itself.
					child.C0 = child.C0 + child.C0.Position*(Scale-1)
					child.C1 = child.C1 + child.C1.Position*(Scale-1)
				end
			end
		end
	end
end

Hope this helps.

11 Likes

Thanks so much, I’ve been stuck on this issue for months

(the code works perfectly)

1 Like