How to convert CFrame to C0

I want to convert the resulting CFrame to C0 Weld (I need to convert the rotation).

``````script.Parent.HumanoidRootPart.Weld.C0 = cframe
``````

Is it something like welding a part to another?
I think this is what youâ€™re trying to find:

``````Part.Weld.C0 = Part.Weld.Part0.CFrame:Inverse() * Part.Weld.Part1.CFrame
``````

(If it doesnâ€™t work, switch up Part0 with Part1 instead and vice versa.)

Your method is quite sympathetic to me, but the part changes its position that it is very abnormal. It is necessary to make that only rotation changes.
For understanding, I will provide you with this code:

``````               local sourcePosition = script.Parent.Point.Position
local targetPosition = nearestTarget.HumanoidRootPart.Position

local targetVector = Vector3.new(sourcePosition.X, targetPosition.Y, targetPosition.Z)

local cframe = CFrame.lookAt(sourcePosition, targetVector)

script.Parent.HumanoidRootPart.Weld.C0 = script.Parent.HumanoidRootPart.Weld.Part1.CFrame:Inverse() * cframe
``````

Well, you could try doing:

``````local cframe = Weld.Part0.CFrame:Inverse() * Weld.Part1.CFrame
cframe = CFrame.new(0, 0, 0, select(4, cframe:GetComponents())
Weld.C0 = cframe
``````

Could you provide a screenshot/image depicting the problem youâ€™re encountering right now and what youâ€™re trying to achieve?

2 Likes

Here is a video clip:

I want to achieve that this cube does not rotate in x and z and does not change positions, but rotates strictly up or down y depending on the position of the target (changes with the height of the target will be clearly visible). It does not turn up or down and teleports back and forth (I used your new provided code, with another one in general, the cube in space flew strangely around the NPC).

Sorry for the late response, school work. Anyways, so from what I can image, you donâ€™t want the part to tilt upwards and roll right and that it updates always right?
Try this?

``````local originalC0 = humanoidRootPart.Weld.Part1.CFrame:Inverse() * humanoidRootPart.Weld.Part0.CFrame

-- assume this while loop is the loop your source code is in
local targetPos, sourcePos = target.Position, source.Position
local to = (targetPos-sourcePos)
if to:Dot(to) > 0 then -- a 0,0,0 vector would result to NaN since .Unit is
-- vector.Unit = vector/vector.Magnitude, to put it simply, NaN = vector/0
to = to.Unit
end
local lookAt = CFrame.lookAt(Vector3.zero, to)
humanoidRootPart.Weld.C0 = originalC0 * lookAt
end
``````
``````local sourcePosition = script.Parent.Point.Position
local targetPosition = nearestTarget.HumanoidRootPart.Position

local targetVector = Vector3.new(sourcePosition.X, targetPosition.Y, targetPosition.Z)

local cframe = CFrame.lookAt(sourcePosition, targetVector)

script.Parent.HumanoidRootPart.Weld.C0 = cframe
``````

This code calculates the `CFrame` directly and sets it as the C0 of the Weld. The `C0` property expects a CFrame, and you can assign the calculated `cframe` directly without the need for additional transformations.