I have been working on a script for a plugin to non-uniformly scale all parts within a model along the axis of the model’s primary part cframe with a vector and I am running into an issue where sometimes it scales parts correctly, however sometimes parts on a mirrored axis result in incorrect scaling, see image below where I scaled a model by the vector (2,1,1) all parts scale correctly except for the part on the left z axis.
The position scaling is done correctly, but not sure why the primary part aligned scale for each part isn’t working as expected in all cases
a copy of the place with the model above and the script
Scaling issue.rbxl (45.8 KB)
current scale funciton code that works mostly
local function scaleModelNonUniform(model,scale)
if model:isA("Model") then
local primaryPart = model.PrimaryPart
if model.PrimaryPart ~= nil then
for i,v in pairs(model:GetDescendants())do
if v:isA("BasePart") then
local scaleWorldSpace = scale*primaryPart.CFrame:VectorToObjectSpace(v.CFrame:VectorToWorldSpace(v.Size))
if(scaleWorldSpace.Magnitude>=2048^3)then
warn('Max part size exceeded')
else
local scaleObjectSpace = v.CFrame:VectorToObjectSpace(primaryPart.CFrame:VectorToWorldSpace(scaleWorldSpace))
v.Size =Vector3.new(math.abs(scaleObjectSpace.x),math.abs(scaleObjectSpace.y),math.abs(scaleObjectSpace.z))
if v ~= primaryPart then
v.Position =primaryPart.CFrame*CFrame.new(model.PrimaryPart.CFrame:ToObjectSpace(v.CFrame).Position*scale).Position
end
end
end
end
else
warn('No primary part set for'..model.Name..'!')
end
else
warn('No model passed to function !')
end
end