I am trying to create a turret that turns but is already welded to a ship. I have seen several solutions for similar problems, but my code rotates the entire ship. I have moved the problem to a smaller area on the baseplate. Assume that the grey part is the turret, the red is what it will be pivoting on.
My code that was taken from another tutorial (rBase meaning the baseplate):
local weld = Instance.new("Weld")
weld.Part0 = script.Parent.around
weld.Part1 = workspace.rBase
weld.C0 = script.Parent.around.CFrame:Inverse()
weld.C1 = workspace.rBase.CFrame:Inverse()
weld.Parent = script.Parent.around
The code that pivots the red part (this simple for testing purposes):
while wait(0.5) do
local pivot = script.Parent.around.Position
local newpivot = CFrame.new(pivot)
local offset = newpivot:toObjectSpace(script.Parent.Part.CFrame)
newpivot = newpivot * CFrame.Angles(0, math.rad(2), 0)
script.Parent.Part.CFrame = newpivot * offset
end
Thank you in advance!