Understanding C1 and C0

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Understanding C0 and C1 and how they are related to Part0 and Part1 ; the purpose and how they work.

  2. What is the issue? Include screenshots / videos if possible!
    I watched a tutorial on welds but there is something I do not understand, C1 and C0. What are their purpose? What do they do? I noticed the script did not work when i did not include it. What does adding .CFrame after the part linked to C0 or C1 do? Please help me understand.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes I did, but i did not understand the answers people gave. I also want to make a new post since most of them were old and responding would not work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is a simple script I made involving c0 and c1, however i do not understand how c0 an c1 really works yet. Are my guesses right?

local hat = workspace:WaitForChild("Hat")
local debounce = false

script.Parent.Touched:Connect(function(otherpart)
	
	if debounce == true then 
		print("Debounce") -- Guard clause for debounce
		return
	end
	
	if otherpart.Parent:FindFirstChild("Humanoid") then -- check if humanoid
		
		print("Touched a humanoid.") --
		
		debounce = true -- turn on debounce
		
		hat.CanTouch = false -- set properties to false 
		hat.Anchored = false
		
		local head = otherpart.Parent.Head -- reference the touched humanoid's head
		
		hat.CFrame = head.CFrame * CFrame.new(0,5,0) -- our offset
		
		local weld = Instance.new("Weld")
		
		weld.Part0 = head -- what ur welding to
		
		weld.Part1 = hat -- What you are welding
		
		weld.C0 = head.CFrame:Inverse() -- does not autofill as it does not know yet
		weld.C1 = hat.CFrame:Inverse()-- c0 and c1 are used to create an offset point - so for example to add a part 10 studs above us.
		
		weld.Parent = hat -- the weld needs a parent
		task.wait(3)
		weld:Destroy()
	end
	task.wait(2)
	debounce = false
end)

-- Inverse will reverse the digits of the cframe (1,1,1 would be -1,-1,-1)
-- c0 and c1 - subtracts the cframes and determines the offset

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Let’s say you have a part and if you touch it, a weld will be created inside the player’s head and it will weld the part and the head together. For now the part will just overlap the player’s head and make them look silly. But with C0 and C1, you can apply a relative offset to the part so it will weld to the head 10 studs high.

local part = script.Parent
part.Touched:Connect(function(hit)
   if not hit.Parent:FindFirstChild('Humanoid') then return end
   local head = hit.Parent.Head
   local weld = Instance.new('Weld')
   part.CFrame = head.CFrame * CFrame.new(0,10,0) -- Offset of part from head
   weld.Part0 = head
   weld.Part1 = part
   -- Here we are gonna register the offset we put up there
   weld.C0 = head.CFrame:Inverse()
   weld.C1 = part.CFrame:Inverse()
end)

So C0 and C1 simply let you register an offset for one (or two) of the welded parts.

2 Likes

Rig edit is a good visualization of C0 and C1. You can imagine C0 as an arrow starting from the part0 going towards the joint position.

You can also use Attachments to help obtain the values of C0 and C1 and also visualize it.

I have seen this formula before and it is quite weird if you use rig edit to visualize it you will find that the joint position is created at (0,0,0) since the C0 cancels out the Part0 CFrame initially.

I suggest you try to visualize it yourself with rig edit in studio.

--weld formula
part1.CFrame * C1 == Part0.CFrame * C0
--You can get the joint world position or attachment world position using this CFrame
--Focusing on getting the joint position from part0 only
Part0.CFrame * C0

--If head is the part0
 Head.CFrame * C0
--Using the formula
Head.CFrame*head.CFrame:Inverse() 
--It cancels out creating the joint position at CFrame.new() or origin
CFrame.new()
2 Likes

I dont understand too much because there is a lot but makes a bit more sense. How would I work welding with humanoids, can I use inverse? And why does it not work if i do not inverse?