I’m trying to make cframe.lookat work with welds and that works fine but now the issue is if an object its welded to moves it doesnt like “auto-register” it and do the math with it
while task.wait() do
local pos = script.Parent:GetPivot().Position
local weld = script.Parent.Parent.MainBody.TurretBody
local rx, ry = CFrame.lookAt(pos, workspace.Part.Position):ToOrientation()
weld.C0 = CFrame.new(weld.C0.Position) * CFrame.fromOrientation(0, ry - math.pi, 0)
end
I think you can offset from C0
Unless you replace it with an Attachment and use WorldCFrame
local Weld=WeldObject
local Offset=Vector3.new(x,y,z)
local C0_CFramr=PartWeldIsAttacgedTo.CFrame*C0
local Lookatposition=Cframe.new(Position)
local Inverse=C0_CFrame:ToObjectSpace(Lookatposition)
Weld.C1=Cframe.new(Offset,Inverse.Position)
I created this on my phone, and if you have any questions please ask them.
I dont understand a large chunk of your code. i put it to mine and its just an helicopter
while task.wait() do
local Weld=script.Parent.Parent.MainBody.TurretBody
local Offset=Vector3.new(0,0,0)
local C0_Position=script.Parent.CFrame*Weld.C0
local Lookatposition=CFrame.new(workspace.Part.Position)
local Inverse=C0_Position:ToObjectSpace(Lookatposition)
Weld.C1= CFrame.new(Offset,Inverse.Position)
end
Well first I think you might if misunderstood C0_Position
It looks like you might of attached it to the The actual part the Weld Is on, But I meant the Part that is not moved By the Weld and it attached to
But I do not think really any one of the people who you are talking too doesnt know the parts of the tank very well.
So I am taking A guess by the name of it.
Turretbody is the weld
Mainbody is what the turret is attached to (turret is the part that moves)
script.parent is wha ti want to move (turret)
weld: c0 = mainbody c1 = script.parent.
I don’t understand any of your code because im not that of an experienced coder
You have to add the initial rotation to the new rotation. So make a variable for the initial c1 or c0 and simply add the rotations. In this case your tank rotation is what you should add onto your new rotation. It may be subtracting. But try adding it first
Can you go a little more in depth, i dont understand fully.
What i think your saying is create a number value and when i rotate the tank make the number value the number you rotate it and add it to the code?
And making it when the tank moves it edits the value to stay on the correct path (this is the easiest because using RUN its automatically on the server so you can modify the value to be correct)
like this: