So I want to move part A to spot X, which is let’s say 1 stud away from A’s current position, relative to part B.
By relative I mean if we draw a line from B to A, I want A to be 1 stud away from it’s current position, but still be on that line.
I am pretty good at scripting, know about CFrames, lookvectors and etc… But I’m not very good at math and coming up with complicated formulas. So if someone could help me I would much appreciate.
P.S. This is for scaling a custom character correctly, if it matters. Now I’m just scaling all the parts of the character, but not moving them, and this is the result
If I could after scaling move the part relative to HumanoidRootPart for a certain distance, this issue would be fixed.
1 Like
So you want to get like line between A and B, then move it 1 stud further from B ?
I don’t need the line, I draw and described the line just to make clear how I want part A to move. Yes, I guess that’s one way to put it, I want to move part A 1 stud away from part B
So I played with CFrames abit and there is your code. To make it visible to everyone you need to make sure its not client sided but server sided.
Script
local partA = game.Workspace.PartA
local partB = game.Workspace.PartB
local multiplier = 1
local newCFrame = CFrame.lookAt(partA.CFrame.Position, partB.CFrame.Position)
newCFrame *= CFrame.Angles(0, math.rad(180), 0)
partA.CFrame = CFrame.new(partA.CFrame.Position + newCFrame.LookVector * multiplier)
The higher you set the multiplier, the further it moves.
3 Likes
I marked your post as solution, because it does completely answer my question, but doesn’t solve my issue. I would much appreciate if you helped me with this.
As you can see in the video I posted, I am trying to scale a custom character, and it scales very badly, here’s the code that I’m using
local function ScaleModel(model, scale)
local primary = model.PrimaryPart
local primaryCf = primary.CFrame
for _,v in pairs(model:GetDescendants()) do
if (v:IsA("BasePart")) or (v:IsA("MeshPart")) or (v:IsA("Union")) or (v:IsA("Part")) then
v.Size = (v.Size * scale)
if (v ~= primary) then
--Move relative to primary
end
end
end
model:MoveTo(game.Workspace.SpawnLocation.Position + Vector3.new(0,50,0))
end
I think the solution to the issue is to move the part relative to humanoidrootpart after scaling. But when I tried to incorporate your code in the commented section, it still scaled the same way as in the video.
Do you know how can I scale it correctly, the way models scale in studio with regular scale tool?
Download f3x tools the plugin they actually have good scaling. So you can scale one side at a time.
If you want to scale relative to the other part then just set the size to the same as the other part.
I know about f3x tools, it is not what Im looking for at all. The character is suppossed to grow automatically over a period of time.
What do you mean set the size same as other part? What other part? And it is definitely wrong, because parts have different sizes, for example head is bigger than tail. Setting them to same size would completely mess them up
Just look inside the character for the size values. If you can’t find them then just take them from the regular character and add them in.
If you use joints on the parts, cannot you just like scale every part ?
I do scale every part with above code, and it results what’s in the video. The reason is when you scale a part, it scales from it’s center. Meaning it stays in the same position, and scales equally from each side. So when you scale it after a certain point parts start getting into each other and becoming a mess.
What about moving actual attachements further from the part center ? That could teoretically work, only thing is that you would have to calculate the new position
xDDD, yes that or moving the part itself is what I am suggesting, but
I am having very much trouble with this only thing
Well, I never worked with custom characters so I dont really know how to do this. If it has like humanoid, maybe try setting it there. I found something like this:
local Humanoid = script.Parent:WaitForChild("Humanoid",3);
local HS = Humanoid.HeadScale;
local BDS = Humanoid.BodyDepthScale;
local BWS = Humanoid.BodyWidthScale;
local BHS = Humanoid.BodyHeightScale;
spawn(function()
for i=0, 30 do
Humanoid.AutomaticScalingEnabled = false;
HS.Value += 0.1;
BDS.Value += 0.1;
BWS.Value += 0.1;
BHS.Value += 0.1;
Humanoid.AutomaticScalingEnabled = true;
wait();
end
end)
Else I dont really know.