So i made a script that clones the player character and moves it to a certain position. I want the limbs on the new one to match the ones of its relative name on the player. Right arm matches player right arm ect. This is the method im using
for i,v in pairs(fake:GetChildren()) do v.Anchored = true v.Rotation = player.Character:FindFirstChild(v.Name).Rotation wait() end
the issue with this is that the parts are trying to overlay themselves in order to complete the rotation change. Is there a way that i could do this using c framing, which is an exception to this rule?
Here is an image if it helps: Image
A CFrame is a matrix representing the position & orientation of something relative to some other reference frame.
Normally, that reference frame is the origin, and the CFrame is called "in world space".
How the "math" behind it works is that result = frame * relative
. If frame
is the origin, i.e., CFrame.new()
, then you just get relative
out: CFrame.new() * relative == relative
.
ASIDE: Another way to write this is
frame:toWorldSpace( relative )
, which may be easier to think about.
Imagine you have the CFrame CFrame.new(0, 2, 0)
. If you set a part to have that CFrame, it means you move it to the position (0, 2, 0)
.
Another way to interpret this CFrame is that it describes moving up 2 (rather than to the position (0, 2, 0)
). For example, part.CFrame * CFrame.new(0, 2, 0)
will be the CFrame that is 2 studs above where part.CFrame
was.
Imagine you have four parts, A, B
and X, Y
.
A
and X
are placed somewhere in the world. B
is somewhere nearby A
.
You want Y
to be in the same position relative to X
that B
is to A
. E.g., if B
is sitting on top of A
, you want Y
to be sitting on top of X
.
If I tell you that the relative CFrame of B
to A
is r
, then you can just use Y.CFrame = X.CFrame * r
.
The obvious question is: how do we get r
?
CFrames have a method, r = A.CFrame:toObjectSpace( B.CFrame )
. This gets the relative CFrame from A
to B
.
ASIDE: This is mathematically the same as
A.CFrame:inverse() * B.CFrame
You need to pick the "base" of the two models -- what are all the CFrames relative to?
For Humanoids, the HumanoidRootPart would be a good bet, since it doesn't animate at all.
-- Where "from", where "to" local inRoot = player.Character.HumanoidRootPart.CFrame local outRoot = fake.HumanoidRootPart.CFrame for _, part in pairs(fake:GetChildren()) do if part:IsA("BasePart") then -- Get original part relative to character: local correspond = player.Character[ part.Name ].CFrame -- Move me relative to my root: part.CFrame = outRoot * inRoot:toObjectSpace(correspond) end end