Turret Rotation issue

Hello, I made a turret for my firetruck and it works perfectly when its not rotated but when I rotate the vehicle its not working properly what can I do ?

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.1)

local function point(position)
    local joint = workspace.FireTruck.Body.Part.Motor6D
    local worldC0 = CFrame.new(joint.Part0.CFrame.X,0,joint.Part0.CFrame.Z)* joint.C0
    local cf = CFrame.new(Vector3.new(worldC0.X,0,worldC0.Z), position) * CFrame.Angles(math.rad(180),math.rad(180),math.rad(90))
    local goal = {}
    goal.C0 = ((cf - cf.p) + joint.C0.p) * CFrame.Angles(0,-math.pi / 2, -math.pi / 2)
    local asd =TS:Create(joint,TI,goal)
    asd:Play()
end

while wait(0.1) do
    point(Vector3.new(workspace.Target.Position.X,0,workspace.Target.Position.Z))
end 

1 Like

Hi, after looking at what happens I think i may of created some code that could help.

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.1)

local function point(position)
	local joint = game.Workspace.Part1.Weld
    CF = CFrame.new(joint.Part0.Position,position)
	X,Y,Z = CF:ToOrientation()local goal = {}
    goal.C0 = CFrame.Angles(0,Y,0)*CFrame.Angles(0,-math.rad(joint.Part0.Orientation.Y),0)
    local asd =TS:Create(joint,TI,goal)
    asd:Play()
end

while wait(0.1) do
    point(Vector3.new(workspace.Target.Position.X,0,workspace.Target.Position.Z))
end 

You will need to change the parts and the weld name as i used a normal weld. Hope this helps getting your turret fixed!

3 Likes

Thanks for helping :slight_smile: