Trouble with C0

I have researched alot and alot for a simple problem, how can I make a welded part (assigned as part1 in this weld we are talking about) face to a position? Basically how can I create CFrame.lookat()/CFrame.new(pos,lookat) with C0? because when I try these on C0 lets say it gets wacky (and also doesnt work) so if you have any resources or examples, it would be really useful, thanks.

2 Likes

You could probably use cframe:ToObjectSpace and the other like CFrame methods. Here’s a good starting point:

1 Like

To make a welded part face a specific position, you can use the CFrame.lookAt method to create a CFrame that represents the orientation you want the part to have. This method takes two arguments: the position of the part, and the position you want the part to face. You can then use this CFrame to set the part’s CFrame property, which will orient the part as desired.

Here’s an example of how you could use CFrame.lookAt to orient a welded part:

-- Define the position of the welded part
local partPosition = CFrame.new(0, 0, 0)

-- Define the position you want the part to face
local lookAtPosition = CFrame.new(1, 0, 0)

-- Create a CFrame that represents the orientation you want the part to have
local partCFrame = CFrame.lookAt(partPosition, lookAtPosition)

-- Set the part's CFrame to the calculated CFrame
part1.CFrame = partCFrame

If you want to use a CFrame.new method with a C0 value, you can do so by specifying the C0 value as the second argument to the CFrame.new method. Here’s an example of how you could use CFrame.new with a C0 value:

-- Define the position of the welded part
local partPosition = CFrame.new(0, 0, 0)

-- Define the position you want the part to face
local lookAtPosition = CFrame.new(1, 0, 0)

-- Create a CFrame that represents the orientation you want the part to have, using a C0 value
local partCFrame = CFrame.new(partPosition, lookAtPosition, C0)

-- Set the part's CFrame to the calculated CFrame
part1.CFrame = partCFrame

I hope this helps!

1 Like

I tried to explain in my tutorial, but its not that good, too much words.

Tl;DR gotta CFrame inverse or to object space as @7z99 said to rearrange the weld equation.

2 Likes

When you say it acts wonky, what do you mean exactly?

Is the welded Part always pointing the same direction, but not at the direction you want it to? You may have to add or subtract 90 degrees to an X,Y or Z angle to get the right face looking at the target.

Does it move, but not face the correct orientation? It might be as others have stated it might be an Object space/World space issue.

Does it face the right direction, but when you get to 90 degrees it starts reacting differently? Gimbal lock is a term that describes when an object is rotated 90 degrees so two of the axes are now aligned.

1 Like

I did use that while setting the original C0 position of the part but I just cant make it face to the given position

that is exactly what I tried as I even specified but… how do I say it? it turned out weird as you can see it doesnt rotat to above like 180 degree and it just overall wacky from what you can see
@scottifly

https://gyazo.com/3cb8d8d9e6793f4111b3c7bcdc2dc606

Could you show what you tried?

please specify if I should send a recording of it (I already have done) or send the script

Please send the script you tried.

1 Like
game.Lighting.Charge.OnServerEvent:Connect(function(plr,bool)
	print(bool)
	if plr.Character.Charges.Value == 0 then
		if plr.Character:FindFirstChild("ChargeHolders") then else
			if bool == true then
				plr.Character.Charging.Value = true
				while task.wait(3) do
					plr.Character.Charges.Value+=1
					print("yes?")
					if plr.Character.Charging.Value == false then
						break
					end
				end
			end
		end
		end
	if not plr.Character:FindFirstChild("ChargeHolders") then
		print("woah charge done")
		if bool == false then
			plr.Character.Charging.Value=false
			if plr.Character.Charges.Value ~= 0 then
			local g = 1/plr.Character.Charges.Value
			local folda = Instance.new("Folder", plr.Character)
			local weldsfolda = Instance.new("Folder",plr.Character)
			--local thingss = Instance.new("Attachment",plr.Character.HumanoidRootPart)
			folda.Name="ChargeHolders"
			weldsfolda.Name="WeldsFolder"
			local N = false
			local amt = 0
			for i = 0,1,g do
				if i ~= 0 then
					local V = nil
					amt +=1
					if N == false then
						V = game.Lighting.BlackCursor:Clone()
					else
						V = game.Lighting.WhiteCursor:Clone()
					end
					N = not N
					V.Parent=folda --RightVector
					print(i)
					local pcf = plr.Character.HumanoidRootPart.CFrame --pcf.UpVector*((plr.Character.Charges.Value)*1.5)
					V.CFrame =  pcf + pcf.UpVector*((plr.Character.Charges.Value)*1.5)+ (pcf.UpVector*(math.cos(math.rad(360*i))*(plr.Character.Charges.Value*1.5)))+(pcf.RightVector*(math.sin(math.rad(360*i))*(plr.Character.Charges.Value*1.5)))+pcf.LookVector*-5
					local weld = Instance.new("Weld")
					local thingish = plr.Character.HumanoidRootPart.CFrame:ToObjectSpace(V.CFrame)
					weld.Parent=weldsfolda
					weld.C0 = thingish
					weld.Part0=plr.Character.HumanoidRootPart
					weld.Part1=V
					local H = workspace["Retro Gun shot (Lowered)"]:Clone()
					H.Parent=workspace
					game:GetService("Debris"):AddItem(H,5)
					H:Play()
					V.Name= amt
					weld.Name = amt
				end
				
			end
			task.spawn(function()
				while task.wait() do
					if not plr.Character:FindFirstChild("ChargeHolders") then
						break
					end
					local success, errore = pcall(function()
						local mouse = game.Lighting.GetMousePos:InvokeClient(plr)
						for i,_ in pairs(weldsfolda:GetChildren()) do
								local v = weldsfolda:FindFirstChild(i)
								--*local n = folda:FindFirstChild(i)
							local L = CFrame.new(v.C0.Position, mouse).LookVector
							--print(L)
								
								--n.CFrame = CFrame.lookAt(n.CFrame.Position,mouse)
						end
					end)
					if not success then
						
						warn(errore)
					end
				end
			end)
			end
			end
	end
end)

Try:

local cf = CFrame.lookAt(arrow.Position, mouse)
weld.C0 = rootPart.CFrame:ToObjectSpace(cf)
4 Likes

is rootpart supposed to be humanoidrootpart? just making sure… sorry if I’m asking too many questions (I assume that the arrow is one of the attack part)

1 Like

rootPart is the humanoid root part, yeah, arrow is the attack part I believe, the things that should be pointing towards the cursor.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.